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 233920 Details for
Bug 408230
[1.8][hovering] NPE on hovering over a type inferred parameter in lambda expression
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]
patch for the fix
Bug-408230_new.patch (text/plain), 20.15 KB, created by
ANIRBAN CHAKRABORTY
on 2013-07-29 23:30:18 EDT
(
hide
)
Description:
patch for the fix
Filename:
MIME Type:
Creator:
ANIRBAN CHAKRABORTY
Created:
2013-07-29 23:30:18 EDT
Size:
20.15 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeResolveTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeResolveTests.java >index 942f889..8208c29 100644 >--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeResolveTests.java >+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeResolveTests.java >@@ -1,11 +1,15 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2012 IBM Corporation and others. >+ * Copyright (c) 2000, 2013 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 > * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * This is an implementation of an early-draft specification developed under the Java >+ * Community Process (JCP) and is made available for testing and evaluation purposes >+ * only. The code is not compatible with any specification of the JCP. > * > * Contributors: > * IBM Corporation - initial API and implementation > *******************************************************************************/ > package org.eclipse.jdt.core.tests.model; >@@ -832,6 +836,108 @@ > } > finally { > deleteProject("Test342393"); > } > } >+// Bug 408230 - [1.8][hovering] NPE on hovering over a type inferred parameter in lambda expression >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=408230 >+public void testBug408230a() throws CoreException { >+ try { >+ createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8"); >+ String source = "package p;\n" + >+ "public class X {\n" + >+ " FI i1 = (a, b) -> a+b;\n" + >+ " void foo() {\n" + >+ " FI i2 = (a,barg) -> { return a+barg; };\n" + >+ " }\n" + >+ "}\n" + >+ "interface FI { int f1(int a, int b); }\n"; >+ createFolder("/P/src/p"); >+ createFile( >+ "/P/src/p/X.java", >+ source >+ ); >+ waitForAutoBuild(); >+ >+ ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); >+ String selectString = "barg"; >+ ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length()); >+ } finally { >+ deleteProject("P"); >+ } >+} >+public void testBug408230b() throws CoreException { >+ try { >+ createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8"); >+ String source = "package p;\n" + >+ "public class X {\n" + >+ " FI i1 = (a, b) -> a+b;\n" + >+ " void foo() {\n" + >+ " FI i2 = (aarg) -> { return aarg; };\n" + >+ " }\n" + >+ "}\n" + >+ "interface FI { int f1(int a, int b); }\n"; >+ createFolder("/P/src/p"); >+ createFile( >+ "/P/src/p/X.java", >+ source >+ ); >+ waitForAutoBuild(); >+ >+ ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); >+ String selectString = "aarg"; >+ ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length()); >+ } finally { >+ deleteProject("P"); >+ } >+} >+public void testBug408230c() throws CoreException { >+ try { >+ createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8"); >+ String source = "package p;\n" + >+ "public class X {\n" + >+ " FI i1 = (a, barg) -> a+barg;\n" + >+ " void foo() {\n" + >+ " FI i2 = (a,b) -> { return a+b; };\n" + >+ " }\n" + >+ "}\n" + >+ "interface FI { int f1(int a, int b); }\n"; >+ createFolder("/P/src/p"); >+ createFile( >+ "/P/src/p/X.java", >+ source >+ ); >+ waitForAutoBuild(); >+ >+ ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); >+ String selectString = "barg"; >+ ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length()); >+ } finally { >+ deleteProject("P"); >+ } >+} >+public void testBug408230d() throws CoreException { >+ try { >+ createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8"); >+ String source = "package p;\n" + >+ "public class X {\n" + >+ " FI i1 = (aarg) -> aarg++;\n" + >+ " void foo() {\n" + >+ " FI i2 = (a,b) -> { return a+b; };\n" + >+ " }\n" + >+ "}\n" + >+ "interface FI { int f1(int a, int b); }\n"; >+ createFolder("/P/src/p"); >+ createFile( >+ "/P/src/p/X.java", >+ source >+ ); >+ waitForAutoBuild(); >+ >+ ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); >+ String selectString = "aarg"; >+ ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length()); >+ } finally { >+ deleteProject("P"); >+ } >+} > } >diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java >index 90722bf..12dfe22 100644 >--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java >+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java >@@ -1439,10 +1439,16 @@ > this action is also performed when shifting token after recovery > got activated once. > */ > recoveryTokenCheck(); > } >+protected void consumeTypeElidedLambdaParameter(boolean parenthesized) { >+ if (this.astStack[this.astPtr] instanceof LocalDeclaration) { >+ this.astStack[this.astPtr].bits |= ASTNode.IsInitializedByLamdaExpression; >+ } >+ super.consumeTypeElidedLambdaParameter(parenthesized); >+} > > public String toString() { > String s = Util.EMPTY_STRING; > s = s + "elementKindStack : int[] = {"; //$NON-NLS-1$ > for (int i = 0; i <= this.elementPtr; i++) { >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java >index 55091f8..8cf1613 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java >@@ -41,11 +41,11 @@ > public final static int Bit3 = 0x4; // return type (operator) | name reference kind (name ref) | implicit this (this ref) | is argument(local) > public final static int Bit4 = 0x8; // return type (operator) | first assignment to local (name ref,local decl) | undocumented empty block (block, type and method decl) > public final static int Bit5 = 0x10; // value for return (expression) | has all method bodies (unit) | supertype ref (type ref) | resolved (field decl) > public final static int Bit6 = 0x20; // depth (name ref, msg) | ignore need cast check (cast expression) | error in signature (method declaration/ initializer) | is recovered (annotation reference) > public final static int Bit7 = 0x40; // depth (name ref, msg) | operator (operator) | need runtime checkcast (cast expression) | label used (labelStatement) | needFreeReturn (AbstractMethodDeclaration) >- public final static int Bit8 = 0x80; // depth (name ref, msg) | operator (operator) | unsafe cast (cast expression) | is default constructor (constructor declaration) | isElseStatementUnreachable (if statement) >+ public final static int Bit8 = 0x80; // depth (name ref, msg) | operator (operator) | unsafe cast (cast expression) | is default constructor (constructor declaration) | isElseStatementUnreachable (if statement) | IsInitializedByLambdaExpression (local declaration) > public final static int Bit9 = 0x100; // depth (name ref, msg) | operator (operator) | is local type (type decl) | isThenStatementUnreachable (if statement) | can be static > public final static int Bit10= 0x200; // depth (name ref, msg) | operator (operator) | is anonymous type (type decl) > public final static int Bit11 = 0x400; // depth (name ref, msg) | operator (operator) | is member type (type decl) > public final static int Bit12 = 0x800; // depth (name ref, msg) | operator (operator) | has abstract methods (type decl) > public final static int Bit13 = 0x1000; // depth (name ref, msg) | is secondary type (type decl) >@@ -126,10 +126,11 @@ > public static final int IsTypeElided = Bit2; // type elided lambda argument. > public static final int IsArgument = Bit3; > public static final int IsLocalDeclarationReachable = Bit31; > public static final int IsForeachElementVariable = Bit5; > public static final int ShadowsOuterLocal = Bit22; >+ public static final int IsInitializedByLamdaExpression = Bit8; > > // for name refs or local decls > public static final int FirstAssignmentToLocal = Bit4; > > // for msg or field references >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredBlock.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredBlock.java >index 1d74fe8..48453b4 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredBlock.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredBlock.java >@@ -1,12 +1,16 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2009 IBM Corporation and others. >+ * Copyright (c) 2000, 2013 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 > * http://www.eclipse.org/legal/epl-v10.html > * >+ * This is an implementation of an early-draft specification developed under the Java >+ * Community Process (JCP) and is made available for testing and evaluation purposes >+ * only. The code is not compatible with any specification of the JCP. >+ * > * Contributors: > * IBM Corporation - initial API and implementation > *******************************************************************************/ > package org.eclipse.jdt.internal.compiler.parser; > >@@ -17,10 +21,11 @@ > import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; > import org.eclipse.jdt.internal.compiler.ast.Argument; > import org.eclipse.jdt.internal.compiler.ast.ASTNode; > import org.eclipse.jdt.internal.compiler.ast.Block; > import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; >+import org.eclipse.jdt.internal.compiler.ast.LambdaExpression; > import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; > import org.eclipse.jdt.internal.compiler.ast.Statement; > import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; > import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; > import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; >@@ -29,11 +34,11 @@ > > public Block blockDeclaration; > public RecoveredStatement[] statements; > public int statementCount; > public boolean preserveContent = false; >- public RecoveredLocalVariable pendingArgument; >+ public RecoveredLocalVariable [] pendingArguments = null; > > int pendingModifiers; > int pendingModifersSourceStart = -1; > RecoveredAnnotation[] pendingAnnotations; > int pendingAnnotationCount; >@@ -54,10 +59,21 @@ > return this; // ignore this element > } > } > return super.add(methodDeclaration, bracketBalanceValue); > } >+public void addPendingArgument(RecoveredLocalVariable pendingArg) { >+ if (this.pendingArguments == null) { >+ RecoveredLocalVariable recoveredLocalVariable [] = {pendingArg}; >+ this.pendingArguments = recoveredLocalVariable; >+ } >+ else { >+ int length = this.pendingArguments.length; >+ System.arraycopy(this.pendingArguments, 0, this.pendingArguments = new RecoveredLocalVariable[length+1], 0, length); >+ this.pendingArguments[length] = pendingArg; >+ } >+} > /* > * Record a nested block declaration > */ > public RecoveredElement add(Block nestedBlockDeclaration, int bracketBalanceValue) { > resetPendingModifiers(); >@@ -70,13 +86,15 @@ > } > > RecoveredBlock element = new RecoveredBlock(nestedBlockDeclaration, this, bracketBalanceValue); > > // if we have a pending Argument, promote it into the new block >- if (this.pendingArgument != null){ >- element.attach(this.pendingArgument); >- this.pendingArgument = null; >+ if (this.pendingArguments != null) { >+ for (int indx = 0; indx < this.pendingArguments.length; indx++) { >+ element.attach(this.pendingArguments[indx]); >+ } >+ this.pendingArguments = null; > } > if(parser().statementRecoveryActivated) { > addBlockStatement(element); > } > attach(element); >@@ -129,11 +147,11 @@ > this.pendingModifersSourceStart); > } > resetPendingModifiers(); > > if (localDeclaration instanceof Argument){ >- this.pendingArgument = element; >+ addPendingArgument(element); > return this; > } > > attach(element); > if (localDeclaration.declarationSourceEnd == 0) return element; >@@ -277,11 +295,14 @@ > return result.toString(); > } > /* > * Rebuild a block from the nested structure which is in scope > */ >-public Block updatedBlock(int depth, Set knownTypes){ >+public Block updatedBlock(int depth, Set knownTypes) { >+ return updatedBlock(depth, knownTypes, false); >+} >+public Block updatedBlock(int depth, Set knownTypes, boolean lambdaExpressionExpected) { > > // if block was not marked to be preserved or empty, then ignore it > if (!this.preserveContent || this.statementCount == 0) return null; > > Statement[] updatedStatements = new Statement[this.statementCount]; >@@ -323,13 +344,20 @@ > > int lastEnd = this.blockDeclaration.sourceStart; > > // only collect the non-null updated statements > for (int i = 0; i < this.statementCount; i++){ >- Statement updatedStatement = this.statements[i].updatedStatement(depth, knownTypes); >+ boolean lambdaExprInit = i > 0 && lambdaExpressionInitializable(this.statements[i-1]); >+ Statement updatedStatement = this.statements[i].updatedStatement(depth, knownTypes, lambdaExprInit); > if (updatedStatement != null){ >- updatedStatements[updatedCount++] = updatedStatement; >+ LambdaExpression lambdaExpr = getLambdaExpression(updatedStatement); >+ if (lambdaExprInit && lambdaExpr != null) { >+ ((LocalDeclaration)updatedStatements[updatedCount-1]).initialization = lambdaExpr; >+ } >+ else { >+ updatedStatements[updatedCount++] = updatedStatement; >+ } > > if (updatedStatement instanceof LocalDeclaration) { > LocalDeclaration localDeclaration = (LocalDeclaration) updatedStatement; > if(localDeclaration.declarationSourceEnd > lastEnd) { > lastEnd = localDeclaration.declarationSourceEnd; >@@ -351,11 +379,18 @@ > // resize statement collection if necessary > if (updatedCount != this.statementCount){ > this.blockDeclaration.statements = new Statement[updatedCount]; > System.arraycopy(updatedStatements, 0, this.blockDeclaration.statements, 0, updatedCount); > } else { >- this.blockDeclaration.statements = updatedStatements; >+ LambdaExpression lambda = null; >+ if (lambdaExpressionExpected && (lambda = canGetLambdaExpression(updatedStatements, updatedCount)) != null) { >+ Statement [] stmt = {lambda}; >+ this.blockDeclaration.statements = stmt; >+ } >+ else { >+ this.blockDeclaration.statements = updatedStatements; >+ } > } > > if (this.blockDeclaration.sourceEnd == 0) { > if(lastEnd < bodyEndValue) { > this.blockDeclaration.sourceEnd = bodyEndValue; >@@ -364,17 +399,47 @@ > } > } > > return this.blockDeclaration; > } >+public LambdaExpression getLambdaExpression (Statement stmnt) { >+ if (stmnt instanceof LambdaExpression) { >+ return (LambdaExpression)stmnt; >+ } >+ else if (stmnt instanceof Block && ((Block)stmnt).statements[0] instanceof LambdaExpression) { >+ return (LambdaExpression)((Block)stmnt).statements[0]; >+ } >+ return null; >+} >+public LambdaExpression canGetLambdaExpression (Statement [] statementsArray, int count) { >+ for (int indx = 0; indx < count - 1; indx++) { >+ if (!(statementsArray[indx] instanceof Argument)) { >+ return null; >+ } >+ } >+ Argument [] arguments = new Argument [count-1]; >+ System.arraycopy(statementsArray, 0, arguments, 0, count-1); >+ return new LambdaExpression(parser().compilationUnit.compilationResult, arguments, statementsArray[count-1]); >+} > /* > * Rebuild a statement from the nested structure which is in scope > */ > public Statement updatedStatement(int depth, Set knownTypes){ > > return updatedBlock(depth, knownTypes); > } >+public Statement updatedStatement(int depth, Set knownTypes, boolean lambdaExpressionExpected) { >+ >+ return lambdaExpressionExpected ? updatedBlock(depth, knownTypes, true) : updatedStatement(depth, knownTypes); >+} >+boolean lambdaExpressionInitializable(RecoveredStatement stmnt) { >+ if (stmnt instanceof RecoveredLocalVariable) { >+ RecoveredLocalVariable recLocVar = (RecoveredLocalVariable) stmnt; >+ return recLocVar.localDeclaration != null && (recLocVar.localDeclaration.bits & ASTNode.IsInitializedByLamdaExpression) != 0; >+ } >+ return false; >+} > /* > * A closing brace got consumed, might have closed the current element, > * in which case both the currentElement is exited > */ > public RecoveredElement updateOnClosingBrace(int braceStart, int braceEnd){ >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredStatement.java >index 5d3f653..540c2e2 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredStatement.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredStatement.java >@@ -1,12 +1,16 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2009 IBM Corporation and others. >+ * Copyright (c) 2000, 2013 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 > * http://www.eclipse.org/legal/epl-v10.html > * >+ * This is an implementation of an early-draft specification developed under the Java >+ * Community Process (JCP) and is made available for testing and evaluation purposes >+ * only. The code is not compatible with any specification of the JCP. >+ * > * Contributors: > * IBM Corporation - initial API and implementation > *******************************************************************************/ > package org.eclipse.jdt.internal.compiler.parser; > >@@ -42,10 +46,13 @@ > return tabString(tab) + "Recovered statement:\n" + this.statement.print(tab + 1, new StringBuffer(10)); //$NON-NLS-1$ > } > public Statement updatedStatement(int depth, Set knownTypes){ > return this.statement; > } >+public Statement updatedStatement(int depth, Set knownTypes, boolean lambdaExpressionExpected) { >+ return updatedStatement(depth, knownTypes); >+} > public void updateParseTree(){ > updatedStatement(0, new HashSet()); > } > /* > * Update the declarationSourceEnd of the corresponding parse node >diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SelectionRequestor.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SelectionRequestor.java >index 7accbff..1ab6fa7 100644 >--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SelectionRequestor.java >+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SelectionRequestor.java >@@ -1,12 +1,16 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2011 IBM Corporation and others. >+ * Copyright (c) 2000, 2013 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 > * http://www.eclipse.org/legal/epl-v10.html > * >+ * This is an implementation of an early-draft specification developed under the Java >+ * Community Process (JCP) and is made available for testing and evaluation purposes >+ * only. The code is not compatible with any specification of the JCP. >+ * > * Contributors: > * IBM Corporation - initial API and implementation > *******************************************************************************/ > package org.eclipse.jdt.internal.core; > >@@ -449,11 +453,11 @@ > new String(local.name), > local.declarationSourceStart, > local.declarationSourceEnd, > local.sourceStart, > local.sourceEnd, >- Util.typeSignature(local.type), >+ local.type == null ? Signature.createTypeSignature(local.binding.type.readableName(), false) : Util.typeSignature(local.type), > local.annotations, > local.modifiers, > local.getKind() == AbstractVariableDeclaration.PARAMETER); > } > if (localVar != null) {
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 408230
:
233920
|
236207