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 197215 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 v1.1 + regression tests
patch346454.txt (text/plain), 12.04 KB, created by
Ayushman Jain
on 2011-06-02 01:05:41 EDT
(
hide
)
Description:
proposed fix v1.1 + regression tests
Filename:
MIME Type:
Creator:
Ayushman Jain
Created:
2011-06-02 01:05:41 EDT
Size:
12.04 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 2 Jun 2011 04:58:35 -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 2 Jun 2011 04:58:35 -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 2 Jun 2011 04:58:58 -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 2 Jun 2011 04:58:59 -0000 >@@ -989,7 +989,7 @@ > int currentIdentifiersLength = identifierLength; > while (index > 0) { > int currentTypeArgumentsLength = this.genericsLengthStack[this.genericsLengthPtr--]; >- if (currentTypeArgumentsLength != 0) { >+ if (currentTypeArgumentsLength > 0) { > 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 2 Jun 2011 04:59:27 -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
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