Skip to content

Commit 24ecfb3

Browse files
authored
Merge pull request #9225 from lahodaj/GITHUB-9182
[GITHUB-9182] Fixing code completion for record component types.
2 parents 9f2f330 + c9268b7 commit 24ecfb3

6 files changed

Lines changed: 38 additions & 22 deletions

File tree

java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3356,7 +3356,6 @@ private void insideRecord(Env env) throws IOException {
33563356
}
33573357
List<? extends Tree> members = cls.getMembers();
33583358

3359-
Tree lastParam = null;
33603359
for (Tree member : members) {
33613360
if (member.getKind() == Tree.Kind.VARIABLE) {
33623361
ModifiersTree modifiers = ((VariableTree) member).getModifiers();
@@ -3367,29 +3366,9 @@ private void insideRecord(Env env) throws IOException {
33673366
if (paramPos == Diagnostic.NOPOS || offset <= paramPos) {
33683367
break;
33693368
}
3370-
lastParam = member;
33713369
startPos = paramPos;
33723370
}
33733371
}
3374-
3375-
if (lastParam != null) {
3376-
TokenSequence<JavaTokenId> first = findFirstNonWhitespaceToken(env, startPos, offset);
3377-
if (first != null && first.token().id() == JavaTokenId.COMMA) {
3378-
controller.toPhase(Phase.ELEMENTS_RESOLVED);
3379-
env.addToExcludes(controller.getTrees().getElement(path));
3380-
addTypes(env, EnumSet.of(INTERFACE, ANNOTATION_TYPE), null);
3381-
return;
3382-
}
3383-
if (first != null && first.token().id() == JavaTokenId.RPAREN) {
3384-
first = nextNonWhitespaceToken(first);
3385-
if (!tu.isInterface(cls) && first.token().id() == JavaTokenId.LBRACE) {
3386-
addKeyword(env, IMPLEMENTS_KEYWORD, SPACE, false);
3387-
}
3388-
3389-
}
3390-
return;
3391-
}
3392-
33933372
}
33943373

33953374
TypeParameterTree lastTypeParam = null;
@@ -3405,7 +3384,7 @@ private void insideRecord(Env env) throws IOException {
34053384
TokenSequence<JavaTokenId> lastNonWhitespaceToken = findLastNonWhitespaceToken(env, startPos, offset);
34063385
if (lastNonWhitespaceToken != null) {
34073386
switch (lastNonWhitespaceToken.token().id()) {
3408-
case LPAREN:
3387+
case COMMA, LPAREN:
34093388
addMemberModifiers(env, Collections.<Modifier>emptySet(), true);
34103389
addClassTypes(env, null);
34113390
break;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecated
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
StrictMath
2+
String
3+
StringBuffer
4+
StringBuilder
5+
StringIndexOutOfBoundsException
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
StrictMath
2+
String
3+
StringBuffer
4+
StringBuilder
5+
StringIndexOutOfBoundsException
6+
StringTemplate
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
StrictMath
2+
String
3+
StringBuffer
4+
StringBuilder
5+
StringIndexOutOfBoundsException

java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask116FeaturesTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,26 @@ public void testVariableNameSuggestion() throws Exception {
8181
performTest("Records", 1071, null, "recordVariableSuggestion.pass", SOURCE_LEVEL);
8282
}
8383

84+
public void testRecordFirstComponentType() throws Exception {
85+
performTest("Records", 1036, "Str", "typesStartingStr.pass", SOURCE_LEVEL);
86+
}
87+
88+
public void testRecordSecondComponentType() throws Exception {
89+
performTest("Records", 1036, "Exception a, Str", "typesStartingStr.pass", SOURCE_LEVEL);
90+
}
91+
92+
public void testRecordThirdComponentType() throws Exception {
93+
performTest("Records", 1036, "Exception a, Exception b, Str", "typesStartingStr.pass", SOURCE_LEVEL);
94+
}
95+
96+
public void testRecordThirdComponentAnnotation() throws Exception {
97+
performTest("Records", 1036, "Exception a, Exception b, @Dep", "deprecated.pass", SOURCE_LEVEL);
98+
}
99+
100+
public void testRecordThirdComponentAnnotationThenType() throws Exception {
101+
performTest("Records", 1036, "Exception a, Exception b, @Deprecated Str", "typesStartingStr.pass", SOURCE_LEVEL);
102+
}
103+
84104
static {
85105
JavacParser.DISABLE_SOURCE_LEVEL_DOWNGRADE = true;
86106
}

0 commit comments

Comments
 (0)