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 124690 Details for
Bug 262932
[assist] Constructor completion makes array allocation difficult
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix
bug262932_002.txt (text/plain), 16.70 KB, created by
David Audel
on 2009-02-04 11:14:18 EST
(
hide
)
Description:
Proposed fix
Filename:
MIME Type:
Creator:
David Audel
Created:
2009-02-04 11:14:18 EST
Size:
16.70 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java,v >retrieving revision 1.386 >diff -u -r1.386 CompletionEngine.java >--- codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 22 Jan 2009 09:46:59 -0000 1.386 >+++ codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 4 Feb 2009 16:06:59 -0000 >@@ -487,6 +487,8 @@ > TypeBinding[] expectedTypes = new TypeBinding[1]; > int expectedTypesFilter; > boolean hasJavaLangObjectAsExpectedType = false; >+ boolean hasExpectedArrayTypes = false; >+ boolean hasComputedExpectedArrayTypes = false; > int uninterestingBindingsPtr = -1; > Binding[] uninterestingBindings = new Binding[1]; > int forbbidenBindingsPtr = -1; >@@ -759,7 +761,7 @@ > final int extraFlags = acceptedConstructor.extraFlags; > final int accessibility = acceptedConstructor.accessibility; > >- boolean proposeType = (extraFlags & ExtraFlags.HasNonPrivateStaticMemberTypes) != 0; >+ boolean proposeType = hasArrayTypeAsExpectedSuperTypes() || (extraFlags & ExtraFlags.HasNonPrivateStaticMemberTypes) != 0; > > char[] fullyQualifiedName = CharOperation.concat(packageName, simpleTypeName, '.'); > >@@ -9249,7 +9251,8 @@ > if (!this.assistNodeIsConstructor || > !allowingLongComputationProposals || > hasStaticMemberTypes(memberType, invocationType, this.unitScope) || >- (memberType instanceof SourceTypeBinding && hasMemberTypesInEnclosingScope((SourceTypeBinding)memberType, scope))) { >+ (memberType instanceof SourceTypeBinding && hasMemberTypesInEnclosingScope((SourceTypeBinding)memberType, scope)) || >+ hasArrayTypeAsExpectedSuperTypes()) { > createTypeProposal( > memberType, > memberType.qualifiedSourceName(), >@@ -9689,7 +9692,7 @@ > relevance += computeRelevanceForAnnotationTarget(localType); > > boolean allowingLongComputationProposals = isAllowingLongComputationProposals(); >- if (!this.assistNodeIsConstructor || !allowingLongComputationProposals) { >+ if (!this.assistNodeIsConstructor || !allowingLongComputationProposals || hasArrayTypeAsExpectedSuperTypes()) { > this.noProposal = false; > if(!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) { > createTypeProposal( >@@ -10085,7 +10088,8 @@ > (!this.assistNodeIsConstructor || > !allowingLongComputationProposals || > hasStaticMemberTypes(sourceType, null, this.unitScope) || >- hasMemberTypesInEnclosingScope(sourceType, scope))) { >+ hasMemberTypesInEnclosingScope(sourceType, scope)) || >+ hasArrayTypeAsExpectedSuperTypes()) { > char[] typeName = sourceType.sourceName(); > createTypeProposal( > sourceType, >@@ -10313,7 +10317,8 @@ > (!this.assistNodeIsConstructor || > !allowingLongComputationProposals || > hasStaticMemberTypes(sourceType, null, this.unitScope) || >- hasMemberTypesInEnclosingScope(sourceType, scope))) { >+ hasMemberTypesInEnclosingScope(sourceType, scope)) || >+ hasArrayTypeAsExpectedSuperTypes()) { > char[] typeName = sourceType.sourceName(); > createTypeProposal( > sourceType, >@@ -10433,7 +10438,7 @@ > > for (int j = 0; j < typesFound.size(); j++) { > ReferenceBinding typeFound = (ReferenceBinding)typesFound.elementAt(j); >- if (typeFound == refBinding) { >+ if (typeFound == refBinding.erasure()) { > continue next; > } > } >@@ -10484,7 +10489,11 @@ > relevance += computeRelevanceForInterface(); > } > >- if (proposeType && (!this.assistNodeIsConstructor || !allowingLongComputationProposals || hasStaticMemberTypes(refBinding, scope.enclosingSourceType() ,this.unitScope))) { >+ if (proposeType && >+ (!this.assistNodeIsConstructor || >+ !allowingLongComputationProposals || >+ hasStaticMemberTypes(refBinding, scope.enclosingSourceType() ,this.unitScope)) || >+ hasArrayTypeAsExpectedSuperTypes()) { > this.noProposal = false; > if(!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) { > InternalCompletionProposal proposal = createProposal(CompletionProposal.TYPE_REF, this.actualCompletionPosition); >@@ -10610,7 +10619,8 @@ > relevance += computeRelevanceForException(typeBinding.sourceName); > } > >- if (proposeType && hasStaticMemberTypes(typeBinding, scope.enclosingSourceType(), this.unitScope)) { >+ if (proposeType && >+ (hasStaticMemberTypes(typeBinding, scope.enclosingSourceType(), this.unitScope) || hasArrayTypeAsExpectedSuperTypes())) { > this.noProposal = false; > if(!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) { > InternalCompletionProposal proposal = createProposal(CompletionProposal.TYPE_REF, this.actualCompletionPosition); >@@ -11508,6 +11518,24 @@ > > return this.parser; > } >+ protected boolean hasArrayTypeAsExpectedSuperTypes() { >+ if ((this.expectedTypesFilter & ~SUBTYPE) != 0) return false; >+ >+ if (!this.hasComputedExpectedArrayTypes) { >+ if(this.expectedTypes != null) { >+ done : for (int i = 0; i <= this.expectedTypesPtr; i++) { >+ if(this.expectedTypes[i].isArrayType()) { >+ this.hasExpectedArrayTypes = true; >+ break done; >+ } >+ } >+ } >+ >+ this.hasComputedExpectedArrayTypes = true; >+ } >+ >+ return this.hasExpectedArrayTypes; >+ } > protected boolean hasPossibleAnnotationTarget(TypeBinding typeBinding, Scope scope) { > if (this.targetedElement == TagBits.AnnotationForPackage) { > long target = typeBinding.getAnnotationTagBits() & TagBits.AnnotationTargetMASK; >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/CompletionTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java,v >retrieving revision 1.193 >diff -u -r1.193 CompletionTests.java >--- src/org/eclipse/jdt/core/tests/model/CompletionTests.java 30 Jan 2009 15:47:19 -0000 1.193 >+++ src/org/eclipse/jdt/core/tests/model/CompletionTests.java 4 Feb 2009 16:07:09 -0000 >@@ -15484,6 +15484,197 @@ > } > } > } >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262932 >+public void testConstructor1() throws JavaModelException { >+ this.workingCopies = new ICompilationUnit[2]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/Test.java", >+ "package test;"+ >+ "public class Test {\n" + >+ " public void foo() {\n" + >+ " TestConstructor1[] var = new TestConstructor\n" + >+ " }\n" + >+ "}"); >+ this.workingCopies[1] = getWorkingCopy( >+ "/Completion/src/test/TestConstructor1.java", >+ "package test;"+ >+ "public class TestConstructor1 {\n" + >+ " public TestConstructor1(int i) {\n" + >+ " }\n" + >+ "}"); >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true); >+ requestor.allowAllRequiredProposals(); >+ NullProgressMonitor monitor = new NullProgressMonitor(); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "TestConstructor"; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor); >+ >+ assertResults( >+ "TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" + >+ "TestConstructor1[CONSTRUCTOR_INVOCATION]{(), Ltest.TestConstructor1;, (I)V, TestConstructor1, (i), "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" + >+ " TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}", >+ requestor.getResults()); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262932 >+public void testConstructor2() throws JavaModelException { >+ this.workingCopies = new ICompilationUnit[2]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/Test.java", >+ "package test;"+ >+ "public class Test {\n" + >+ " public void foo(TestConstructor1[] var) {\n" + >+ " foo(new TestConstructor\n" + >+ " }\n" + >+ "}"); >+ this.workingCopies[1] = getWorkingCopy( >+ "/Completion/src/test/TestConstructor1.java", >+ "package test;"+ >+ "public class TestConstructor1 {\n" + >+ " public TestConstructor1(int i) {\n" + >+ " }\n" + >+ "}"); >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true); >+ requestor.allowAllRequiredProposals(); >+ NullProgressMonitor monitor = new NullProgressMonitor(); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "TestConstructor"; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor); >+ >+ assertResults( >+ "TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" + >+ "TestConstructor1[CONSTRUCTOR_INVOCATION]{(), Ltest.TestConstructor1;, (I)V, TestConstructor1, (i), "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" + >+ " TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}", >+ requestor.getResults()); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262932 >+public void testConstructor3() throws JavaModelException { >+ this.workingCopies = new ICompilationUnit[2]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/Test.java", >+ "package test;"+ >+ "public class Test {\n" + >+ " public TestConstructor1[] foo() {\n" + >+ " return new TestConstructor\n" + >+ " }\n" + >+ "}"); >+ this.workingCopies[1] = getWorkingCopy( >+ "/Completion/src/test/TestConstructor1.java", >+ "package test;"+ >+ "public class TestConstructor1 {\n" + >+ " public TestConstructor1(int i) {\n" + >+ " }\n" + >+ "}"); >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true); >+ requestor.allowAllRequiredProposals(); >+ NullProgressMonitor monitor = new NullProgressMonitor(); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "TestConstructor"; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor); >+ >+ assertResults( >+ "TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" + >+ "TestConstructor1[CONSTRUCTOR_INVOCATION]{(), Ltest.TestConstructor1;, (I)V, TestConstructor1, (i), "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" + >+ " TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}", >+ requestor.getResults()); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262932 >+public void testConstructor4() throws JavaModelException { >+ this.workingCopies = new ICompilationUnit[2]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/Test.java", >+ "package test;"+ >+ "public class Test {\n" + >+ " public Test(TestConstructor1[] var) {}\n" + >+ " public void foo() {\n" + >+ " new Test(new TestConstructor\n" + >+ " }\n" + >+ "}"); >+ this.workingCopies[1] = getWorkingCopy( >+ "/Completion/src/test/TestConstructor1.java", >+ "package test;"+ >+ "public class TestConstructor1 {\n" + >+ " public TestConstructor1(int i) {\n" + >+ " }\n" + >+ "}"); >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true); >+ requestor.allowAllRequiredProposals(); >+ NullProgressMonitor monitor = new NullProgressMonitor(); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "TestConstructor"; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor); >+ >+ assertResults( >+ "TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" + >+ "TestConstructor1[CONSTRUCTOR_INVOCATION]{(), Ltest.TestConstructor1;, (I)V, TestConstructor1, (i), "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" + >+ " TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}", >+ requestor.getResults()); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262932 >+public void testConstructor5() throws JavaModelException { >+ this.workingCopies = new ICompilationUnit[2]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/Test.java", >+ "package test;"+ >+ "public class Test {\n" + >+ " public void foo(TestConstructor1[] var) {\n" + >+ " if (var == new TestConstructor) {}\n" + >+ " }\n" + >+ "}"); >+ this.workingCopies[1] = getWorkingCopy( >+ "/Completion/src/test/TestConstructor1.java", >+ "package test;"+ >+ "public class TestConstructor1 {\n" + >+ " public TestConstructor1(int i) {\n" + >+ " }\n" + >+ "}"); >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true); >+ requestor.allowAllRequiredProposals(); >+ NullProgressMonitor monitor = new NullProgressMonitor(); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "TestConstructor"; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor); >+ >+ assertResults( >+ "TestConstructor1[CONSTRUCTOR_INVOCATION]{(), Ltest.TestConstructor1;, (I)V, TestConstructor1, (i), "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" + >+ " TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}", >+ requestor.getResults()); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262932 >+public void testConstructor6() throws JavaModelException { >+ this.workingCopies = new ICompilationUnit[2]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/Test.java", >+ "package test;"+ >+ "public class Test {\n" + >+ " public void foo(Object o) {\n" + >+ " o = (TestConstructor1[])new TestConstructor\n" + >+ " }\n" + >+ "}"); >+ this.workingCopies[1] = getWorkingCopy( >+ "/Completion/src/test/TestConstructor1.java", >+ "package test;"+ >+ "public class TestConstructor1 {\n" + >+ " public TestConstructor1(int i) {\n" + >+ " }\n" + >+ "}"); >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true); >+ requestor.allowAllRequiredProposals(); >+ NullProgressMonitor monitor = new NullProgressMonitor(); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "TestConstructor"; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor); >+ >+ assertResults( >+ "TestConstructor1[CONSTRUCTOR_INVOCATION]{(), Ltest.TestConstructor1;, (I)V, TestConstructor1, (i), "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" + >+ " TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}", >+ requestor.getResults()); >+} > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=127296 > public void testDeprecationCheck1() throws JavaModelException { > Hashtable options = JavaCore.getOptions();
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 262932
: 124690