Write constant initializer for java properties
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
org.jetbrains.jet.lang.resolve.java.structure.impl.JavaPropertyInitializerEvaluatorImpl
|
||||
-14
@@ -77,20 +77,6 @@ public class TraceBasedJavaResolverCache implements JavaResolverCache {
|
||||
public void recordField(@NotNull JavaField field, @NotNull PropertyDescriptor descriptor) {
|
||||
PsiField psiField = ((JavaFieldImpl) field).getPsi();
|
||||
trace.record(VARIABLE, psiField, descriptor);
|
||||
|
||||
if (!descriptor.isVar()) {
|
||||
PsiExpression initializer = psiField.getInitializer();
|
||||
Object evaluatedExpression = JavaConstantExpressionEvaluator.computeConstantExpression(initializer, false);
|
||||
if (evaluatedExpression != null) {
|
||||
CompileTimeConstant<?> constant =
|
||||
ResolverPackage.resolveCompileTimeConstantValue(evaluatedExpression,
|
||||
CompileTimeConstantUtils.isPropertyCompileTimeConstant(descriptor),
|
||||
descriptor.getType());
|
||||
if (constant != null) {
|
||||
trace.record(COMPILE_TIME_INITIALIZER, descriptor, constant);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+7
@@ -17,8 +17,10 @@
|
||||
package org.jetbrains.jet.lang.resolve.java.structure.impl;
|
||||
|
||||
import com.intellij.psi.PsiEnumConstant;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiField;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaField;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaType;
|
||||
|
||||
@@ -37,4 +39,9 @@ public class JavaFieldImpl extends JavaMemberImpl<PsiField> implements JavaField
|
||||
public JavaType getType() {
|
||||
return JavaTypeImpl.create(getPsi().getType());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiExpression getInitializer() {
|
||||
return getPsi().getInitializer();
|
||||
}
|
||||
}
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java.structure.impl;
|
||||
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.impl.JavaConstantExpressionEvaluator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.constants.ConstantUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaField;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaPropertyInitializerEvaluator;
|
||||
|
||||
public class JavaPropertyInitializerEvaluatorImpl extends JavaPropertyInitializerEvaluator {
|
||||
@Nullable
|
||||
@Override
|
||||
public CompileTimeConstant<?> getInitializerConstant(@NotNull JavaField field, @NotNull PropertyDescriptor descriptor) {
|
||||
PsiExpression initializer = ((JavaFieldImpl) field).getInitializer();
|
||||
Object evaluatedExpression = JavaConstantExpressionEvaluator.computeConstantExpression(initializer, false);
|
||||
if (evaluatedExpression != null) {
|
||||
return ConstantUtils.createCompileTimeConstant(
|
||||
evaluatedExpression,
|
||||
DescriptorUtils.isPropertyCompileTimeConstant(descriptor),
|
||||
false,
|
||||
descriptor.getType());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user