Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 108177 Details for
Bug 209639
codeSelect does not resolve correct key for implicit method type arguments
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix
bug209639_003.txt (text/plain), 14.96 KB, created by
David Audel
on 2008-07-23 05:45:07 EDT
(
hide
)
Description:
Proposed fix
Filename:
MIME Type:
Creator:
David Audel
Created:
2008-07-23 05:45:07 EDT
Size:
14.96 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/parser/GenericsSelectionTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/GenericsSelectionTest.java,v >retrieving revision 1.7 >diff -u -r1.7 GenericsSelectionTest.java >--- src/org/eclipse/jdt/core/tests/compiler/parser/GenericsSelectionTest.java 27 Jun 2008 16:04:46 -0000 1.7 >+++ src/org/eclipse/jdt/core/tests/compiler/parser/GenericsSelectionTest.java 23 Jul 2008 09:43:37 -0000 >@@ -893,4 +893,45 @@ > expectedReplacedSource, > testName); > } >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209639 >+public void test0023() { >+ >+ String str = >+ "package test;\n" + >+ "public class Test {\n" + >+ " public List<String> foo() {\n" + >+ " return Collections.emptyList();\n" + >+ " }\n" + >+ "}"; >+ >+ String selection = "emptyList"; >+ >+ String expectedCompletionNodeToString = "<SelectOnMessageSend:Collections.emptyList()>"; >+ >+ String completionIdentifier = "emptyList"; >+ String expectedUnitDisplayString = >+ "package test;\n" + >+ "public class Test {\n" + >+ " public Test() {\n" + >+ " }\n" + >+ " public List<String> foo() {\n" + >+ " return <SelectOnMessageSend:Collections.emptyList()>;\n" + >+ " }\n" + >+ "}\n"; >+ String expectedReplacedSource = "Collections.emptyList()"; >+ String testName = "<select method>"; >+ >+ int selectionStart = str.lastIndexOf(selection); >+ int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; >+ >+ this.checkMethodParse( >+ str.toCharArray(), >+ selectionStart, >+ selectionEnd, >+ expectedCompletionNodeToString, >+ expectedUnitDisplayString, >+ completionIdentifier, >+ expectedReplacedSource, >+ testName); >+} > } >Index: src/org/eclipse/jdt/core/tests/compiler/parser/SelectionTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionTest.java,v >retrieving revision 1.21 >diff -u -r1.21 SelectionTest.java >--- src/org/eclipse/jdt/core/tests/compiler/parser/SelectionTest.java 27 Jun 2008 16:04:46 -0000 1.21 >+++ src/org/eclipse/jdt/core/tests/compiler/parser/SelectionTest.java 23 Jul 2008 09:43:37 -0000 >@@ -794,7 +794,7 @@ > " public X() {\n" + > " }\n" + > " Object foo() {\n" + >- " <SelectOnName:Object>;\n" + >+ " return <SelectOnName:Object>;\n" + > " }\n" + > "}\n"; > >@@ -1064,7 +1064,7 @@ > " public G() {\n" + > " }\n" + > " Object foo() {\n" + >- " <SelectOnSuper:super>;\n" + >+ " return <SelectOnSuper:super>;\n" + > " }\n" + > "}\n"; > >@@ -1113,7 +1113,7 @@ > " Object foo() {\n" + > " new X() {\n" + > " Object bar() {\n" + >- " <SelectOnQualifiedSuper:G.super>;\n" + >+ " return <SelectOnQualifiedSuper:G.super>;\n" + > " }\n" + > " };\n" + > " }\n" + >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/ResolveTests_1_5.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests_1_5.java,v >retrieving revision 1.63 >diff -u -r1.63 ResolveTests_1_5.java >--- src/org/eclipse/jdt/core/tests/model/ResolveTests_1_5.java 23 Jul 2008 07:24:59 -0000 1.63 >+++ src/org/eclipse/jdt/core/tests/model/ResolveTests_1_5.java 23 Jul 2008 09:43:40 -0000 >@@ -2775,4 +2775,138 @@ > assertTrue("Unexpected elements", false); > } > } >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209639 >+public void test0119() throws Exception { >+ this.workingCopies = new ICompilationUnit[3]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Resolve/src/test/Test.java", >+ "package test;\n" + >+ "public class Test {\n" + >+ " public List<String> foo() {\n" + >+ " return Collections.emptyList();\n" + >+ " }\n" + >+ "}"); >+ >+ this.workingCopies[1] = getWorkingCopy( >+ "/Resolve/src/test/Collections.java", >+ "package test;\n" + >+ "public class Collections {\n" + >+ " public static final <T> List<T> emptyList() {return null;}\n" + >+ "}"); >+ >+ this.workingCopies[1] = getWorkingCopy( >+ "/Resolve/src/test/List.java", >+ "package test;\n" + >+ "public class List<E> {\n" + >+ "}"); >+ >+ String str = this.workingCopies[0].getSource(); >+ int start = str.lastIndexOf("emptyList"); >+ int length = "emptyList".length(); >+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length, this.wcOwner); >+ >+ assertElementsEqual( >+ "Unexpected elements", >+ "emptyList() {key=Ltest/Collections;.emptyList<T:Ljava/lang/Object;>()Ltest/List<TT;>;%<Ljava/lang/String;>} [in Collections [in [Working copy] Collections.java [in test [in src [in Resolve]]]]]", >+ elements, >+ true >+ ); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209639 >+public void test0120() throws Exception { >+ this.workingCopies = new ICompilationUnit[3]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Resolve/src/test/Test.java", >+ "package test;\n" + >+ "public class Test {\n" + >+ " public void foo() {\n" + >+ " List<String> local = Collections.emptyList();\n" + >+ " }\n" + >+ "}"); >+ >+ this.workingCopies[1] = getWorkingCopy( >+ "/Resolve/src/test/Collections.java", >+ "package test;\n" + >+ "public class Collections {\n" + >+ " public static final <T> List<T> emptyList() {return null;}\n" + >+ "}"); >+ >+ this.workingCopies[1] = getWorkingCopy( >+ "/Resolve/src/test/List.java", >+ "package test;\n" + >+ "public class List<E> {\n" + >+ "}"); >+ >+ String str = this.workingCopies[0].getSource(); >+ int start = str.lastIndexOf("emptyList"); >+ int length = "emptyList".length(); >+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length, this.wcOwner); >+ >+ assertElementsEqual( >+ "Unexpected elements", >+ "emptyList() {key=Ltest/Collections;.emptyList<T:Ljava/lang/Object;>()Ltest/List<TT;>;%<Ljava/lang/String;>} [in Collections [in [Working copy] Collections.java [in test [in src [in Resolve]]]]]", >+ elements, >+ true >+ ); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209639 >+public void test0121() throws Exception { >+ this.workingCopies = new ICompilationUnit[3]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Resolve/src/test/Test.java", >+ "package test;\n" + >+ "public class Test {\n" + >+ " List<String> field = Collections.emptyList();\n" + >+ " public void foo() {\n" + >+ " }\n" + >+ "}"); >+ >+ this.workingCopies[1] = getWorkingCopy( >+ "/Resolve/src/test/Collections.java", >+ "package test;\n" + >+ "public class Collections {\n" + >+ " public static final <T> List<T> emptyList() {return null;}\n" + >+ "}"); >+ >+ this.workingCopies[1] = getWorkingCopy( >+ "/Resolve/src/test/List.java", >+ "package test;\n" + >+ "public class List<E> {\n" + >+ "}"); >+ >+ String str = this.workingCopies[0].getSource(); >+ int start = str.lastIndexOf("emptyList"); >+ int length = "emptyList".length(); >+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length, this.wcOwner); >+ >+ assertElementsEqual( >+ "Unexpected elements", >+ "emptyList() {key=Ltest/Collections;.emptyList<T:Ljava/lang/Object;>()Ltest/List<TT;>;%<Ljava/lang/String;>} [in Collections [in [Working copy] Collections.java [in test [in src [in Resolve]]]]]", >+ elements, >+ true >+ ); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209639 >+public void test0122() throws Exception { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Resolve/src/test/Test.java", >+ "package test;\n" + >+ "public class Test {\n" + >+ " static <T> T foo() { return null; }\n" + >+ " String[] strings = { foo() };\n" + >+ "}"); >+ >+ String str = this.workingCopies[0].getSource(); >+ int start = str.lastIndexOf("foo"); >+ int length = "foo".length(); >+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length, this.wcOwner); >+ >+ assertElementsEqual( >+ "Unexpected elements", >+ "foo() {key=Ltest/Test;.foo<T:Ljava/lang/Object;>()TT;%<Ljava/lang/String;>} [in Test [in [Working copy] Test.java [in test [in src [in Resolve]]]]]", >+ elements, >+ true >+ ); >+} > } >#P org.eclipse.jdt.core >Index: codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java,v >retrieving revision 1.85 >diff -u -r1.85 SelectionParser.java >--- codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java 27 Jun 2008 16:04:03 -0000 1.85 >+++ codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java 23 Jul 2008 09:43:47 -0000 >@@ -40,6 +40,8 @@ > > // KIND : all values known by SelectionParser are between 1025 and 1549 > protected static final int K_BETWEEN_CASE_AND_COLON = SELECTION_PARSER + 1; // whether we are inside a block >+ protected static final int K_INSIDE_RETURN_STATEMENT = SELECTION_PARSER + 2; // whether we are between the keyword 'return' and the end of a return statement >+ > > public ASTNode assistNodeParent; // the parent node of assist node > >@@ -90,8 +92,8 @@ > > int kind = topKnownElementKind(SELECTION_OR_ASSIST_PARSER); > if(kind != 0) { >-// int info = topKnownElementInfo(SELECTION_OR_ASSIST_PARSER); >- switch (kind) { >+ int info = topKnownElementInfo(SELECTION_OR_ASSIST_PARSER); >+ nextElement : switch (kind) { > case K_BETWEEN_CASE_AND_COLON : > if(this.expressionPtr > 0) { > SwitchStatement switchStatement = new SwitchStatement(); >@@ -119,7 +121,14 @@ > parentNode = switchStatement; > this.assistNodeParent = parentNode; > } >- break; >+ break nextElement; >+ case K_INSIDE_RETURN_STATEMENT : >+ if(info == this.bracketDepth) { >+ ReturnStatement returnStatement = new ReturnStatement(expression, expression.sourceStart, expression.sourceEnd); >+ parentNode = returnStatement; >+ this.assistNodeParent = parentNode; >+ } >+ break nextElement; > } > } > if(parentNode != null) { >@@ -918,6 +927,18 @@ > popElement(K_BETWEEN_CASE_AND_COLON); > } > break; >+ case TokenNamereturn: >+ pushOnElementStack(K_INSIDE_RETURN_STATEMENT, this.bracketDepth); >+ break; >+ case TokenNameSEMICOLON: >+ switch(topKnownElementKind(SELECTION_OR_ASSIST_PARSER)) { >+ case K_INSIDE_RETURN_STATEMENT : >+ if(topKnownElementInfo(SELECTION_OR_ASSIST_PARSER) == this.bracketDepth) { >+ popElement(K_INSIDE_RETURN_STATEMENT); >+ } >+ break; >+ } >+ break; > } > } > } >Index: codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java,v >retrieving revision 1.197 >diff -u -r1.197 CompletionParser.java >--- codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 23 Jul 2008 07:25:06 -0000 1.197 >+++ codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 23 Jul 2008 09:43:45 -0000 >@@ -135,9 +135,6 @@ > // used to find if there is unused modifiers when building completion inside a method or an initializer > boolean hasUnusedModifiers; > >- // depth of '(', '{' and '[]' >- int bracketDepth; >- > // show if the current token can be an explicit constructor > int canBeExplicitConstructor = NO; > static final int NO = 0; >@@ -3262,7 +3259,6 @@ > pushOnElementStack(K_BETWEEN_CATCH_AND_RIGHT_PAREN); > break; > case TokenNameLPAREN: >- this.bracketDepth++; > if (this.invocationType == NO_RECEIVER || this.invocationType == NAME_RECEIVER || this.invocationType == SUPER_RECEIVER) { > this.qualifier = this.expressionPtr; // remenber the last expression so that arguments are correctly computed > } >@@ -3323,7 +3319,6 @@ > } > break; > case TokenNameLBRACE: >- this.bracketDepth++; > int kind = topKnownElementKind(COMPLETION_OR_ASSIST_PARSER); > if(kind == K_FIELD_INITIALIZER_DELIMITER > || kind == K_LOCAL_INITIALIZER_DELIMITER >@@ -3380,16 +3375,8 @@ > this.qualifier = -1; > } > } >- this.bracketDepth++; >- break; >- case TokenNameRBRACE: >- this.bracketDepth--; >- break; >- case TokenNameRBRACKET: >- this.bracketDepth--; > break; > case TokenNameRPAREN: >- this.bracketDepth--; > switch(topKnownElementKind(COMPLETION_OR_ASSIST_PARSER)) { > case K_BETWEEN_CATCH_AND_RIGHT_PAREN : > popElement(K_BETWEEN_CATCH_AND_RIGHT_PAREN); >@@ -4209,7 +4196,6 @@ > private void initializeForBlockStatements() { > this.previousToken = -1; > this.previousIdentifierPtr = -1; >- this.bracketDepth = 0; > this.invocationType = NO_RECEIVER; > this.qualifier = -1; > popUntilElement(K_SWITCH_LABEL); >Index: codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java,v >retrieving revision 1.86 >diff -u -r1.86 AssistParser.java >--- codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java 23 Jul 2008 07:25:06 -0000 1.86 >+++ codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java 23 Jul 2008 09:43:47 -0000 >@@ -42,6 +42,9 @@ > > // the index in the identifier stack of the previous identifier > protected int previousIdentifierPtr; >+ >+ // depth of '(', '{' and '[]' >+ protected int bracketDepth; > > // element stack > protected static final int ElementStackIncrement = 100; >@@ -740,6 +743,7 @@ > if (isInsideMethod() || isInsideFieldInitialization() || isInsideAttributeValue()) { > switch (token) { > case TokenNameLPAREN : >+ this.bracketDepth++; > switch (this.previousToken) { > case TokenNameIdentifier: > this.pushOnElementStack(K_SELECTOR, this.identifierPtr); >@@ -759,6 +763,21 @@ > break; > } > break; >+ case TokenNameLBRACE: >+ this.bracketDepth++; >+ break; >+ case TokenNameLBRACKET: >+ this.bracketDepth++; >+ break; >+ case TokenNameRBRACE: >+ this.bracketDepth--; >+ break; >+ case TokenNameRBRACKET: >+ this.bracketDepth--; >+ break; >+ case TokenNameRPAREN: >+ this.bracketDepth--; >+ break; > } > } else { > switch (token) { >@@ -1119,12 +1138,14 @@ > flushAssistState(); > flushElementStack(); > this.previousIdentifierPtr = -1; >+ this.bracketDepth = 0; > } > public void initialize(boolean initializeNLS) { > super.initialize(initializeNLS); > flushAssistState(); > flushElementStack(); > this.previousIdentifierPtr = -1; >+ this.bracketDepth = 0; > } > public abstract void initializeScanner(); > protected boolean isIndirectlyInsideFieldInitialization(){
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 209639
: 108177