Method reverences language level highlighting

This commit is contained in:
Roman Shevchenko
2012-06-04 12:18:58 +04:00
parent 94e69692bc
commit 679ab25896
6 changed files with 32 additions and 3 deletions
@@ -2538,7 +2538,8 @@ public class HighlightUtil {
TRY_WITH_RESOURCES(LanguageLevel.JDK_1_7, "feature.try.with.resources"),
BIN_LITERALS(LanguageLevel.JDK_1_7, "feature.binary.literals"),
UNDERSCORES(LanguageLevel.JDK_1_7, "feature.underscores.in.literals"),
EXTENSION_METHODS(LanguageLevel.JDK_1_8, "feature.extension.methods");
EXTENSION_METHODS(LanguageLevel.JDK_1_8, "feature.extension.methods"),
METHOD_REFERENCES(LanguageLevel.JDK_1_8, "feature.method.references");
private final LanguageLevel level;
private final String key;
@@ -2606,4 +2607,9 @@ public class HighlightUtil {
public static HighlightInfo checkExtensionMethodsFeature(final PsiMethod method) {
return checkFeature(method, Feature.EXTENSION_METHODS);
}
@Nullable
public static HighlightInfo checkMethodReferencesFeature(final PsiMethodReferenceExpression expression) {
return checkFeature(expression, Feature.METHOD_REFERENCES);
}
}
@@ -892,7 +892,13 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkClassReferenceAfterQualifier(expression, resolved));
}
@Override public void visitReferenceList(PsiReferenceList list) {
@Override
public void visitMethodReferenceExpression(PsiMethodReferenceExpression expression) {
myHolder.add(HighlightUtil.checkMethodReferencesFeature(expression));
}
@Override
public void visitReferenceList(PsiReferenceList list) {
if (list.getFirstChild() == null) return;
PsiElement parent = list.getParent();
if (!(parent instanceof PsiTypeParameter)) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -244,6 +244,10 @@ public abstract class JavaElementVisitor extends PsiElementVisitor {
*/
public void visitReferenceExpression(PsiReferenceExpression expression) {}
public void visitMethodReferenceExpression(PsiMethodReferenceExpression expression) {
visitReferenceExpression(expression);
}
public void visitReferenceList(PsiReferenceList list) {
visitElement(list);
}
@@ -104,6 +104,16 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
return element.getManager().areElementsEquivalent(element, resolve());
}
@Override
public void accept(@NotNull final PsiElementVisitor visitor) {
if (visitor instanceof JavaElementVisitor) {
((JavaElementVisitor)visitor).visitMethodReferenceExpression(this);
}
else {
visitor.visitElement(this);
}
}
@Override
public String toString() {
return "PsiMethodReferenceExpression:" + getText();
@@ -353,4 +353,5 @@ feature.try.with.resources=Try-with-resources
feature.binary.literals=Binary literals
feature.underscores.in.literals=Underscores in literals
feature.extension.methods=Extension methods
feature.method.references=Method references
insufficient.language.level={0} are not supported at this language level
@@ -37,6 +37,8 @@ class UnsupportedFeatures {
catch (<error descr="Multi-catches are not supported at this language level">FileNotFoundException | IOException e</error>) { e.printStackTrace(); }
try <error descr="Try-with-resources are not supported at this language level">(Reader r = new FileReader("/dev/null"))</error> { }
I i = <error descr="Method references are not supported at this language level">UnsupportedFeatures::m</error>;
}
interface I {