mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
groovy: suggest 'def' before an assignment
This commit is contained in:
+5
-9
@@ -606,7 +606,9 @@ public class GroovyCompletionData {
|
||||
}
|
||||
|
||||
private static boolean suggestModifiers(PsiElement context) {
|
||||
if (GroovyCompletionUtil.asSimpleVariable(context) || GroovyCompletionUtil.asTypedMethod(context)) {
|
||||
if (GroovyCompletionUtil.asSimpleVariable(context) ||
|
||||
GroovyCompletionUtil.asTypedMethod(context) ||
|
||||
GroovyCompletionUtil.isNewStatementInScript(context)) {
|
||||
return true;
|
||||
}
|
||||
if (GroovyCompletionUtil.isFirstElementAfterPossibleModifiersInVariableDeclaration(context, false) &&
|
||||
@@ -640,13 +642,6 @@ public class GroovyCompletionData {
|
||||
if (context.getTextRange().getStartOffset() == 0 && !(context instanceof OuterLanguageElement)) {
|
||||
return true;
|
||||
}
|
||||
final PsiElement leaf = GroovyCompletionUtil.getLeafByOffset(context.getTextRange().getStartOffset() - 1, context);
|
||||
if (leaf != null && GroovyCompletionUtil.isNewStatement(context, false)) {
|
||||
PsiElement parent = leaf.getParent();
|
||||
if (parent instanceof GroovyFile) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return contextParent instanceof GrExpression &&
|
||||
contextParent.getParent() instanceof GrApplicationStatement &&
|
||||
contextParent.getParent().getParent() instanceof GroovyFile &&
|
||||
@@ -656,7 +651,8 @@ public class GroovyCompletionData {
|
||||
public static boolean suggestFinalDef(PsiElement context) {
|
||||
if (GroovyCompletionUtil.asSimpleVariable(context) ||
|
||||
GroovyCompletionUtil.asTypedMethod(context) ||
|
||||
GroovyCompletionUtil.asVariableInBlock(context)) {
|
||||
GroovyCompletionUtil.asVariableInBlock(context) ||
|
||||
GroovyCompletionUtil.isNewStatementInScript(context)) {
|
||||
return true;
|
||||
}
|
||||
if ((context.getParent() instanceof GrParameter &&
|
||||
|
||||
+12
@@ -51,6 +51,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.formatter.GeeseUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.GrReferenceAdjuster;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation;
|
||||
@@ -565,4 +566,15 @@ public class GroovyCompletionUtil {
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
static boolean isNewStatementInScript(PsiElement context) {
|
||||
final PsiElement leaf = getLeafByOffset(context.getTextRange().getStartOffset() - 1, context);
|
||||
if (leaf != null && isNewStatement(context, false)) {
|
||||
PsiElement parent = leaf.getParent();
|
||||
if (parent instanceof GroovyFile) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -984,6 +984,8 @@ println "abcd"
|
||||
|
||||
public void testIfParenthesis() { checkCompletion 'int iff; if<caret>', '(', "int iff; if (<caret>)" }
|
||||
|
||||
public void testMakingDefFromAssignment() { checkCompletion 'int defInt; de<caret>foo = 2', 'f ', "int defInt; def <caret>foo = 2" }
|
||||
|
||||
public void testEnumPropertyType() {
|
||||
checkSingleItemCompletion 'enum Foo {a,b; static List<StringBui<caret>>', "enum Foo {a,b; static List<StringBuilder<caret>>"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user