diff options
author | Jesper Steen Møller | 2018-03-07 17:07:33 +0000 |
---|---|---|
committer | Jay Arthanareeswaran | 2018-03-09 11:11:35 +0000 |
commit | 28580a8e9d83198ae2ddbe9029d9028144edb915 (patch) | |
tree | 8c6c72f74bc8b286abcc1ffee260514a695b0ee0 /org.eclipse.jdt.core/codeassist | |
parent | be6db8a853a75e7d08b17e8b0d96810c363ec4c8 (diff) | |
download | eclipse.jdt.core-28580a8e9d83198ae2ddbe9029d9028144edb915.tar.gz eclipse.jdt.core-28580a8e9d83198ae2ddbe9029d9028144edb915.tar.xz eclipse.jdt.core-28580a8e9d83198ae2ddbe9029d9028144edb915.zip |
Change-Id: I1b428a0695b4a27e30a8d6370fcbe171fa95cde2
Signed-off-by: Jesper Moller <jesper@selskabet.org>
Diffstat (limited to 'org.eclipse.jdt.core/codeassist')
2 files changed, 14 insertions, 5 deletions
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java index 3ede784df6..b342151d76 100644 --- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java +++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java @@ -7,6 +7,8 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Jesper Steen Møller <jesper@selskabet.org> - contributions for: + * Bug 531046: [10] ICodeAssist#codeSelect support for 'var' *******************************************************************************/ package org.eclipse.jdt.internal.codeassist; @@ -56,9 +58,11 @@ import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration; import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; import org.eclipse.jdt.internal.compiler.ast.ImportReference; +import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration; import org.eclipse.jdt.internal.compiler.ast.PackageVisibilityStatement; +import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeParameter; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; @@ -1411,6 +1415,12 @@ public final class SelectionEngine extends Engine implements ISearchRequestor { } return true; } + public boolean visit( + LocalDeclaration localDeclaration, BlockScope scope) { + if (localDeclaration.type instanceof SingleTypeReference && ((SingleTypeReference)localDeclaration.type).token == assistIdentifier) + throw new SelectionNodeFound(localDeclaration.binding.type); + return true; // do nothing by default, keep traversing + } public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) { if (fieldDeclaration.name == assistIdentifier){ throw new SelectionNodeFound(fieldDeclaration.binding); 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 64c38a0d35..e323ddc0a3 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 @@ -11,6 +11,8 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Jesper Steen Møller <jesper@selskabet.org> - contributions for: + * Bug 531046: [10] ICodeAssist#codeSelect support for 'var' *******************************************************************************/ package org.eclipse.jdt.internal.codeassist.select; @@ -65,7 +67,6 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; -import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.jdt.internal.compiler.parser.JavadocParser; import org.eclipse.jdt.internal.compiler.parser.RecoveredType; import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; @@ -593,7 +594,7 @@ protected void consumeEnterVariable() { AbstractVariableDeclaration variable = (AbstractVariableDeclaration) this.astStack[this.astPtr]; if (variable.type == this.assistNode){ - if (!this.diet){ + if (!this.diet && ! variable.type.isTypeNameVar(null)) { this.restartRecovery = true; // force to restart in recovery mode this.lastIgnoredToken = -1; } @@ -608,10 +609,8 @@ protected void consumeExitVariableWithInitialization() { AbstractVariableDeclaration variable = (AbstractVariableDeclaration) this.astStack[this.astPtr]; int start = variable.declarationSourceStart; int end = variable.declarationSourceEnd; - char[][] typeName = variable.type == null ? null : variable.type.getTypeName(); // Keep the initialization intact, because that's the only way we are going to know the type - // TODO: Figure out a way to get the scope and hence the compliance - if (typeName == null || !(typeName.length == 1 && CharOperation.equals(typeName[0], TypeConstants.VAR))) { + if (!variable.type.isTypeNameVar(null)) { if ((this.selectionStart < start) && (this.selectionEnd < start) || (this.selectionStart > end) && (this.selectionEnd > end)) { variable.initialization = null; |