summaryrefslogtreecommitdiff
path: root/java/java-psi-impl/src/com/intellij/psi/impl
diff options
context:
space:
mode:
Diffstat (limited to 'java/java-psi-impl/src/com/intellij/psi/impl')
-rw-r--r--java/java-psi-impl/src/com/intellij/psi/impl/InheritanceImplUtil.java12
-rw-r--r--java/java-psi-impl/src/com/intellij/psi/impl/JavaConstantExpressionEvaluator.java6
-rw-r--r--java/java-psi-impl/src/com/intellij/psi/impl/compiled/SignatureParsing.java4
-rw-r--r--java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/JavaImportStatementElementType.java6
-rw-r--r--java/java-psi-impl/src/com/intellij/psi/impl/source/JavaLightStubBuilder.java4
-rw-r--r--java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java12
-rw-r--r--java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/ClassResolverProcessor.java5
-rw-r--r--java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java21
-rw-r--r--java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/PsiMethodReferenceCompatibilityConstraint.java15
-rw-r--r--java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java2
-rw-r--r--java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaSourceUtil.java81
-rw-r--r--java/java-psi-impl/src/com/intellij/psi/impl/source/tree/SourceUtil.java79
-rw-r--r--java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/ExpressionPsiElement.java21
-rw-r--r--java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodElement.java18
-rw-r--r--java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java8
-rw-r--r--java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiPackageStatementImpl.java4
-rw-r--r--java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiReferenceExpressionImpl.java2
17 files changed, 171 insertions, 129 deletions
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/InheritanceImplUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/InheritanceImplUtil.java
index 543c8a653651..f958555a3c45 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/InheritanceImplUtil.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/InheritanceImplUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-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.
@@ -24,7 +24,7 @@ import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiModificationTracker;
-import com.intellij.util.containers.ConcurrentHashMap;
+import com.intellij.util.containers.ConcurrentWeakHashMap;
import com.intellij.util.containers.HashSet;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NonNls;
@@ -41,14 +41,14 @@ public class InheritanceImplUtil {
if (baseClass instanceof PsiAnonymousClass) return false;
if (!checkDeep) return isInheritor(candidateClass, baseClass, false, null);
- if (CommonClassNames.JAVA_LANG_OBJECT.equals(candidateClass.getQualifiedName())) return false;
- if (CommonClassNames.JAVA_LANG_OBJECT.equals(baseClass.getQualifiedName())) return true;
+ if (CommonClassNames.JAVA_LANG_OBJECT_SHORT.equals(candidateClass.getName()) && CommonClassNames.JAVA_LANG_OBJECT.equals(candidateClass.getQualifiedName())) return false;
+ if (CommonClassNames.JAVA_LANG_OBJECT_SHORT.equals(baseClass.getName()) && CommonClassNames.JAVA_LANG_OBJECT.equals(baseClass.getQualifiedName())) return true;
Map<PsiClass, Boolean> map = CachedValuesManager.
getCachedValue(candidateClass, new CachedValueProvider<Map<PsiClass, Boolean>>() {
@Nullable
@Override
public Result<Map<PsiClass, Boolean>> compute() {
- final Map<PsiClass, Boolean> map = new ConcurrentHashMap<PsiClass, Boolean>();
+ final Map<PsiClass, Boolean> map = new ConcurrentWeakHashMap<PsiClass, Boolean>();
return Result.create(map, candidateClass, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
}
});
@@ -82,7 +82,7 @@ public class InheritanceImplUtil {
}
@NonNls final String baseName = baseClass.getName();
- if ("Object".equals(baseName)) {
+ if (CommonClassNames.JAVA_LANG_OBJECT_SHORT.equals(baseName)) {
PsiClass objectClass = JavaPsiFacade.getInstance(manager.getProject()).findClass(CommonClassNames.JAVA_LANG_OBJECT, candidateClass.getResolveScope());
if (manager.areElementsEquivalent(baseClass, objectClass)) {
if (manager.areElementsEquivalent(candidateClass, objectClass)) return false;
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/JavaConstantExpressionEvaluator.java b/java/java-psi-impl/src/com/intellij/psi/impl/JavaConstantExpressionEvaluator.java
index 674ccbe1f03f..19da149c99b8 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/JavaConstantExpressionEvaluator.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/JavaConstantExpressionEvaluator.java
@@ -105,11 +105,11 @@ public class JavaConstantExpressionEvaluator extends JavaRecursiveElementWalking
return myMapFactory.create();
}
- public static Object computeConstantExpression(PsiExpression expression, @Nullable Set<PsiVariable> visitedVars, boolean throwExceptionOnOverflow) {
+ public static Object computeConstantExpression(@Nullable PsiExpression expression, @Nullable Set<PsiVariable> visitedVars, boolean throwExceptionOnOverflow) {
return computeConstantExpression(expression, visitedVars, throwExceptionOnOverflow, null);
}
- public static Object computeConstantExpression(PsiExpression expression, @Nullable Set<PsiVariable> visitedVars, boolean throwExceptionOnOverflow,
+ public static Object computeConstantExpression(@Nullable PsiExpression expression, @Nullable Set<PsiVariable> visitedVars, boolean throwExceptionOnOverflow,
final PsiConstantEvaluationHelper.AuxEvaluator auxEvaluator) {
if (expression == null) return null;
@@ -131,7 +131,7 @@ public class JavaConstantExpressionEvaluator extends JavaRecursiveElementWalking
return cached == NO_VALUE ? null : cached;
}
- public static Object computeConstantExpression(PsiExpression expression, boolean throwExceptionOnOverflow) {
+ public static Object computeConstantExpression(@Nullable PsiExpression expression, boolean throwExceptionOnOverflow) {
return computeConstantExpression(expression, null, throwExceptionOnOverflow);
}
}
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/SignatureParsing.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/SignatureParsing.java
index 46cceffcb6ad..bd5f75ece27f 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/SignatureParsing.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/SignatureParsing.java
@@ -32,6 +32,7 @@ import com.intellij.util.cls.ClsFormatException;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.text.CharacterIterator;
@@ -259,7 +260,8 @@ public class SignatureParsing {
return variance;
}
- public static String parseTypeString(CharacterIterator signature) throws ClsFormatException {
+ @NotNull
+ public static String parseTypeString(@NotNull CharacterIterator signature) throws ClsFormatException {
int arrayDimensions = 0;
while (signature.current() == '[') {
arrayDimensions++;
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/JavaImportStatementElementType.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/JavaImportStatementElementType.java
index 7c9af30f1d9b..93e359e6778a 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/JavaImportStatementElementType.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/JavaImportStatementElementType.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-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.
@@ -24,7 +24,7 @@ import com.intellij.psi.impl.java.stubs.impl.PsiImportStatementStubImpl;
import com.intellij.psi.impl.source.PsiImportStatementImpl;
import com.intellij.psi.impl.source.PsiImportStaticStatementImpl;
import com.intellij.psi.impl.source.tree.JavaElementType;
-import com.intellij.psi.impl.source.tree.SourceUtil;
+import com.intellij.psi.impl.source.tree.JavaSourceUtil;
import com.intellij.psi.impl.source.tree.java.ImportStaticStatementElement;
import com.intellij.psi.stubs.IndexSink;
import com.intellij.psi.stubs.StubElement;
@@ -68,7 +68,7 @@ public abstract class JavaImportStatementElementType extends JavaStubElementType
for (LighterASTNode child : tree.getChildren(node)) {
IElementType type = child.getTokenType();
if (type == JavaElementType.JAVA_CODE_REFERENCE || type == JavaElementType.IMPORT_STATIC_REFERENCE) {
- refText = SourceUtil.getReferenceText(tree, child);
+ refText = JavaSourceUtil.getReferenceText(tree, child);
}
else if (type == JavaTokenType.ASTERISK) {
isOnDemand = true;
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/JavaLightStubBuilder.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/JavaLightStubBuilder.java
index ff8c80db3729..3413fda3a3fe 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/source/JavaLightStubBuilder.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/JavaLightStubBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-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.
@@ -44,7 +44,7 @@ public class JavaLightStubBuilder extends LightStubBuilder {
if (pkg != null) {
LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, pkg, JavaElementType.JAVA_CODE_REFERENCE);
if (ref != null) {
- refText = SourceUtil.getReferenceText(tree, ref);
+ refText = JavaSourceUtil.getReferenceText(tree, ref);
}
}
return new PsiJavaFileStubImpl((PsiJavaFile)file, StringRef.fromString(refText), false);
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java
index 55b760031646..807b42d60383 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java
@@ -587,7 +587,15 @@ public class PsiJavaCodeReferenceElementImpl extends CompositePsiElement impleme
if (parameterList != null) {
text += parameterList.getText();
}
- PsiJavaCodeReferenceElement ref = facade.getParserFacade().createReferenceFromText(text, getParent());
+
+ PsiJavaCodeReferenceElement ref;
+ try {
+ ref = facade.getParserFacade().createReferenceFromText(text, getParent());
+ }
+ catch (IncorrectOperationException e) {
+ throw new IncorrectOperationException(e.getMessage() + " [qname=" + qName + " class=" + aClass + ";" + aClass.getClass().getName() + "]");
+ }
+
((PsiJavaCodeReferenceElementImpl)ref).setAnnotations(annotations);
getTreeParent().replaceChildInternal(this, (TreeElement)ref.getNode());
@@ -743,7 +751,7 @@ public class PsiJavaCodeReferenceElementImpl extends CompositePsiElement impleme
private String getNormalizedText() {
String whiteSpaceAndComments = myCachedNormalizedText;
if (whiteSpaceAndComments == null) {
- myCachedNormalizedText = whiteSpaceAndComments = SourceUtil.getReferenceText(this);
+ myCachedNormalizedText = whiteSpaceAndComments = JavaSourceUtil.getReferenceText(this);
}
return whiteSpaceAndComments;
}
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/ClassResolverProcessor.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/ClassResolverProcessor.java
index a2e5593478eb..3e081a738caf 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/ClassResolverProcessor.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/ClassResolverProcessor.java
@@ -38,6 +38,7 @@ public class ClassResolverProcessor extends BaseScopeProcessor implements NameHi
@NotNull
private final PsiFile myContainingFile;
private final PsiElement myPlace;
+ private final PsiResolveHelper myResolveHelper;
private PsiClass myAccessClass = null;
private List<ClassCandidateInfo> myCandidates = null;
private boolean myHasAccessibleCandidate;
@@ -67,6 +68,7 @@ public class ClassResolverProcessor extends BaseScopeProcessor implements NameHi
}
}
}
+ myResolveHelper = JavaPsiFacade.getInstance(containingFile.getProject()).getResolveHelper();
}
@NotNull
@@ -252,8 +254,7 @@ public class ClassResolverProcessor extends BaseScopeProcessor implements NameHi
}
private boolean checkAccessibility(final PsiClass aClass) {
- JavaPsiFacade facade = JavaPsiFacade.getInstance(aClass.getProject());
- return facade.getResolveHelper().isAccessible(aClass, myPlace, myAccessClass);
+ return myResolveHelper.isAccessible(aClass, myPlace, myAccessClass);
}
@Override
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java
index f16231ac8d26..6098199c591c 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java
@@ -379,7 +379,7 @@ public class InferenceSession {
PsiType returnType = method.getReturnType();
if (!PsiType.VOID.equals(returnType) && returnType != null) {
PsiType targetType = getTargetType(context);
- if (targetType != null) {
+ if (targetType != null && !PsiType.VOID.equals(targetType)) {
registerReturnTypeConstraints(PsiUtil.isRawSubstitutor(method, mySiteSubstitutor) ? returnType : mySiteSubstitutor.substitute(returnType), targetType);
}
}
@@ -970,7 +970,8 @@ public class InferenceSession {
addConstraint(new TypeCompatibilityConstraint(getParameterType(parameters, i, PsiSubstitutor.EMPTY, varargs), pType));
}
}
- else if (parameters.length + 1 == functionalMethodParameters.length && !varargs || !isStatic && varargs && functionalMethodParameters.length > 0) { //instance methods
+ else if (parameters.length + 1 == functionalMethodParameters.length && !varargs ||
+ !isStatic && varargs && functionalMethodParameters.length > 0 && PsiMethodReferenceUtil.hasReceiver(reference, method)) { //instance methods
initBounds(containingClass.getTypeParameters());
final PsiType pType = signature.getParameterTypes()[0];
@@ -1020,13 +1021,13 @@ public class InferenceSession {
*/
public static boolean isMoreSpecific(PsiMethod m1,
PsiMethod m2,
- PsiSubstitutor siteSubstitutor2,
PsiExpression[] args,
PsiElement context,
boolean varargs) {
- final PsiTypeParameter[] typeParameters = m2.getTypeParameters();
-
- final InferenceSession session = new InferenceSession(typeParameters, siteSubstitutor2, m2.getManager(), context);
+ final InferenceSession session = new InferenceSession(PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY, m2.getManager(), context);
+ for (PsiTypeParameter param : PsiUtil.typeParametersIterable(m2)) {
+ session.initBounds(param);
+ }
final PsiParameter[] parameters1 = m1.getParameterList().getParameters();
final PsiParameter[] parameters2 = m2.getParameterList().getParameters();
@@ -1036,8 +1037,8 @@ public class InferenceSession {
final int paramsLength = !varargs ? parameters1.length : parameters1.length - 1;
for (int i = 0; i < paramsLength; i++) {
- PsiType sType = getParameterType(parameters1, i, siteSubstitutor2, false);
- PsiType tType = getParameterType(parameters2, i, siteSubstitutor2, varargs);
+ PsiType sType = getParameterType(parameters1, i, PsiSubstitutor.EMPTY, false);
+ PsiType tType = getParameterType(parameters2, i, PsiSubstitutor.EMPTY, varargs);
if (session.isProperType(sType) && session.isProperType(tType)) {
if (!TypeConversionUtil.isAssignable(tType, sType)) {
return false;
@@ -1054,8 +1055,8 @@ public class InferenceSession {
}
if (varargs) {
- PsiType sType = getParameterType(parameters1, paramsLength, siteSubstitutor2, true);
- PsiType tType = getParameterType(parameters2, paramsLength, siteSubstitutor2, true);
+ PsiType sType = getParameterType(parameters1, paramsLength, PsiSubstitutor.EMPTY, true);
+ PsiType tType = getParameterType(parameters2, paramsLength, PsiSubstitutor.EMPTY, true);
session.addConstraint(new StrictSubtypingConstraint(tType, sType));
}
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/PsiMethodReferenceCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/PsiMethodReferenceCompatibilityConstraint.java
index 175f083ce319..18d0c49e79d4 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/PsiMethodReferenceCompatibilityConstraint.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/PsiMethodReferenceCompatibilityConstraint.java
@@ -21,6 +21,7 @@ import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfacePa
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession;
import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil;
import com.intellij.psi.infos.MethodCandidateInfo;
+import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.TypeConversionUtil;
@@ -60,6 +61,10 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
final PsiType interfaceMethodReturnType = interfaceMethod.getReturnType();
final PsiType returnType = substitutor.substitute(interfaceMethodReturnType);
final PsiType[] typeParameters = myExpression.getTypeParameters();
+
+ final PsiMethodReferenceUtil.QualifierResolveResult qualifierResolveResult = PsiMethodReferenceUtil.getQualifierResolveResult(myExpression);
+ PsiSubstitutor psiSubstitutor = qualifierResolveResult.getSubstitutor();
+
if (!myExpression.isExact()) {
for (PsiParameter parameter : targetParameters) {
if (!session.isProperType(substitutor.substitute(parameter.getType()))) {
@@ -70,11 +75,9 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
final PsiMember applicableMember = myExpression.getPotentiallyApplicableMember();
LOG.assertTrue(applicableMember != null);
- final PsiMethodReferenceUtil.QualifierResolveResult qualifierResolveResult = PsiMethodReferenceUtil.getQualifierResolveResult(myExpression);
final PsiClass applicableMemberContainingClass = applicableMember.getContainingClass();
final PsiClass containingClass = qualifierResolveResult.getContainingClass();
- PsiSubstitutor psiSubstitutor = qualifierResolveResult.getSubstitutor();
psiSubstitutor = applicableMemberContainingClass == null || containingClass == null || myExpression.isConstructor()
? psiSubstitutor
: TypeConversionUtil.getSuperClassSubstitutor(applicableMemberContainingClass, containingClass, psiSubstitutor);
@@ -143,6 +146,13 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
final PsiType referencedMethodReturnType;
final PsiClass containingClass = method.getContainingClass();
LOG.assertTrue(containingClass != null, method);
+
+ PsiClass qContainingClass = qualifierResolveResult.getContainingClass();
+ if (qContainingClass != null && InheritanceUtil.isInheritorOrSelf(qContainingClass, containingClass, true)) {
+ psiSubstitutor = TypeConversionUtil.getClassSubstitutor(containingClass, qContainingClass, PsiSubstitutor.EMPTY);
+ LOG.assertTrue(psiSubstitutor != null);
+ }
+
if (method.isConstructor()) {
referencedMethodReturnType = JavaPsiFacade.getElementFactory(method.getProject()).createType(containingClass, PsiSubstitutor.EMPTY);
}
@@ -179,7 +189,6 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
}
int idx = 0;
- PsiSubstitutor psiSubstitutor = PsiSubstitutor.EMPTY;
for (PsiTypeParameter param : method.getTypeParameters()) {
if (idx < typeParameters.length) {
psiSubstitutor = psiSubstitutor.put(param, typeParameters[idx++]);
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java
index 4fbbad26964d..8d42dbeb4f90 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java
@@ -84,8 +84,8 @@ public interface JavaElementType {
IElementType PARAMETER_LIST = JavaStubElementTypes.PARAMETER_LIST;
IElementType EXTENDS_BOUND_LIST = JavaStubElementTypes.EXTENDS_BOUND_LIST;
IElementType THROWS_LIST = JavaStubElementTypes.THROWS_LIST;
- IElementType LITERAL_EXPRESSION = new JavaCompositeElementType("LITERAL_EXPRESSION", PsiLiteralExpressionImpl.class);
+ IElementType LITERAL_EXPRESSION = new JavaCompositeElementType("LITERAL_EXPRESSION", PsiLiteralExpressionImpl.class);
IElementType IMPORT_STATIC_REFERENCE = new JavaCompositeElementType("IMPORT_STATIC_REFERENCE", PsiImportStaticReferenceElementImpl.class);
IElementType TYPE = new JavaCompositeElementType("TYPE", PsiTypeElementImpl.class);
IElementType DIAMOND_TYPE = new JavaCompositeElementType("DIAMOND_TYPE", PsiDiamondTypeElementImpl.class);
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaSourceUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaSourceUtil.java
index 8cf5b5bfbdd2..e2af7b08df0d 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaSourceUtil.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaSourceUtil.java
@@ -15,13 +15,28 @@
*/
package com.intellij.psi.impl.source.tree;
+import com.intellij.lang.ASTFactory;
import com.intellij.lang.ASTNode;
+import com.intellij.lang.LighterAST;
+import com.intellij.lang.LighterASTNode;
+import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.*;
+import com.intellij.psi.codeStyle.CodeStyleManager;
+import com.intellij.psi.impl.source.DummyHolder;
import com.intellij.psi.impl.source.SourceJavaCodeReference;
+import com.intellij.psi.impl.source.SourceTreeToPsiMap;
+import com.intellij.psi.tree.IElementType;
+import com.intellij.psi.tree.TokenSet;
import com.intellij.util.CharTable;
+import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
public class JavaSourceUtil {
+ private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.JavaSourceUtil");
+
+ private static final TokenSet REF_FILTER = TokenSet.orSet(
+ ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET, TokenSet.create(JavaElementType.ANNOTATION));
+
private JavaSourceUtil() { }
public static void fullyQualifyReference(@NotNull CompositeElement reference, @NotNull PsiClass targetClass) {
@@ -61,4 +76,70 @@ public class JavaSourceUtil {
}
}
}
+
+ @NotNull
+ public static String getReferenceText(@NotNull PsiJavaCodeReferenceElement ref) {
+ final StringBuilder buffer = new StringBuilder();
+
+ ((TreeElement)ref.getNode()).acceptTree(new RecursiveTreeElementWalkingVisitor() {
+ @Override
+ public void visitLeaf(LeafElement leaf) {
+ if (!REF_FILTER.contains(leaf.getElementType())) {
+ String leafText = leaf.getText();
+ if (buffer.length() > 0 && !leafText.isEmpty() && Character.isJavaIdentifierPart(leafText.charAt(0))) {
+ char lastInBuffer = buffer.charAt(buffer.length() - 1);
+ if (lastInBuffer == '?' || Character.isJavaIdentifierPart(lastInBuffer)) {
+ buffer.append(" ");
+ }
+ }
+
+ buffer.append(leafText);
+ }
+ }
+
+ @Override
+ public void visitComposite(CompositeElement composite) {
+ if (!REF_FILTER.contains(composite.getElementType())) {
+ super.visitComposite(composite);
+ }
+ }
+ });
+
+ return buffer.toString();
+ }
+
+ @NotNull
+ public static String getReferenceText(@NotNull LighterAST tree, @NotNull LighterASTNode node) {
+ return LightTreeUtil.toFilteredString(tree, node, REF_FILTER);
+ }
+
+ public static TreeElement addParenthToReplacedChild(@NotNull IElementType parenthType,
+ @NotNull TreeElement newChild,
+ @NotNull PsiManager manager) {
+ CompositeElement parenthExpr = ASTFactory.composite(parenthType);
+
+ TreeElement dummyExpr = (TreeElement)newChild.clone();
+ final CharTable charTableByTree = SharedImplUtil.findCharTableByTree(newChild);
+ new DummyHolder(manager, parenthExpr, null, charTableByTree);
+ parenthExpr.putUserData(CharTable.CHAR_TABLE_KEY, charTableByTree);
+ parenthExpr.rawAddChildren(ASTFactory.leaf(JavaTokenType.LPARENTH, "("));
+ parenthExpr.rawAddChildren(dummyExpr);
+ parenthExpr.rawAddChildren(ASTFactory.leaf(JavaTokenType.RPARENTH, ")"));
+
+ try {
+ CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject());
+ PsiElement formatted = codeStyleManager.reformat(SourceTreeToPsiMap.treeToPsiNotNull(parenthExpr));
+ parenthExpr = (CompositeElement)SourceTreeToPsiMap.psiToTreeNotNull(formatted);
+ }
+ catch (IncorrectOperationException e) {
+ LOG.error(e); // should not happen
+ }
+
+ newChild.putUserData(CharTable.CHAR_TABLE_KEY, SharedImplUtil.findCharTableByTree(newChild));
+ dummyExpr.getTreeParent().replaceChild(dummyExpr, newChild);
+
+ // TODO remove explicit caches drop since this should be ok if we will use ChangeUtil for the modification
+ TreeUtil.clearCaches(TreeUtil.getFileElement(parenthExpr));
+ return parenthExpr;
+ }
}
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/SourceUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/SourceUtil.java
index 93e9f60c890e..554580828c0b 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/SourceUtil.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/SourceUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-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.
@@ -15,94 +15,29 @@
*/
package com.intellij.psi.impl.source.tree;
-import com.intellij.lang.ASTFactory;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.psi.JavaTokenType;
-import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiJavaCodeReferenceElement;
import com.intellij.psi.PsiManager;
-import com.intellij.psi.codeStyle.CodeStyleManager;
-import com.intellij.psi.impl.source.DummyHolder;
-import com.intellij.psi.impl.source.SourceTreeToPsiMap;
import com.intellij.psi.tree.IElementType;
-import com.intellij.psi.tree.TokenSet;
-import com.intellij.util.CharTable;
-import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
+/** @deprecated use {@link JavaSourceUtil} (to be removed in IDEA 15) */
+@SuppressWarnings("UnusedDeclaration")
public class SourceUtil {
- private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.SourceUtil");
-
- private static final TokenSet REF_FILTER = TokenSet.orSet(
- ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET, TokenSet.create(JavaElementType.ANNOTATION));
-
private SourceUtil() { }
@NotNull
public static String getReferenceText(@NotNull PsiJavaCodeReferenceElement ref) {
- final StringBuilder buffer = new StringBuilder();
-
- ((TreeElement)ref.getNode()).acceptTree(new RecursiveTreeElementWalkingVisitor() {
- @Override
- public void visitLeaf(LeafElement leaf) {
- if (!REF_FILTER.contains(leaf.getElementType())) {
- String leafText = leaf.getText();
- if (buffer.length() > 0 && !leafText.isEmpty() && Character.isJavaIdentifierPart(leafText.charAt(0))) {
- char lastInBuffer = buffer.charAt(buffer.length() - 1);
- if (lastInBuffer == '?' || Character.isJavaIdentifierPart(lastInBuffer)) {
- buffer.append(" ");
- }
- }
-
- buffer.append(leafText);
- }
- }
-
- @Override
- public void visitComposite(CompositeElement composite) {
- if (!REF_FILTER.contains(composite.getElementType())) {
- super.visitComposite(composite);
- }
- }
- });
-
- return buffer.toString();
+ return JavaSourceUtil.getReferenceText(ref);
}
@NotNull
public static String getReferenceText(@NotNull LighterAST tree, @NotNull LighterASTNode node) {
- return LightTreeUtil.toFilteredString(tree, node, REF_FILTER);
+ return JavaSourceUtil.getReferenceText(tree, node);
}
- public static TreeElement addParenthToReplacedChild(@NotNull IElementType parenthType,
- @NotNull TreeElement newChild,
- @NotNull PsiManager manager) {
- CompositeElement parenthExpr = ASTFactory.composite(parenthType);
-
- TreeElement dummyExpr = (TreeElement)newChild.clone();
- final CharTable charTableByTree = SharedImplUtil.findCharTableByTree(newChild);
- new DummyHolder(manager, parenthExpr, null, charTableByTree);
- parenthExpr.putUserData(CharTable.CHAR_TABLE_KEY, charTableByTree);
- parenthExpr.rawAddChildren(ASTFactory.leaf(JavaTokenType.LPARENTH, "("));
- parenthExpr.rawAddChildren(dummyExpr);
- parenthExpr.rawAddChildren(ASTFactory.leaf(JavaTokenType.RPARENTH, ")"));
-
- try {
- CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject());
- PsiElement formatted = codeStyleManager.reformat(SourceTreeToPsiMap.treeToPsiNotNull(parenthExpr));
- parenthExpr = (CompositeElement)SourceTreeToPsiMap.psiToTreeNotNull(formatted);
- }
- catch (IncorrectOperationException e) {
- LOG.error(e); // should not happen
- }
-
- newChild.putUserData(CharTable.CHAR_TABLE_KEY, SharedImplUtil.findCharTableByTree(newChild));
- dummyExpr.getTreeParent().replaceChild(dummyExpr, newChild);
-
- // TODO remove explicit caches drop since this should be ok if we will use ChangeUtil for the modification
- TreeUtil.clearCaches(TreeUtil.getFileElement(parenthExpr));
- return parenthExpr;
+ public static TreeElement addParenthToReplacedChild(@NotNull IElementType parenthType, @NotNull TreeElement newChild, @NotNull PsiManager manager) {
+ return JavaSourceUtil.addParenthToReplacedChild(parenthType, newChild, manager);
}
}
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/ExpressionPsiElement.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/ExpressionPsiElement.java
index 1d8693efc55c..e0b122e95592 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/ExpressionPsiElement.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/ExpressionPsiElement.java
@@ -13,10 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-/*
- * @author max
- */
package com.intellij.psi.impl.source.tree.java;
import com.intellij.lang.ASTNode;
@@ -24,13 +20,11 @@ import com.intellij.psi.impl.source.tree.*;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
+/**
+ * @author max
+ */
public class ExpressionPsiElement extends CompositePsiElement {
- private final int myHC = CompositePsiElement.ourHC++;
-
- @Override
- public final int hashCode() {
- return myHC;
- }
+ @SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod") private final int myHC = CompositePsiElement.ourHC++;
public ExpressionPsiElement(final IElementType type) {
super(type);
@@ -42,9 +36,14 @@ public class ExpressionPsiElement extends CompositePsiElement {
ElementType.EXPRESSION_BIT_SET.contains(newElement.getElementType())) {
boolean needParenth = ReplaceExpressionUtil.isNeedParenthesis(child, newElement);
if (needParenth) {
- newElement = SourceUtil.addParenthToReplacedChild(JavaElementType.PARENTH_EXPRESSION, newElement, getManager());
+ newElement = JavaSourceUtil.addParenthToReplacedChild(JavaElementType.PARENTH_EXPRESSION, newElement, getManager());
}
}
super.replaceChildInternal(child, newElement);
}
+
+ @Override
+ public final int hashCode() {
+ return myHC;
+ }
}
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodElement.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodElement.java
index 31fb4bca8833..1edd7cbaec76 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodElement.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodElement.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-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.
@@ -41,14 +41,15 @@ public class MethodElement extends CompositeElement implements Constants {
@Override
public int getTextOffset() {
- return findChildByRole(ChildRole.NAME).getStartOffset();
+ ASTNode name = findChildByType(IDENTIFIER);
+ return name != null ? name.getStartOffset() : this.getStartOffset();
}
@Override
public TreeElement addInternal(TreeElement first, ASTNode last, ASTNode anchor, Boolean before) {
- if (first == last && first.getElementType() == JavaElementType.CODE_BLOCK){
- ASTNode semicolon = findChildByRole(ChildRole.CLOSING_SEMICOLON);
- if (semicolon != null){
+ if (first == last && first.getElementType() == JavaElementType.CODE_BLOCK) {
+ ASTNode semicolon = TreeUtil.findChildBackward(this, SEMICOLON);
+ if (semicolon != null) {
deleteChildInternal(semicolon);
}
}
@@ -64,7 +65,7 @@ public class MethodElement extends CompositeElement implements Constants {
@Override
public void deleteChildInternal(@NotNull ASTNode child) {
- if (child.getElementType() == CODE_BLOCK){
+ if (child.getElementType() == CODE_BLOCK) {
final ASTNode prevWS = TreeUtil.prevLeaf(child);
if (prevWS != null && prevWS.getElementType() == TokenType.WHITE_SPACE) {
removeChild(prevWS);
@@ -80,9 +81,9 @@ public class MethodElement extends CompositeElement implements Constants {
}
@Override
- public ASTNode findChildByRole(int role){
+ public ASTNode findChildByRole(int role) {
LOG.assertTrue(ChildRole.isUnique(role));
- switch(role){
+ switch (role) {
default:
return null;
@@ -161,5 +162,4 @@ public class MethodElement extends CompositeElement implements Constants {
protected boolean isVisibilitySupported() {
return true;
}
-
}
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java
index 2209efe4141b..95171ba30bc9 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java
@@ -434,7 +434,7 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
return true;
}
- final PsiSubstitutor subst = result.getSubstitutor();
+ PsiSubstitutor subst = result.getSubstitutor();
PsiType methodReturnType = null;
PsiClass containingClass = null;
@@ -451,6 +451,12 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
return false;
}
+ PsiClass qContainingClass = PsiMethodReferenceUtil.getQualifierResolveResult(this).getContainingClass();
+ if (qContainingClass != null && containingClass != null && InheritanceUtil.isInheritorOrSelf(qContainingClass, containingClass, true)) {
+ subst = TypeConversionUtil.getClassSubstitutor(containingClass, qContainingClass, subst);
+ LOG.assertTrue(subst != null);
+ }
+
methodReturnType = subst.substitute(returnType);
}
else if (resolve instanceof PsiClass) {
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiPackageStatementImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiPackageStatementImpl.java
index 5a42715590ef..29d072970560 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiPackageStatementImpl.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiPackageStatementImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-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.
@@ -38,7 +38,7 @@ public class PsiPackageStatementImpl extends CompositePsiElement implements PsiP
@Override
public String getPackageName() {
PsiJavaCodeReferenceElement ref = getPackageReference();
- return ref == null ? null : SourceUtil.getReferenceText(ref);
+ return ref == null ? null : JavaSourceUtil.getReferenceText(ref);
}
@Override
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiReferenceExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiReferenceExpressionImpl.java
index 02ffaa6f3c20..8dd43933c660 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiReferenceExpressionImpl.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiReferenceExpressionImpl.java
@@ -761,7 +761,7 @@ public class PsiReferenceExpressionImpl extends PsiReferenceExpressionBase imple
private String getCachedNormalizedText() {
String whiteSpaceAndComments = myCachedNormalizedText;
if (whiteSpaceAndComments == null) {
- myCachedNormalizedText = whiteSpaceAndComments = SourceUtil.getReferenceText(this);
+ myCachedNormalizedText = whiteSpaceAndComments = JavaSourceUtil.getReferenceText(this);
}
return whiteSpaceAndComments;
}