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 99725 Details for
Bug 230885
[content assist] NPE at ParameterGuesser.createVariable()
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix
bug230885_001.txt (text/plain), 14.25 KB, created by
David Audel
on 2008-05-12 10:59:59 EDT
(
hide
)
Description:
Proposed fix
Filename:
MIME Type:
Creator:
David Audel
Created:
2008-05-12 10:59:59 EDT
Size:
14.25 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: codeassist/org/eclipse/jdt/internal/codeassist/CompletionUnitStructureRequestor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionUnitStructureRequestor.java,v >retrieving revision 1.1 >diff -u -r1.1 CompletionUnitStructureRequestor.java >--- codeassist/org/eclipse/jdt/internal/codeassist/CompletionUnitStructureRequestor.java 6 Mar 2008 15:31:28 -0000 1.1 >+++ codeassist/org/eclipse/jdt/internal/codeassist/CompletionUnitStructureRequestor.java 12 May 2008 13:37:38 -0000 >@@ -59,6 +59,7 @@ > > private Map bindingCache; > private Map elementCache; >+ private Map elementWithProblemCache; > > public CompletionUnitStructureRequestor( > ICompilationUnit unit, >@@ -67,12 +68,14 @@ > ASTNode assistNode, > Map bindingCache, > Map elementCache, >+ Map elementWithProblemCache, > Map newElements) { > super(unit, unitInfo, newElements); > this.parser = parser; > this.assistNode = assistNode; > this.bindingCache = bindingCache; > this.elementCache = elementCache; >+ this.elementWithProblemCache = elementWithProblemCache; > } > > protected Annotation createAnnotation(JavaElement parent, String name) { >@@ -85,6 +88,8 @@ > if (fieldInfo.node.binding != null) { > this.bindingCache.put(field, fieldInfo.node.binding); > this.elementCache.put(fieldInfo.node.binding, field); >+ } else { >+ this.elementWithProblemCache.put(fieldInfo.node, field); > } > return field; > } >@@ -108,6 +113,8 @@ > if (methodInfo.node.binding != null) { > this.bindingCache.put(method, methodInfo.node.binding); > this.elementCache.put(methodInfo.node.binding, method); >+ } else { >+ this.elementWithProblemCache.put(methodInfo.node, method); > } > return method; > } >@@ -122,6 +129,8 @@ > if (typeInfo.node.binding != null) { > this.bindingCache.put(type, typeInfo.node.binding); > this.elementCache.put(typeInfo.node.binding, type); >+ } else { >+ this.elementWithProblemCache.put(typeInfo.node, type); > } > return type; > } >Index: codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java,v >retrieving revision 1.3 >diff -u -r1.3 InternalExtendedCompletionContext.java >--- codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java 21 Apr 2008 10:26:36 -0000 1.3 >+++ codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java 12 May 2008 13:37:38 -0000 >@@ -86,6 +86,7 @@ > private boolean hasComputedEnclosingJavaElements; > Map bindingsToNodes; > private Map bindingsToHandles; >+ private Map nodesWithProblemsToHandles; > private ICompilationUnit compilationUnit; > > public InternalExtendedCompletionContext( >@@ -117,6 +118,7 @@ > > HashMap handleToBinding = new HashMap(); > HashMap bindingToHandle = new HashMap(); >+ HashMap nodeWithProblemToHandle = new HashMap(); > HashMap handleToInfo = new HashMap(); > > org.eclipse.jdt.core.ICompilationUnit handle = new AssistCompilationUnit(original, this.owner, handleToBinding, handleToInfo); >@@ -132,6 +134,7 @@ > this.assistNode, > handleToBinding, > bindingToHandle, >+ nodeWithProblemToHandle, > handleToInfo); > > CompletionElementNotifier notifier = >@@ -149,6 +152,7 @@ > new HashMap()); > > this.bindingsToHandles = bindingToHandle; >+ this.nodesWithProblemsToHandles = nodeWithProblemToHandle; > this.compilationUnit = handle; > } > } >@@ -218,12 +222,12 @@ > ReferenceContext referenceContext = binding.declaringScope.referenceContext(); > if (referenceContext instanceof AbstractMethodDeclaration) { > AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) referenceContext; >- parent = this.getJavaElementOfCompilationUnit(methodDeclaration.binding); >+ parent = this.getJavaElementOfCompilationUnit(methodDeclaration, methodDeclaration.binding); > } else if (referenceContext instanceof TypeDeclaration){ > // Local variable is declared inside an initializer > TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext; > >- IType type = (IType)this.getJavaElementOfCompilationUnit(typeDeclaration.binding); >+ IType type = (IType)this.getJavaElementOfCompilationUnit(typeDeclaration, typeDeclaration.binding); > if (type != null) { > try { > IInitializer[] initializers = type.getInitializers(); >@@ -268,6 +272,19 @@ > return (JavaElement)this.bindingsToHandles.get(binding); > } > >+ private JavaElement getJavaElementOfCompilationUnit(ASTNode node, Binding binding) { >+ if (!this.hasComputedEnclosingJavaElements) { >+ computeEnclosingJavaElements(); >+ } >+ if (binding != null) { >+ if (this.bindingsToHandles == null) return null; >+ return (JavaElement)this.bindingsToHandles.get(binding); >+ } else { >+ if (this.nodesWithProblemsToHandles == null) return null; >+ return (JavaElement)this.nodesWithProblemsToHandles.get(node); >+ } >+ } >+ > private TypeBinding getTypeFromSignature(String typeSignature, Scope scope) { > TypeBinding assignableTypeBinding = null; > >@@ -353,7 +370,8 @@ > next : for (int i = 0; i < size; i++) { > LocalVariableBinding binding = (LocalVariableBinding) visibleLocalVariables.elementAt(i); > if (assignableTypeBinding != null && !binding.type.isCompatibleWith(assignableTypeBinding)) continue next; >- result[elementCount++] = getJavaElement(binding); >+ JavaElement localVariable = getJavaElement(binding); >+ if (localVariable != null) result[elementCount++] = localVariable; > } > > } >Index: codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceType.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceType.java,v >retrieving revision 1.2 >diff -u -r1.2 AssistSourceType.java >--- codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceType.java 14 Mar 2008 16:43:23 -0000 1.2 >+++ codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceType.java 12 May 2008 13:37:38 -0000 >@@ -29,6 +29,7 @@ > private Map infoCache; > > private String uniqueKey; >+ private boolean isResolved; > > public AssistSourceType(JavaElement parent, String name, Map bindingCache, Map infoCache) { > super(parent, name, null); >@@ -54,14 +55,24 @@ > if (this.uniqueKey == null) { > Binding binding = (Binding) this.bindingCache.get(this); > if (binding != null) { >+ this.isResolved = true; > this.uniqueKey = new String(binding.computeUniqueKey()); >+ } else { >+ this.isResolved = false; >+ try { >+ this.uniqueKey = getKey(this, false/*don't open*/); >+ } catch (JavaModelException e) { >+ // happen only if force open is true >+ return null; >+ } > } > } > return this.uniqueKey; > } > > public boolean isResolved() { >- return getKey() != null; >+ getKey(); >+ return this.isResolved; > } > > protected void toStringInfo(int tab, StringBuffer buffer, Object info,boolean showResolvedInfo) { >Index: codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceMethod.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceMethod.java,v >retrieving revision 1.1 >diff -u -r1.1 AssistSourceMethod.java >--- codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceMethod.java 6 Mar 2008 15:31:31 -0000 1.1 >+++ codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceMethod.java 12 May 2008 13:37:38 -0000 >@@ -26,6 +26,7 @@ > private Map infoCache; > > private String uniqueKey; >+ private boolean isResolved; > > public AssistSourceMethod(JavaElement parent, String name, String[] parameterTypes, Map bindingCache, Map infoCache) { > super(parent, name, parameterTypes, null); >@@ -44,14 +45,24 @@ > if (this.uniqueKey == null) { > Binding binding = (Binding) this.bindingCache.get(this); > if (binding != null) { >+ this.isResolved = true; > this.uniqueKey = new String(binding.computeUniqueKey()); >+ } else { >+ this.isResolved = false; >+ try { >+ this.uniqueKey = getKey(this, false/*don't open*/); >+ } catch (JavaModelException e) { >+ // happen only if force open is true >+ return null; >+ } > } > } > return this.uniqueKey; > } > > public boolean isResolved() { >- return getKey() != null; >+ getKey(); >+ return this.isResolved; > } > > protected void toStringInfo(int tab, StringBuffer buffer, Object info,boolean showResolvedInfo) { >Index: codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceField.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceField.java,v >retrieving revision 1.1 >diff -u -r1.1 AssistSourceField.java >--- codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceField.java 6 Mar 2008 15:31:31 -0000 1.1 >+++ codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceField.java 12 May 2008 13:37:38 -0000 >@@ -25,6 +25,7 @@ > private Map infoCache; > > private String uniqueKey; >+ private boolean isResolved; > > public AssistSourceField(JavaElement parent, String name, Map bindingCache, Map infoCache) { > super(parent, name, null); >@@ -43,14 +44,24 @@ > if (this.uniqueKey == null) { > Binding binding = (Binding) this.bindingCache.get(this); > if (binding != null) { >+ this.isResolved = true; > this.uniqueKey = new String(binding.computeUniqueKey()); >+ } else { >+ this.isResolved = false; >+ try { >+ this.uniqueKey = getKey(this, false/*don't open*/); >+ } catch (JavaModelException e) { >+ // happen only if force open is true >+ return null; >+ } > } > } > return this.uniqueKey; > } > > public boolean isResolved() { >- return getKey() != null; >+ getKey(); >+ return this.isResolved; > } > > protected void toStringInfo(int tab, StringBuffer buffer, Object info,boolean showResolvedInfo) { >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java,v >retrieving revision 1.10 >diff -u -r1.10 CompletionContextTests.java >--- src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java 14 Apr 2008 10:55:43 -0000 1.10 >+++ src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java 12 May 2008 13:37:41 -0000 >@@ -4779,4 +4779,89 @@ > "}", > result.context); > } >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=230885 >+public void test0163() throws JavaModelException { >+ this.workingCopies = new ICompilationUnit[3]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src3/test/X.java", >+ "public class Foo {\n"+ >+ "\n"+ >+ " private void addDepencency(int source, int target, int depth) {\n"+ >+ " }\n"+ >+ "\n"+ >+ " private void addDataDependencies(int source) {\n"+ >+ " addD/**/\n"+ >+ " }\n"+ >+ "\n"+ >+ " private void addDataDependencies(int source) {\n"+ >+ " }\n"+ >+ "}"); >+ >+ >+ String str = this.workingCopies[0].getSource(); >+ int tokenStart = str.lastIndexOf("addD/**/"); >+ int tokenEnd = tokenStart + "addD".length() - 1; >+ int cursorLocation = str.lastIndexOf("addD/**/") + "addD".length(); >+ >+ CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "I"); >+ >+ String jclPath = getExternalJCLPathString(); >+ assertResults( >+ "completion offset="+(cursorLocation)+"\n" + >+ "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" + >+ "completion token=\"addD\"\n" + >+ "completion token kind=TOKEN_KIND_NAME\n" + >+ "expectedTypesSignatures=null\n" + >+ "expectedTypesKeys=null\n" + >+ "completion token location={STATEMENT_START}\n" + >+ "visibleElements={\n" + >+ " source [in addDataDependencies(int) [in Foo [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" + >+ " hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" + >+ "}", >+ result.context); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=230885 >+public void test0164() throws JavaModelException { >+ this.workingCopies = new ICompilationUnit[3]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src3/test/X.java", >+ "public class Foo {\n"+ >+ "\n"+ >+ " private void addDepencency(int source, int target, int depth) {\n"+ >+ " }\n"+ >+ "\n"+ >+ " private int addDataDependencies(int source) {\n"+ >+ " }\n"+ >+ "\n"+ >+ " private int addDataDependencies(int source) {\n"+ >+ " addD/**/\n"+ >+ " }\n"+ >+ "\n"+ >+ " private int addDataDependencies(int source) {\n"+ >+ " }\n"+ >+ "}"); >+ >+ >+ String str = this.workingCopies[0].getSource(); >+ int tokenStart = str.lastIndexOf("addD/**/"); >+ int tokenEnd = tokenStart + "addD".length() - 1; >+ int cursorLocation = str.lastIndexOf("addD/**/") + "addD".length(); >+ >+ CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "I"); >+ >+ String jclPath = getExternalJCLPathString(); >+ assertResults( >+ "completion offset="+(cursorLocation)+"\n" + >+ "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" + >+ "completion token=\"addD\"\n" + >+ "completion token kind=TOKEN_KIND_NAME\n" + >+ "expectedTypesSignatures=null\n" + >+ "expectedTypesKeys=null\n" + >+ "completion token location={STATEMENT_START}\n" + >+ "visibleElements={\n" + >+ " source [in addDataDependencies(int)#2 [in Foo [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" + >+ " hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" + >+ "}", >+ result.context); >+} > }
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 230885
:
99066
| 99725