mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't cache globally types calculated during inference
This commit is contained in:
@@ -25,6 +25,7 @@ import com.intellij.psi.impl.source.resolve.ResolveCache;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
@@ -64,6 +65,12 @@ public interface InferenceContext {
|
||||
ResolveResult[] results = ResolveCache.getInstance(ref.getElement().getProject()).resolveWithCaching(ref, resolver, true, incomplete);
|
||||
return results.length == 0 ? GroovyResolveResult.EMPTY_ARRAY : (GroovyResolveResult[])results;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T extends GroovyPsiElement> PsiType getExpressionType(T element, Function<T, PsiType> calculator) {
|
||||
return GroovyPsiManager.getInstance(element.getProject()).getType(element, calculator);
|
||||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
@@ -73,6 +80,9 @@ public interface InferenceContext {
|
||||
|
||||
<T extends PsiPolyVariantReference> GroovyResolveResult[] multiResolve(@NotNull T ref, boolean incomplete, ResolveCache.PolyVariantResolver<T> resolver);
|
||||
|
||||
@Nullable
|
||||
<T extends GroovyPsiElement> PsiType getExpressionType(T element, Function<T, PsiType> calculator);
|
||||
|
||||
class PartialContext implements InferenceContext {
|
||||
private final Map<String, PsiType> myTypes;
|
||||
private final Map<PsiElement, Map<Object, Object>> myCache = newHashMap();
|
||||
@@ -118,6 +128,18 @@ public interface InferenceContext {
|
||||
}
|
||||
}, Pair.create(incomplete, resolver.getClass()));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T extends GroovyPsiElement> PsiType getExpressionType(final T element, final Function<T, PsiType> calculator) {
|
||||
return _getCachedValue(element, new Computable<PsiType>() {
|
||||
@Override
|
||||
public PsiType compute() {
|
||||
PsiType type = calculator.fun(element);
|
||||
return type == PsiType.NULL ? null : type;
|
||||
}
|
||||
}, "type");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-1
@@ -54,7 +54,7 @@ public class TypeInferenceHelper {
|
||||
private static final Logger LOG = Logger.getInstance(TypeInferenceHelper.class);
|
||||
private static final ThreadLocal<InferenceContext> ourInferenceContext = new ThreadLocal<InferenceContext>();
|
||||
|
||||
public static <T> T doInference(Map<String, PsiType> bindings, Computable<T> computation) {
|
||||
private static <T> T doInference(Map<String, PsiType> bindings, Computable<T> computation) {
|
||||
InferenceContext old = ourInferenceContext.get();
|
||||
ourInferenceContext.set(new InferenceContext.PartialContext(bindings));
|
||||
try {
|
||||
@@ -125,6 +125,7 @@ public class TypeInferenceHelper {
|
||||
return inferVariableType(variableName, scope, flow, findInstructionAt(place, flow));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiType inferVariableType(String variableName, GrControlFlowOwner scope, Instruction[] flow, Instruction instruction) {
|
||||
if (instruction == null) return null;
|
||||
|
||||
|
||||
+2
-5
@@ -36,10 +36,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgument
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrMapType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrExpressionImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames;
|
||||
@@ -96,7 +93,7 @@ public class GrListOrMapImpl extends GrExpressionImpl implements GrListOrMap {
|
||||
}
|
||||
|
||||
public PsiType getType() {
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, TYPES_CALCULATOR);
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, TYPES_CALCULATOR);
|
||||
}
|
||||
|
||||
public boolean isMap() {
|
||||
|
||||
+2
-5
@@ -39,10 +39,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrClosureType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiElementImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.params.GrParameterListImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.ClosureSyntheticParameter;
|
||||
@@ -265,7 +262,7 @@ public class GrClosableBlockImpl extends GrBlockImpl implements GrClosableBlock
|
||||
|
||||
@Nullable
|
||||
public PsiType getReturnType() {
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, ourTypesCalculator);
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, ourTypesCalculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-2
@@ -37,7 +37,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpres
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.TypeInferenceHelper;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
|
||||
@@ -101,7 +100,7 @@ public class GrAssignmentExpressionImpl extends GrExpressionImpl implements GrAs
|
||||
}
|
||||
|
||||
public PsiType getType() {
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, TYPE_CALCULATOR);
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, TYPE_CALCULATOR);
|
||||
}
|
||||
|
||||
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
|
||||
|
||||
+1
-2
@@ -33,7 +33,6 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.TypeInferenceHelper;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
|
||||
@@ -121,7 +120,7 @@ public abstract class GrBinaryExpressionImpl extends GrExpressionImpl implements
|
||||
|
||||
@Override
|
||||
public PsiType getType() {
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, TYPE_CALCULATOR);
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, TYPE_CALCULATOR);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+2
-1
@@ -28,6 +28,7 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrConditionalExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.TypeInferenceHelper;
|
||||
|
||||
/**
|
||||
* @author ilyas
|
||||
@@ -88,7 +89,7 @@ public class GrConditionalExprImpl extends GrExpressionImpl implements GrConditi
|
||||
}
|
||||
|
||||
public PsiType getType() {
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, TYPE_CALCULATOR);
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, TYPE_CALCULATOR);
|
||||
}
|
||||
|
||||
public void accept(GroovyElementVisitor visitor) {
|
||||
|
||||
+2
-1
@@ -27,6 +27,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpres
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.TypeInferenceHelper;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.path.GrCallExpressionImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.typeEnhancers.GrCallExpressionTypeCalculator;
|
||||
|
||||
@@ -100,7 +101,7 @@ public abstract class GrMethodCallImpl extends GrCallExpressionImpl implements G
|
||||
}
|
||||
|
||||
public PsiType getType() {
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, METHOD_CALL_TYPES_CALCULATOR);
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, METHOD_CALL_TYPES_CALCULATOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-5
@@ -39,10 +39,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrBuiltInTypeElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrClassReferenceType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrMapType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.path.GrCallExpressionImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
|
||||
@@ -96,7 +93,7 @@ public class GrNewExpressionImpl extends GrCallExpressionImpl implements GrNewEx
|
||||
}
|
||||
|
||||
public PsiType getType() {
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, MY_TYPE_CALCULATOR);
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, MY_TYPE_CALCULATOR);
|
||||
}
|
||||
|
||||
public GrNamedArgument addNamedArgument(final GrNamedArgument namedArgument) throws IncorrectOperationException {
|
||||
|
||||
+5
-5
@@ -593,13 +593,14 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
if (result!=null) return result;
|
||||
|
||||
|
||||
final PsiType inferred = refExpr.getQualifier() == null ? TypeInferenceHelper.getCurrentContext().getVariableType(refExpr) : null;
|
||||
final PsiElement resolved = refExpr.resolve();
|
||||
final PsiType inferred = refExpr.getQualifier() == null && !(resolved instanceof PsiClass) ?
|
||||
TypeInferenceHelper.getCurrentContext().getVariableType(refExpr) :
|
||||
null;
|
||||
final PsiType nominal = refExpr.getNominalType();
|
||||
if (inferred == null || PsiType.NULL.equals(inferred)) {
|
||||
if (nominal == null) {
|
||||
//inside nested closure we could still try to infer from variable initializer. Not sound, but makes sense
|
||||
assert refExpr.isValid();
|
||||
final PsiElement resolved = refExpr.resolve();
|
||||
if (resolved instanceof GrVariable) {
|
||||
assert resolved.isValid();
|
||||
return ((GrVariable)resolved).getTypeGroovy();
|
||||
@@ -611,7 +612,6 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
|
||||
if (nominal == null) return inferred;
|
||||
if (!TypeConversionUtil.isAssignable(nominal, inferred, false)) {
|
||||
final PsiElement resolved = refExpr.resolve();
|
||||
if (resolved instanceof GrVariable && ((GrVariable)resolved).getTypeElementGroovy() != null) {
|
||||
return nominal;
|
||||
}
|
||||
@@ -621,7 +621,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
}
|
||||
|
||||
public PsiType getType() {
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, TYPES_CALCULATOR);
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, TYPES_CALCULATOR);
|
||||
}
|
||||
|
||||
public GrExpression replaceWithExpression(@NotNull GrExpression newExpr, boolean removeUnnecessaryParentheses) {
|
||||
|
||||
+2
-1
@@ -30,6 +30,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrSuperR
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.TypeInferenceHelper;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GrClassImplUtil;
|
||||
|
||||
/**
|
||||
@@ -84,7 +85,7 @@ public class GrSuperReferenceExpressionImpl extends GrThisSuperReferenceExpressi
|
||||
}
|
||||
|
||||
public PsiType getType() {
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, TYPE_CALCULATOR);
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, TYPE_CALCULATOR);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -25,6 +25,7 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrThisReferenceExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.TypeInferenceHelper;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
|
||||
/**
|
||||
@@ -86,7 +87,7 @@ public class GrThisReferenceExpressionImpl extends GrThisSuperReferenceExpressio
|
||||
}
|
||||
|
||||
public PsiType getType() {
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, TYPE_CALCULATOR);
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, TYPE_CALCULATOR);
|
||||
}
|
||||
|
||||
private PsiType createType(@NotNull PsiClass context) {
|
||||
|
||||
+1
-2
@@ -35,7 +35,6 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrUnaryExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.TypeInferenceHelper;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrExpressionImpl;
|
||||
@@ -97,7 +96,7 @@ public class GrUnaryExpressionImpl extends GrExpressionImpl implements GrUnaryEx
|
||||
}
|
||||
|
||||
public PsiType getType() {
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, TYPE_CALCULATOR);
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, TYPE_CALCULATOR);
|
||||
}
|
||||
|
||||
public IElementType getOperationTokenType() {
|
||||
|
||||
+2
-13
@@ -22,8 +22,6 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.NullableFunction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
@@ -31,7 +29,6 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GrStringUtil;
|
||||
|
||||
@@ -46,14 +43,6 @@ import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.*;
|
||||
public class GrLiteralImpl extends GrAbstractLiteral implements GrLiteral, PsiLanguageInjectionHost {
|
||||
private static final Logger LOG = Logger.getInstance(GrLiteralImpl.class);
|
||||
|
||||
private static final Function<GrLiteralImpl, PsiType> TYPE_CALCULATOR = new NullableFunction<GrLiteralImpl, PsiType>() {
|
||||
@Override
|
||||
public PsiType fun(GrLiteralImpl grLiteral) {
|
||||
IElementType elemType = getLiteralType(grLiteral);
|
||||
return TypesUtil.getPsiType(grLiteral, elemType);
|
||||
}
|
||||
};
|
||||
|
||||
public GrLiteralImpl(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
@@ -63,8 +52,8 @@ public class GrLiteralImpl extends GrAbstractLiteral implements GrLiteral, PsiLa
|
||||
}
|
||||
|
||||
public PsiType getType() {
|
||||
if (getLiteralType(this) == kNULL) return PsiType.NULL;
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, TYPE_CALCULATOR);
|
||||
IElementType elemType = getLiteralType(this);
|
||||
return elemType == kNULL ? PsiType.NULL : TypesUtil.getPsiType(this, elemType);
|
||||
}
|
||||
|
||||
public void accept(GroovyElementVisitor visitor) {
|
||||
|
||||
+4
-16
@@ -17,36 +17,24 @@
|
||||
package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.literals;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.CommonClassNames;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrStringInjection;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GrStringUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.psi.CommonClassNames.JAVA_LANG_STRING;
|
||||
import static org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.GROOVY_LANG_GSTRING;
|
||||
|
||||
/**
|
||||
* @author ilyas
|
||||
*/
|
||||
public class GrStringImpl extends GrAbstractLiteral implements GrString {
|
||||
private static final Function<GrStringImpl,PsiType> TYPE_CALCULATOR = new Function<GrStringImpl, PsiType>() {
|
||||
@Override
|
||||
public PsiType fun(GrStringImpl grString) {
|
||||
if (grString.findChildByClass(GrStringInjection.class) != null) {
|
||||
return grString.getTypeByFQName(GroovyCommonClassNames.GROOVY_LANG_GSTRING);
|
||||
}
|
||||
else {
|
||||
return grString.getTypeByFQName(CommonClassNames.JAVA_LANG_STRING);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public GrStringImpl(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
@@ -57,7 +45,7 @@ public class GrStringImpl extends GrAbstractLiteral implements GrString {
|
||||
}
|
||||
|
||||
public PsiType getType() {
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, TYPE_CALCULATOR);
|
||||
return getTypeByFQName(findChildByClass(GrStringInjection.class) != null ? GROOVY_LANG_GSTRING : JAVA_LANG_STRING);
|
||||
}
|
||||
|
||||
public boolean isPlainString() {
|
||||
|
||||
+1
-1
@@ -246,7 +246,7 @@ public class GrIndexPropertyImpl extends GrExpressionImpl implements GrIndexProp
|
||||
}
|
||||
|
||||
public PsiType getType() {
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, TYPE_CALCULATOR);
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, TYPE_CALCULATOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBuiltinTypeClassExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.TypeInferenceHelper;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrExpressionImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
|
||||
|
||||
@@ -49,7 +50,7 @@ public class GrBuiltinTypeClassExpressionImpl extends GrExpressionImpl implement
|
||||
}
|
||||
|
||||
public PsiType getType() {
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, TYPES_CALCULATOR);
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, TYPES_CALCULATOR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+1
-10
@@ -19,14 +19,12 @@ package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.types;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.CommonClassNames;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrInstanceOfExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrExpressionImpl;
|
||||
|
||||
/**
|
||||
@@ -34,13 +32,6 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrExpre
|
||||
*/
|
||||
public class GrInstanceofExpressionImpl extends GrExpressionImpl implements GrInstanceOfExpression {
|
||||
|
||||
private static final Function<GrInstanceofExpressionImpl,PsiType> TYPE_CALCULATOR = new Function<GrInstanceofExpressionImpl, PsiType>() {
|
||||
@Override
|
||||
public PsiType fun(GrInstanceofExpressionImpl expression) {
|
||||
return expression.getTypeByFQName(CommonClassNames.JAVA_LANG_BOOLEAN);
|
||||
}
|
||||
};
|
||||
|
||||
public GrInstanceofExpressionImpl(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
@@ -54,7 +45,7 @@ public class GrInstanceofExpressionImpl extends GrExpressionImpl implements GrIn
|
||||
}
|
||||
|
||||
public PsiType getType() {
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, TYPE_CALCULATOR);
|
||||
return getTypeByFQName(CommonClassNames.JAVA_LANG_BOOLEAN);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+1
-2
@@ -33,7 +33,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrSafeCastExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.TypeInferenceHelper;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrExpressionImpl;
|
||||
@@ -116,7 +115,7 @@ public class GrSafeCastExpressionImpl extends GrExpressionImpl implements GrSafe
|
||||
}
|
||||
|
||||
public PsiType getType() {
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, TYPE_CALCULATOR);
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, TYPE_CALCULATOR);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+2
-5
@@ -63,10 +63,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameter;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameterList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrStubElementBase;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyFileImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrReflectedMethodImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.stubs.GrMethodStub;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
@@ -141,7 +138,7 @@ public abstract class GrMethodBaseImpl extends GrStubElementBase<GrMethodStub> i
|
||||
//todo uncomment when EAP is on
|
||||
//LOG.assertTrue(!ApplicationManager.getApplication().isDispatchThread()); //this is a potentially long action
|
||||
}
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, ourTypesCalculator);
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, ourTypesCalculator);
|
||||
}
|
||||
|
||||
public boolean processDeclarations(@NotNull PsiScopeProcessor processor,
|
||||
|
||||
Reference in New Issue
Block a user