update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / impl / PsiConstantEvaluationHelperImpl.java
blob9c000845bede9a404f45a35ac7cf9792ae88e853
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.psi.impl;
18 import com.intellij.psi.*;
19 import com.intellij.psi.util.ConstantExpressionUtil;
21 import java.util.Set;
23 /**
24 * @author ven
26 public class PsiConstantEvaluationHelperImpl extends PsiConstantEvaluationHelper {
28 public Object computeConstantExpression(PsiElement expression) {
29 return computeConstantExpression(expression, false);
32 public Object computeConstantExpression(PsiElement expression, boolean throwExceptionOnOverflow) {
33 if (expression == null) return null;
34 ConstantExpressionEvaluator expressionEvaluator = LanguageConstantExpressionEvaluator.INSTANCE.forLanguage(expression.getLanguage());
35 assert expressionEvaluator != null;
37 return expressionEvaluator.computeConstantExpression(expression, throwExceptionOnOverflow);
40 @Override
41 public Object computeExpression(final PsiExpression expression, final boolean throwExceptionOnOverflow, final AuxEvaluator auxEvaluator) {
42 if (expression == null) return null;
43 ConstantExpressionEvaluator expressionEvaluator = LanguageConstantExpressionEvaluator.INSTANCE.forLanguage(expression.getLanguage());
44 assert expressionEvaluator != null;
45 return expressionEvaluator.computeExpression(expression, throwExceptionOnOverflow, auxEvaluator);
48 public static Object computeCastTo(PsiExpression expression, PsiType castTo, Set<PsiVariable> visitedVars) {
49 Object value = JavaConstantExpressionEvaluator.computeConstantExpression(expression, visitedVars, false);
50 if (value == null) return null;
51 return ConstantExpressionUtil.computeCastTo(value, castTo);