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 197027 Details for
Bug 346454
[1.7][content assist]Getting NegativeArraySizeException while trying content assist after diamond
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
proposed fix
patch346454.txt (text/plain), 31.09 KB, created by
Ayushman Jain
on 2011-05-31 14:45:43 EDT
(
hide
)
Description:
proposed fix
Filename:
MIME Type:
Creator:
Ayushman Jain
Created:
2011-05-31 14:45:43 EDT
Size:
31.09 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.425.2.8 >diff -u -r1.425.2.8 CompletionEngine.java >--- codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 25 May 2011 06:48:14 -0000 1.425.2.8 >+++ codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 31 May 2011 18:17:45 -0000 >@@ -5003,7 +5003,22 @@ > int relevance) { > > // No visibility checks can be performed without the scope & invocationSite >- MethodBinding[] methods = currentType.availableMethods(); >+ MethodBinding[] methods = null; >+ if (currentType instanceof ParameterizedTypeBinding && invocationSite instanceof CompletionOnQualifiedAllocationExpression) { >+ CompletionOnQualifiedAllocationExpression alloc = (CompletionOnQualifiedAllocationExpression) invocationSite; >+ if ((alloc.bits & ASTNode.IsDiamond) != 0) { >+ // inference failed. So don't substitute type arguments. Just return the unsubstituted methods >+ // and let the user decide what to substitute. >+ ParameterizedTypeBinding binding = (ParameterizedTypeBinding) currentType; >+ ReferenceBinding originalGenericType = binding.genericType(); >+ if (originalGenericType != null) >+ methods = originalGenericType.methods(); >+ } else { >+ methods = currentType.availableMethods(); >+ } >+ } else { >+ methods = currentType.availableMethods(); >+ } > if(methods != null) { > int minArgLength = argTypes == null ? 0 : argTypes.length; > next : for (int f = methods.length; --f >= 0;) { >Index: codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionOnQualifiedAllocationExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionOnQualifiedAllocationExpression.java,v >retrieving revision 1.25 >diff -u -r1.25 CompletionOnQualifiedAllocationExpression.java >--- codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionOnQualifiedAllocationExpression.java 7 Mar 2009 00:59:00 -0000 1.25 >+++ codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionOnQualifiedAllocationExpression.java 31 May 2011 18:17:45 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2009 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -39,24 +39,56 @@ > > public class CompletionOnQualifiedAllocationExpression extends QualifiedAllocationExpression { > public TypeBinding resolveType(BlockScope scope) { >+ TypeBinding[] argumentTypes = Binding.NO_PARAMETERS; > if (this.arguments != null) { > int argsLength = this.arguments.length; >- for (int a = argsLength; --a >= 0;) >- this.arguments[a].resolveType(scope); >+ int length = this.arguments.length; >+ argumentTypes = new TypeBinding[length]; >+ for (int a = argsLength; --a >= 0;) { >+ argumentTypes[a] = this.arguments[a].resolveType(scope); >+ } > } >- >+ final boolean isDiamond = this.type != null && (this.type.bits & ASTNode.IsDiamond) != 0; > if (this.enclosingInstance != null) { > TypeBinding enclosingType = this.enclosingInstance.resolveType(scope); >+ if (enclosingType == null) { >+ // try to propose something even if enclosing type cannot be resolved. >+ // Eg.: new Test<>().new Test<>(#cursor# >+ if (this.enclosingInstance instanceof AllocationExpression) { >+ TypeReference enclosingInstanceType = ((AllocationExpression) this.enclosingInstance).type; >+ if (enclosingInstanceType != null) { >+ enclosingType = enclosingInstanceType.resolvedType; >+ } >+ } >+ } > if (enclosingType == null || !(enclosingType instanceof ReferenceBinding)) { > throw new CompletionNodeFound(); > } > this.resolvedType = ((SingleTypeReference) this.type).resolveTypeEnclosing(scope, (ReferenceBinding) enclosingType); >+ if (isDiamond && (this.resolvedType instanceof ParameterizedTypeBinding)) { >+ TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) this.resolvedType).genericType(), null, argumentTypes, scope); >+ if (inferredTypes != null) { >+ this.resolvedType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) this.resolvedType).genericType(), inferredTypes, ((ParameterizedTypeBinding) this.resolvedType).enclosingType()); >+ } else { >+ // inference failed. Resolved type will be of the form Test<> >+ this.bits |= ASTNode.IsDiamond; >+ } >+ } > if (!(this.resolvedType instanceof ReferenceBinding)) > throw new CompletionNodeFound(); // no need to continue if its an array or base type > if (this.resolvedType.isInterface()) // handle the anonymous class definition case > this.resolvedType = scope.getJavaLangObject(); > } else { >- this.resolvedType = this.type.resolveType(scope, true /* check bounds*/); >+ this.resolvedType = this.type.resolveType(scope, true /* check bounds*/); >+ if (isDiamond && (this.resolvedType instanceof ParameterizedTypeBinding)) { >+ TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) this.resolvedType).genericType(), null, argumentTypes, scope); >+ if (inferredTypes != null) { >+ this.resolvedType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) this.resolvedType).genericType(), inferredTypes, ((ParameterizedTypeBinding) this.resolvedType).enclosingType()); >+ } else { >+ // inference failed. Resolved type will be of the form Test<> >+ this.bits |= ASTNode.IsDiamond; >+ } >+ } > if (!(this.resolvedType instanceof ReferenceBinding)) > throw new CompletionNodeFound(); // no need to continue if its an array or base type > } >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.218.2.10 >diff -u -r1.218.2.10 CompletionParser.java >--- codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 25 May 2011 06:48:15 -0000 1.218.2.10 >+++ codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 31 May 2011 18:17:57 -0000 >@@ -2614,6 +2614,14 @@ > this.listLength++; > } > } >+protected void consumeGenericTypeWithDiamond() { >+ super.consumeGenericTypeWithDiamond(); >+ // we need to pop the <> of the diamond from the stack. >+ // This is not required in usual case when the type argument isn't elided >+ // since the < and > get popped while parsing the type argument. >+ popElement(K_BINARY_OPERATOR); // pop > >+ popElement(K_BINARY_OPERATOR); // pop < >+} > protected void consumeStatementFor() { > super.consumeStatementFor(); > >@@ -4366,7 +4374,10 @@ > > protected TypeReference getTypeReferenceForGenericType(int dim, int identifierLength, int numberOfIdentifiers) { > TypeReference ref = super.getTypeReferenceForGenericType(dim, identifierLength, numberOfIdentifiers); >- >+ // in completion case we might have encountered the assist node before really parsing >+ // the complete class instance creation, and so a separate check for diamond is needed here. >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454 >+ checkForDiamond(ref); > if(this.assistNode != null) { > if (identifierLength == 1 && numberOfIdentifiers == 1) { > ParameterizedSingleTypeReference singleRef = (ParameterizedSingleTypeReference) ref; >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.95.2.4 >diff -u -r1.95.2.4 AssistParser.java >--- codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java 25 May 2011 06:48:13 -0000 1.95.2.4 >+++ codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java 31 May 2011 18:17:58 -0000 >@@ -989,7 +989,7 @@ > int currentIdentifiersLength = identifierLength; > while (index > 0) { > int currentTypeArgumentsLength = this.genericsLengthStack[this.genericsLengthPtr--]; >- if (currentTypeArgumentsLength != 0) { >+ if (currentTypeArgumentsLength > -1) { > this.genericsPtr -= currentTypeArgumentsLength; > System.arraycopy(this.genericsStack, this.genericsPtr + 1, typeArguments[index - 1] = new TypeReference[currentTypeArgumentsLength], 0, currentTypeArgumentsLength); > } >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest.java,v >retrieving revision 1.36.2.5 >diff -u -r1.36.2.5 CompletionParserTest.java >--- src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest.java 25 May 2011 06:48:08 -0000 1.36.2.5 >+++ src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest.java 31 May 2011 18:18:12 -0000 >@@ -8868,4 +8868,80 @@ > expectedReplacedSource, > testName); > } >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454 >+public void testBug346454(){ >+ if (this.complianceLevel < ClassFileConstants.JDK1_7) >+ return; >+ String str = >+ "public class Test<T> {\n" + >+ " public void foo() {\n" + >+ " Test<String> t = new Test<>()\n" + >+ " }" + >+ "}\n"; >+ >+ String testName = "<complete after diamond type>"; >+ String completeBehind = "new Test<>("; >+ String expectedCompletionNodeToString = "<CompleteOnAllocationExpression:new Test<>()>"; >+ String completionIdentifier = ""; >+ String expectedReplacedSource = ""; >+ String expectedUnitDisplayString = >+ "public class Test<T> {\n" + >+ " public Test() {\n" + >+ " }\n" + >+ " public void foo() {\n" + >+ " Test<String> t = <CompleteOnAllocationExpression:new Test<>()>;\n" + >+ " }\n" + >+ "}\n"; >+ >+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; >+ checkMethodParse( >+ str.toCharArray(), >+ cursorLocation, >+ expectedCompletionNodeToString, >+ expectedUnitDisplayString, >+ completionIdentifier, >+ expectedReplacedSource, >+ testName); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454 >+public void testBug346454b(){ >+ if (this.complianceLevel < ClassFileConstants.JDK1_7) >+ return; >+ String str = >+ "public class Test<T> {\n" + >+ " public class T2<Z>{}\n" + >+ " public void foo() {\n" + >+ " Test<String>.T2<String> t = new Test<>().new T2<>()\n" + >+ " }" + >+ "}\n"; >+ >+ String testName = "<complete after diamond type>"; >+ String completeBehind = "new Test<>().new T2<>("; >+ String expectedCompletionNodeToString = "<CompleteOnQualifiedAllocationExpression:new Test<>().new T2<>()>"; >+ String completionIdentifier = ""; >+ String expectedReplacedSource = ""; >+ String expectedUnitDisplayString = >+ "public class Test<T> {\n" + >+ " public class T2<Z> {\n" + >+ " public T2() {\n" + >+ " }\n" + >+ " }\n" + >+ " public Test() {\n" + >+ " }\n" + >+ " public void foo() {\n" + >+ " Test<String>.T2<String> t = <CompleteOnQualifiedAllocationExpression:new Test<>().new T2<>()>;\n" + >+ " }\n" + >+ "}\n"; >+ >+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; >+ checkMethodParse( >+ str.toCharArray(), >+ cursorLocation, >+ expectedCompletionNodeToString, >+ expectedUnitDisplayString, >+ completionIdentifier, >+ expectedReplacedSource, >+ testName); >+} > } >#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.236.2.9 >diff -u -r1.236.2.9 CompletionTests.java >--- src/org/eclipse/jdt/core/tests/model/CompletionTests.java 25 May 2011 06:48:06 -0000 1.236.2.9 >+++ src/org/eclipse/jdt/core/tests/model/CompletionTests.java 31 May 2011 18:19:09 -0000 >@@ -1006,6 +1006,16 @@ > suite.addTest(new CompletionTests("testBug343637f")); > suite.addTest(new CompletionTests("testBug343637g")); > suite.addTest(new CompletionTests("testBug343637h")); >+ suite.addTest(new CompletionTests("testBug346454")); >+ suite.addTest(new CompletionTests("testBug346454b")); >+ suite.addTest(new CompletionTests("testBug346454c")); >+ suite.addTest(new CompletionTests("testBug346454c_2")); >+ suite.addTest(new CompletionTests("testBug346454d")); >+ suite.addTest(new CompletionTests("testBug346454e")); >+ suite.addTest(new CompletionTests("testBug346454f")); >+ suite.addTest(new CompletionTests("testBug346454g")); >+ suite.addTest(new CompletionTests("testBug346454h")); >+ suite.addTest(new CompletionTests("testBug346454i")); > return suite; > } > public CompletionTests(String name) { >@@ -24008,4 +24018,402 @@ > COMPLETION_PROJECT.setOptions(options); > } > } >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454 >+// Should not get NegativeArraySizeException or show proposals for types >+public void testBug346454() throws JavaModelException { >+ Map options = COMPLETION_PROJECT.getOptions(true); >+ Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance); >+ try { >+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7); >+ COMPLETION_PROJECT.setOptions(options); >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/Test.java", >+ "package test;"+ >+ "public class Test<T> {\n" + >+ " public void foo() {\n" + >+ " Test<String> x = new Test<>\n" + >+ " }" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "new Test<>"; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ assertResults( >+ "", >+ requestor.getResults()); >+ } finally { >+ // Restore compliance settings. >+ options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance); >+ COMPLETION_PROJECT.setOptions(options); >+ } >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454 >+// Should not get NegativeArraySizeException >+public void testBug346454b() throws JavaModelException { >+ Map options = COMPLETION_PROJECT.getOptions(true); >+ Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance); >+ try { >+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7); >+ COMPLETION_PROJECT.setOptions(options); >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/Test.java", >+ "package test;"+ >+ "public class Test<T> {\n" + >+ " public void foo() {\n" + >+ " Test<String> x = new Test<>.\n" + >+ " }" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "new Test<>."; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ assertResults( >+ "", >+ requestor.getResults()); >+ } finally { >+ // Restore compliance settings. >+ options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance); >+ COMPLETION_PROJECT.setOptions(options); >+ } >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454 >+// Should get proposals for constructor parameters >+public void testBug346454c() throws JavaModelException { >+ Map options = COMPLETION_PROJECT.getOptions(true); >+ Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance); >+ try { >+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7); >+ COMPLETION_PROJECT.setOptions(options); >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/Test.java", >+ "package test;"+ >+ "public class Test<T> {\n" + >+ " public Test(int i){}\n" + >+ " public void foo() {\n" + >+ " int j = 1;\n" + >+ " new Test<>()\n" + >+ " }" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "new Test<>("; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ assertResults( >+ "Test[METHOD_REF<CONSTRUCTOR>]{, Ltest.Test<>;, (I)V, Test, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" + >+ "Test<>[ANONYMOUS_CLASS_DECLARATION]{, Ltest.Test<>;, (I)V, null, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}", >+ requestor.getResults()); >+ } finally { >+ // Restore compliance settings. >+ options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance); >+ COMPLETION_PROJECT.setOptions(options); >+ } >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454 >+// Inference fails but be resilient. At least propose unsubstituted methods. >+public void testBug346454c_2() throws JavaModelException { >+ Map options = COMPLETION_PROJECT.getOptions(true); >+ Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance); >+ try { >+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7); >+ COMPLETION_PROJECT.setOptions(options); >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/Test.java", >+ "package test;"+ >+ "public class Test<T> {\n" + >+ " public Test(T t){}\n" + >+ " public Test(int i){}\n" + >+ " public void foo() {\n" + >+ " new Test<>()\n" + >+ " }" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "new Test<>("; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ assertResults( >+ "Test[METHOD_REF<CONSTRUCTOR>]{, Ltest.Test<>;, (I)V, Test, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" + >+ "Test[METHOD_REF<CONSTRUCTOR>]{, Ltest.Test<>;, (TT;)V, Test, (t), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" + >+ "Test<>[ANONYMOUS_CLASS_DECLARATION]{, Ltest.Test<>;, (I)V, null, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" + >+ "Test<>[ANONYMOUS_CLASS_DECLARATION]{, Ltest.Test<>;, (TT;)V, null, (t), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}", >+ requestor.getResults()); >+ } finally { >+ // Restore compliance settings. >+ options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance); >+ COMPLETION_PROJECT.setOptions(options); >+ } >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454 >+// Qualified exp case. Should get proposals for constructor parameters. >+// This tests changes in CompleteOnQualifiedAllocationExpression >+public void testBug346454d() throws JavaModelException { >+ Map options = COMPLETION_PROJECT.getOptions(true); >+ Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance); >+ try { >+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7); >+ COMPLETION_PROJECT.setOptions(options); >+ this.workingCopies = new ICompilationUnit[2]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/X.java", >+ "package test;"+ >+ "public class X<T> {\n" + >+ " public void foo() {\n" + >+ " new pack.Test<>()\n" + >+ " }" + >+ "}\n"); >+ >+ this.workingCopies[1] = getWorkingCopy( >+ "/Completion/src/pack/Test.java", >+ "package pack;"+ >+ "public class Test<T> {\n" + >+ " public Test(T t){}\n" + >+ " public Test(int i){}\n" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = " new pack.Test<>("; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ assertResults( >+ "Test[METHOD_REF<CONSTRUCTOR>]{, Lpack.Test<>;, (I)V, Test, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" + >+ "Test[METHOD_REF<CONSTRUCTOR>]{, Lpack.Test<>;, (TT;)V, Test, (t), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" + >+ "Test<>[ANONYMOUS_CLASS_DECLARATION]{, Lpack.Test<>;, (I)V, null, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" + >+ "Test<>[ANONYMOUS_CLASS_DECLARATION]{, Lpack.Test<>;, (TT;)V, null, (t), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}", >+ requestor.getResults()); >+ } finally { >+ // Restore compliance settings. >+ options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance); >+ COMPLETION_PROJECT.setOptions(options); >+ } >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454 >+// Qualified exp case. Should get proposals for constructor completion >+public void testBug346454e() throws JavaModelException { >+ Map options = COMPLETION_PROJECT.getOptions(true); >+ Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance); >+ try { >+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7); >+ COMPLETION_PROJECT.setOptions(options); >+ this.workingCopies = new ICompilationUnit[2]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/X.java", >+ "package test;"+ >+ "public class X<T> {\n" + >+ " public void foo() {\n" + >+ " new pack.Test<>.\n" + >+ " }" + >+ "}\n"); >+ >+ this.workingCopies[1] = getWorkingCopy( >+ "/Completion/src/pack/Test.java", >+ "package pack;"+ >+ "public class Test<T> {\n" + >+ " public Test(T t){}\n" + >+ " public Test(int i){}\n" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "new pack.Test<>."; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ assertResults( >+ "", >+ requestor.getResults()); >+ } finally { >+ // Restore compliance settings. >+ options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance); >+ COMPLETION_PROJECT.setOptions(options); >+ } >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454 >+// Qualified allocation case. Should get proposals for constructor completion >+// This tests changes in CompleteOnQualifiedAllocationExpression >+public void testBug346454f() throws JavaModelException { >+ Map options = COMPLETION_PROJECT.getOptions(true); >+ Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance); >+ try { >+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7); >+ COMPLETION_PROJECT.setOptions(options); >+ this.workingCopies = new ICompilationUnit[2]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/Test.java", >+ "package test;" + >+ "import pack.Test;\n"+ >+ "public class X {\n" + >+ " public void foo() {\n" + >+ " Test<String>.T2<String> t = new Test<>().new T2<>()\n" + >+ " }" + >+ "}\n"); >+ >+ this.workingCopies[1] = getWorkingCopy( >+ "/Completion/src/pack/Test.java", >+ "package pack;"+ >+ "public class Test<T> {\n" + >+ " public class T2<Z> {\n" + >+ " public T2(Z z){}\n" + >+ " }" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "new Test<>().new T2<>("; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ assertResults( >+ "T2[METHOD_REF<CONSTRUCTOR>]{, Lpack.Test<>.T2;, (TZ;)V, T2, (z), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" + >+ "Test<>.T2[ANONYMOUS_CLASS_DECLARATION]{, Lpack.Test<>.T2;, (TZ;)V, null, (z), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}", >+ requestor.getResults()); >+ } finally { >+ // Restore compliance settings. >+ options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance); >+ COMPLETION_PROJECT.setOptions(options); >+ } >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454 >+// Qualified allocation case. Should get proposals for constructor completion >+// This tests changes in CompleteOnQualifiedAllocationExpression >+public void testBug346454g() throws JavaModelException { >+ Map options = COMPLETION_PROJECT.getOptions(true); >+ Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance); >+ try { >+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7); >+ COMPLETION_PROJECT.setOptions(options); >+ this.workingCopies = new ICompilationUnit[2]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/Test.java", >+ "package test;" + >+ "public class X {\n" + >+ " public void foo() {\n" + >+ " new pack.Test<>().new T2<>()\n" + >+ " }" + >+ "}\n"); >+ >+ this.workingCopies[1] = getWorkingCopy( >+ "/Completion/src/pack/Test.java", >+ "package pack;"+ >+ "public class Test<T> {\n" + >+ " public Test(T t){}\n" + >+ " public class T2<Z> {\n" + >+ " public T2(Z z){}\n" + >+ " }" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "new pack.Test<>().new T2<>("; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ assertResults( >+ "T2[METHOD_REF<CONSTRUCTOR>]{, Lpack.Test<>.T2;, (TZ;)V, T2, (z), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" + >+ "Test<>.T2[ANONYMOUS_CLASS_DECLARATION]{, Lpack.Test<>.T2;, (TZ;)V, null, (z), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}", >+ requestor.getResults()); >+ } finally { >+ // Restore compliance settings. >+ options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance); >+ COMPLETION_PROJECT.setOptions(options); >+ } >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454 >+// Allocation case with explicit type args and diamond together. Should not throw exception. >+// This tests changes in CompleteOnQualifiedAllocationExpression >+public void testBug346454h() throws JavaModelException { >+ Map options = COMPLETION_PROJECT.getOptions(true); >+ Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance); >+ try { >+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7); >+ COMPLETION_PROJECT.setOptions(options); >+ this.workingCopies = new ICompilationUnit[2]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/Test.java", >+ "package test;" + >+ "import pack.Test;\n"+ >+ "public class X {\n" + >+ " public void foo() {\n" + >+ " new <String> Test<>()\n" + >+ " }" + >+ "}\n"); >+ >+ this.workingCopies[1] = getWorkingCopy( >+ "/Completion/src/pack/Test.java", >+ "package pack;"+ >+ "public class Test<T> {\n" + >+ " public <Z> Test(T t, Z z) {\n" + >+ " }" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "new <String> Test<>("; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ assertResults( >+ "Test[METHOD_REF<CONSTRUCTOR>]{, Lpack.Test<>;, <Z:Ljava.lang.Object;>(TT;TZ;)V, Test, (t, z), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" + >+ "Test<>[ANONYMOUS_CLASS_DECLARATION]{, Lpack.Test<>;, <Z:Ljava.lang.Object;>(TT;TZ;)V, null, (t, z), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}", >+ requestor.getResults()); >+ } finally { >+ // Restore compliance settings. >+ options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance); >+ COMPLETION_PROJECT.setOptions(options); >+ } >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454 >+// Qualified Allocation case with explicit type args and diamond together. Should not throw exception. >+// This tests changes in CompleteOnQualifiedAllocationExpression >+public void testBug346454i() throws JavaModelException { >+ Map options = COMPLETION_PROJECT.getOptions(true); >+ Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance); >+ try { >+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7); >+ COMPLETION_PROJECT.setOptions(options); >+ this.workingCopies = new ICompilationUnit[2]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/Test.java", >+ "package test;" + >+ "import pack.Test;\n"+ >+ "public class X {\n" + >+ " public void foo() {\n" + >+ " new <String> Test<>().new T2<>()\n" + >+ " }" + >+ "}\n"); >+ >+ this.workingCopies[1] = getWorkingCopy( >+ "/Completion/src/pack/Test.java", >+ "package pack;"+ >+ "public class Test<T> {\n" + >+ " public <Z> Test(T t) {\n" + >+ " }\n" + >+ " public class T2<U> {\n" + >+ " public T2(U u) {\n" + >+ " }\n" + >+ " }\n" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "new <String> Test<>().new T2<>("; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ assertResults( >+ "T2[METHOD_REF<CONSTRUCTOR>]{, Lpack.Test<>.T2;, (TU;)V, T2, (u), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" + >+ "Test<>.T2[ANONYMOUS_CLASS_DECLARATION]{, Lpack.Test<>.T2;, (TU;)V, null, (u), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}", >+ requestor.getResults()); >+ } finally { >+ // Restore compliance settings. >+ options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance); >+ COMPLETION_PROJECT.setOptions(options); >+ } >+} > }
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 346454
:
197027
|
197215
|
197247