mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'groovySchemes'
This commit is contained in:
@@ -40,6 +40,10 @@ import com.intellij.pom.PomTarget;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.light.LightElement;
|
||||
import com.intellij.psi.infos.CandidateInfo;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.SearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.search.searches.SuperMethodsSearch;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.MethodSignature;
|
||||
@@ -189,6 +193,10 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
if (resolved instanceof PsiMember) {
|
||||
highlightMemberResolved(myHolder, referenceExpression, ((PsiMember)resolved));
|
||||
}
|
||||
else if (resolved instanceof GrVariable) {
|
||||
highlightVariable((GrVariable)resolved, getElementToHighlight(referenceExpression));
|
||||
}
|
||||
|
||||
/*if (!resolveResult.isAccessible()) {
|
||||
String message = GroovyBundle.message("cannot.access", referenceExpression.getReferenceName());
|
||||
final Annotation annotation = myHolder.createWarningAnnotation(getElementToHighlight(referenceExpression), message);
|
||||
@@ -262,6 +270,35 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
}
|
||||
}
|
||||
|
||||
private void highlightVariable(GrVariable variable, PsiElement toHighlight) {
|
||||
Annotation annotation = myHolder.createInfoAnnotation(toHighlight, null);
|
||||
boolean reassigned = isReassigned(variable);
|
||||
if (variable instanceof GrParameter) {
|
||||
annotation
|
||||
.setTextAttributes(reassigned ? DefaultHighlighter.REASSIGNED_PARAMETER : DefaultHighlighter.PARAMETER);
|
||||
} else {
|
||||
annotation
|
||||
.setTextAttributes(reassigned ? DefaultHighlighter.REASSIGNED_LOCAL_VARIABLE : DefaultHighlighter.LOCAL_VARIABLE);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isReassigned(GrVariable var) {
|
||||
PsiMethod method = PsiTreeUtil.getParentOfType(var, PsiMethod.class);
|
||||
boolean hasAssignment = var.getInitializerGroovy() != null || var instanceof GrParameter;
|
||||
SearchScope scope = method == null ? GlobalSearchScope.projectScope(var.getProject()) : new LocalSearchScope(method);
|
||||
for (PsiReference reference : ReferencesSearch.search(var, scope).findAll()) {
|
||||
if (reference instanceof GrReferenceExpression &&
|
||||
(PsiUtil.isLValue((GrReferenceExpression)reference) ||
|
||||
((GrReferenceExpression)reference).getParent() instanceof GrPostfixExpression)) {
|
||||
if (hasAssignment) {
|
||||
return true;
|
||||
}
|
||||
hasAssignment = true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean shouldHighlightAsUnresolved(@NotNull GrReferenceExpression referenceExpression) {
|
||||
PsiElement refNameElement = referenceExpression.getReferenceNameElement();
|
||||
if (refNameElement != null && referenceExpression.getQualifier() == null) {
|
||||
@@ -485,6 +522,10 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
|
||||
@Override
|
||||
public void visitMethod(GrMethod method) {
|
||||
if (!method.isConstructor()) {
|
||||
myHolder.createInfoAnnotation(method.getNameIdentifierGroovy(), null).setTextAttributes(DefaultHighlighter.METHOD_DECLARATION);
|
||||
}
|
||||
|
||||
checkMethodDefinitionModifiers(myHolder, method);
|
||||
checkMethodWithTypeParamsShouldHaveReturnType(myHolder, method);
|
||||
checkInnerMethod(myHolder, method);
|
||||
@@ -576,6 +617,8 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
checkName(variable);
|
||||
if (variable instanceof GrMember) {
|
||||
highlightMember(myHolder, ((GrMember)variable));
|
||||
} else {
|
||||
highlightVariable(variable, variable.getNameIdentifierGroovy());
|
||||
}
|
||||
|
||||
PsiNamedElement duplicate = ResolveUtil
|
||||
|
||||
@@ -94,6 +94,18 @@ public class DefaultHighlighter {
|
||||
public static TextAttributesKey ANNOTATION = TextAttributesKey.createTextAttributesKey(ANNOTATION_ID,
|
||||
HighlightInfoType.ANNOTATION_NAME.getAttributesKey().getDefaultAttributes());
|
||||
|
||||
public static TextAttributesKey LOCAL_VARIABLE = TextAttributesKey.createTextAttributesKey("Groovy var",
|
||||
HighlightInfoType.LOCAL_VARIABLE.getAttributesKey().getDefaultAttributes());
|
||||
public static TextAttributesKey REASSIGNED_LOCAL_VARIABLE = TextAttributesKey.createTextAttributesKey("Groovy reassigned var",
|
||||
HighlightInfoType.REASSIGNED_LOCAL_VARIABLE.getAttributesKey().getDefaultAttributes());
|
||||
public static TextAttributesKey PARAMETER = TextAttributesKey.createTextAttributesKey("Groovy parameter",
|
||||
HighlightInfoType.PARAMETER.getAttributesKey().getDefaultAttributes());
|
||||
public static TextAttributesKey REASSIGNED_PARAMETER = TextAttributesKey.createTextAttributesKey("Groovy reassigned parameter",
|
||||
HighlightInfoType.REASSIGNED_PARAMETER.getAttributesKey().getDefaultAttributes());
|
||||
|
||||
public static TextAttributesKey METHOD_DECLARATION = TextAttributesKey.createTextAttributesKey("Groovy method declaration",
|
||||
HighlightInfoType.METHOD_DECLARATION.getAttributesKey().getDefaultAttributes());
|
||||
|
||||
public static TextAttributesKey INSTANCE_FIELD = TextAttributesKey.createTextAttributesKey(INSTANCE_FIELD_ID,
|
||||
HighlightInfoType.INSTANCE_FIELD.getAttributesKey().getDefaultAttributes());
|
||||
|
||||
|
||||
+17
-5
@@ -67,10 +67,15 @@ public class GroovyColorsAndFontsPage implements ColorSettingsPage {
|
||||
new AttributesDescriptor("Unresolved reference access", DefaultHighlighter.UNRESOLVED_ACCESS),
|
||||
new AttributesDescriptor("List/map to object conversion", DefaultHighlighter.LITERAL_CONVERSION),
|
||||
new AttributesDescriptor("Annotation", DefaultHighlighter.ANNOTATION),
|
||||
new AttributesDescriptor("Local variable", DefaultHighlighter.LOCAL_VARIABLE),
|
||||
new AttributesDescriptor("Reassigned local variable", DefaultHighlighter.REASSIGNED_LOCAL_VARIABLE),
|
||||
new AttributesDescriptor("Parameter", DefaultHighlighter.PARAMETER),
|
||||
new AttributesDescriptor("Reassigned parameter", DefaultHighlighter.REASSIGNED_PARAMETER),
|
||||
new AttributesDescriptor("Static field", DefaultHighlighter.STATIC_FIELD),
|
||||
new AttributesDescriptor("Instance field", DefaultHighlighter.INSTANCE_FIELD),
|
||||
new AttributesDescriptor("Instance method call", DefaultHighlighter.METHOD_CALL),
|
||||
new AttributesDescriptor("Static method call", DefaultHighlighter.STATIC_METHOD_ACCESS),
|
||||
new AttributesDescriptor("Method declaration", DefaultHighlighter.METHOD_DECLARATION),
|
||||
new AttributesDescriptor("Class reference", DefaultHighlighter.CLASS_REFERENCE),
|
||||
new AttributesDescriptor("Map key accessed as a property", DefaultHighlighter.MAP_KEY),
|
||||
new AttributesDescriptor("Instance property reference", DefaultHighlighter.INSTANCE_PROPERTY_REFERENCE),
|
||||
@@ -103,10 +108,11 @@ public class GroovyColorsAndFontsPage implements ColorSettingsPage {
|
||||
" def <instfield>property</instfield>\n" +
|
||||
"//This is a line comment\n" +
|
||||
"/* This is a block comment */\n" +
|
||||
" static def foo(int i) {\n" +
|
||||
" <classref>Map</classref> map = [key:1, b:2]\n" +
|
||||
" static def <method>foo</method>(int <param>i</param>, int <reParam>j</reParam>) {\n" +
|
||||
" <classref>Map</classref> map = [<mapkey>key</mapkey>:1, <mapkey>b</mapkey>:2]\n" +
|
||||
" <reParam>j</reParam>++\n" +
|
||||
" print map.<mapkey>key</mapkey>\n" +
|
||||
" return [i, i, <instfield>property</instfield>]\n" +
|
||||
" return [<param>i</param>, <instfield>property</instfield>]\n" +
|
||||
" }\n" +
|
||||
" static def <statfield>panel</statfield> = new <classref>JPanel</classref>()\n" +
|
||||
"}\n" +
|
||||
@@ -114,8 +120,9 @@ public class GroovyColorsAndFontsPage implements ColorSettingsPage {
|
||||
"<classref>Demo</classref>.<statfield>panel</statfield>.size = " +
|
||||
"<classref>Demo</classref>.<statmet>foo</statmet>(\"123${456}789\".toInteger()) \n" +
|
||||
"'JetBrains'.matches(/Jw+Bw+/) \n" +
|
||||
"def x=1 + <unresolved>unresolved</unresolved>\n" +
|
||||
"def f1 = []\n" +
|
||||
"def <local>x</local>=1 + <unresolved>unresolved</unresolved>\n" +
|
||||
"def <reLocal>f1</reLocal> = []\n" +
|
||||
"<reLocal>f1</reLocal> = [2]\n" +
|
||||
"<classref>File</classref> f=<literal>[</literal>'path'<literal>]</literal>\n" +
|
||||
"print new <classref>Demo</classref>().<prop>property</prop>\n" +
|
||||
"print '<validescape>\\n</validescape> <invalidescape>\\x</invalidescape>'"
|
||||
@@ -140,6 +147,11 @@ public class GroovyColorsAndFontsPage implements ColorSettingsPage {
|
||||
map.put("staticprop", DefaultHighlighter.STATIC_PROPERTY_REFERENCE);
|
||||
map.put("validescape", DefaultHighlighter.VALID_STRING_ESCAPE);
|
||||
map.put("invalidescape", DefaultHighlighter.INVALID_STRING_ESCAPE);
|
||||
map.put("local", DefaultHighlighter.LOCAL_VARIABLE);
|
||||
map.put("reLocal", DefaultHighlighter.REASSIGNED_LOCAL_VARIABLE);
|
||||
map.put("param", DefaultHighlighter.PARAMETER);
|
||||
map.put("reParam", DefaultHighlighter.REASSIGNED_PARAMETER);
|
||||
map.put("method", DefaultHighlighter.METHOD_DECLARATION);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -691,4 +691,8 @@ public class CorrectImplementor implements ActionListener {
|
||||
''')
|
||||
myFixture.testHighlighting(true, false, false)
|
||||
}
|
||||
|
||||
public void testReassignedHighlighting() {
|
||||
myFixture.testHighlighting(true, true, true, getTestName(false) + ".groovy");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
def <info textAttributesKey="Groovy method declaration">method</info>(int <info textAttributesKey="Groovy parameter">param1</info>, int <info textAttributesKey="Groovy reassigned parameter">param2</info>) {
|
||||
int <info textAttributesKey="Groovy var">var1</info> = 0
|
||||
int <info textAttributesKey="Groovy reassigned var">var2</info> = 1
|
||||
int <info textAttributesKey="Groovy reassigned var">var3</info> = 1
|
||||
if (<info textAttributesKey="Groovy parameter">param1</info> == 1) {
|
||||
<info textAttributesKey="Groovy reassigned parameter">param2</info> = <info textAttributesKey="Groovy reassigned var">var2</info> = 2
|
||||
<info textAttributesKey="Groovy reassigned var">var3</info>++
|
||||
}
|
||||
<info textAttributesKey="Method call">println</info> <info textAttributesKey="Groovy var">var1</info> +
|
||||
<info textAttributesKey="Groovy reassigned var">var2</info> +
|
||||
<info textAttributesKey="Groovy parameter">param1</info> +
|
||||
<info textAttributesKey="Groovy reassigned parameter">param2</info>
|
||||
}
|
||||
|
||||
<info textAttributesKey="Method call">method</info>(239, 42)
|
||||
Reference in New Issue
Block a user