Skip to content

Commit

Permalink
Fix for #866: don't add parser-recovered field declarations to JDT model
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Apr 9, 2019
1 parent 01e00de commit 33ead70
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -1260,7 +1260,6 @@ public void testParsingRecovery_GRE494_1() {

checkGCUDeclaration("X.groovy",
"public class X {\n" +
" private java.lang.Object asdf;\n" +
" public X() {\n" +
" }\n" +
" public java.lang.Object getNumber() {\n" +
Expand Down Expand Up @@ -1291,7 +1290,6 @@ public void testParsingRecovery_GRE494_2() {
checkGCUDeclaration("X.groovy",
"public class X {\n" +
" private int intField;\n" +
" private java.lang.Object belo;\n" +
" public X() {\n" +
" }\n" +
"}\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ classField! {Token first = LT(1);}
if (LA(1) == IDENT) {
reportError(e);
// create a variable definition for "thing" in hopes that subsequent class members can still be parsed
#classField = #(create(VARIABLE_DEF,"VARIABLE_DEF",first,LT(1)),null,#create(TYPE,"java.lang.Object",LT(1),LT(2)),#create(IDENT,first.getText(),LT(1),LT(2)));
#classField = #(create(VARIABLE_DEF,"VARIABLE_DEF",first,LT(1)),null,#(create(TYPE,"TYPE",first,LT(1)),#create(IDENT,"void",first,LT(1))),#create(IDENT,first.getText(),LT(1),LT(2)));
consumeUntil(NLS);
} else {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6406,7 +6406,7 @@ else if ((LA(1)==LCURLY)) {
if (LA(1) == IDENT) {
reportError(e);
// create a variable definition for "thing" in hopes that subsequent class members can still be parsed
classField_AST = (AST)astFactory.make( (new ASTArray(4)).add(create(VARIABLE_DEF,"VARIABLE_DEF",first,LT(1))).add(null).add(create(TYPE,"java.lang.Object",LT(1),LT(2))).add(create(IDENT,first.getText(),LT(1),LT(2))));
classField_AST = (AST)astFactory.make( (new ASTArray(4)).add(create(VARIABLE_DEF,"VARIABLE_DEF",first,LT(1))).add(null).add((AST)astFactory.make( (new ASTArray(2)).add(create(TYPE,"TYPE",first,LT(1))).add(create(IDENT,"void",first,LT(1))))).add(create(IDENT,first.getText(),LT(1),LT(2))));
consumeUntil(NLS);
} else {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ classField! {Token first = LT(1);}
if (LA(1) == IDENT) {
reportError(e);
// create a variable definition for "thing" in hopes that subsequent class members can still be parsed
#classField = #(create(VARIABLE_DEF,"VARIABLE_DEF",first,LT(1)),null,#create(TYPE,"java.lang.Object",LT(1),LT(2)),#create(IDENT,first.getText(),LT(1),LT(2)));
#classField = #(create(VARIABLE_DEF,"VARIABLE_DEF",first,LT(1)),null,#(create(TYPE,"TYPE",first,LT(1)),#create(IDENT,"void",first,LT(1))),#create(IDENT,first.getText(),LT(1),LT(2)));
consumeUntil(NLS);
} else {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6406,7 +6406,7 @@ else if ((LA(1)==LCURLY)) {
if (LA(1) == IDENT) {
reportError(e);
// create a variable definition for "thing" in hopes that subsequent class members can still be parsed
classField_AST = (AST)astFactory.make( (new ASTArray(4)).add(create(VARIABLE_DEF,"VARIABLE_DEF",first,LT(1))).add(null).add(create(TYPE,"java.lang.Object",LT(1),LT(2))).add(create(IDENT,first.getText(),LT(1),LT(2))));
classField_AST = (AST)astFactory.make( (new ASTArray(4)).add(create(VARIABLE_DEF,"VARIABLE_DEF",first,LT(1))).add(null).add((AST)astFactory.make( (new ASTArray(2)).add(create(TYPE,"TYPE",first,LT(1))).add(create(IDENT,"void",first,LT(1))))).add(create(IDENT,first.getText(),LT(1),LT(2))));
consumeUntil(NLS);
} else {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ classField! {Token first = LT(1);}
if (LA(1) == IDENT) {
reportError(e);
// create a variable definition for "thing" in hopes that subsequent class members can still be parsed
#classField = #(create(VARIABLE_DEF,"VARIABLE_DEF",first,LT(1)),null,#create(TYPE,"java.lang.Object",LT(1),LT(2)),#create(IDENT,first.getText(),LT(1),LT(2)));
#classField = #(create(VARIABLE_DEF,"VARIABLE_DEF",first,LT(1)),null,#(create(TYPE,"TYPE",first,LT(1)),#create(IDENT,"void",first,LT(1))),#create(IDENT,first.getText(),LT(1),LT(2)));
consumeUntil(NLS);
} else {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6406,7 +6406,7 @@ else if ((LA(1)==LCURLY)) {
if (LA(1) == IDENT) {
reportError(e);
// create a variable definition for "thing" in hopes that subsequent class members can still be parsed
classField_AST = (AST)astFactory.make( (new ASTArray(4)).add(create(VARIABLE_DEF,"VARIABLE_DEF",first,LT(1))).add(null).add(create(TYPE,"java.lang.Object",LT(1),LT(2))).add(create(IDENT,first.getText(),LT(1),LT(2))));
classField_AST = (AST)astFactory.make( (new ASTArray(4)).add(create(VARIABLE_DEF,"VARIABLE_DEF",first,LT(1))).add(null).add((AST)astFactory.make( (new ASTArray(2)).add(create(TYPE,"TYPE",first,LT(1))).add(create(IDENT,"void",first,LT(1))))).add(create(IDENT,first.getText(),LT(1),LT(2))));
consumeUntil(NLS);
} else {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -1247,6 +1247,9 @@ private FieldDeclaration[] createFieldDeclarations(ClassNode classNode, boolean
if (isEnum && (fieldNode.getName().equals("MAX_VALUE") || fieldNode.getName().equals("MIN_VALUE"))) {
continue;
}
if (fieldNode.getStart() == fieldNode.getNameStart() && ClassHelper.VOID_TYPE.equals(fieldNode.getType())) {
continue;
}
boolean isEnumField = fieldNode.isEnum();
boolean isSynthetic = GroovyUtils.isSynthetic(fieldNode);
if (!isSynthetic) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,25 @@ final class TypeCompletionTests extends CompletionTestSuite {
|'''.stripMargin())
}

@Test // https://github.com/groovy/groovy-eclipse/issues/866
void testField9a() {
String contents = '''\
class Foo {
String bar
List
}
'''.stripIndent()
ICompletionProposal[] proposals = createProposalsAtOffset(contents, getIndexOf(contents, 'List'))
applyProposalAndCheck(findFirstProposal(proposals, 'List - java.awt'), '''\
|import java.awt.List
|
|class Foo {
| String bar
| List
|}
|'''.stripMargin())
}

@Test
void testField10() {
String contents = '''\
Expand Down

0 comments on commit 33ead70

Please sign in to comment.