### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java,v retrieving revision 1.353 diff -u -r1.353 Parser.java --- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 5 Sep 2006 18:34:59 -0000 1.353 +++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 19 Oct 2006 14:12:34 -0000 @@ -184,7 +184,7 @@ // statement recovery // public boolean statementRecoveryEnabled = true; - protected boolean methodRecoveryActivated = false; + public boolean methodRecoveryActivated = false; protected boolean statementRecoveryActivated = false; protected TypeDeclaration[] recoveredTypes; protected int recoveredTypePtr; 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.305 diff -u -r1.305 CompletionEngine.java --- codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 19 Oct 2006 13:47:37 -0000 1.305 +++ codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 19 Oct 2006 14:12:28 -0000 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.jdt.internal.codeassist; +import java.util.ArrayList; import java.util.Locale; import java.util.Map; @@ -37,6 +38,7 @@ import org.eclipse.jdt.internal.compiler.ast.*; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.env.*; +import org.eclipse.jdt.internal.compiler.impl.ReferenceContext; import org.eclipse.jdt.internal.compiler.lookup.*; import org.eclipse.jdt.internal.compiler.parser.Scanner; import org.eclipse.jdt.internal.compiler.parser.ScannerHelper; @@ -1258,7 +1260,7 @@ this.completionToken = method.selector; - findVariableNames(this.completionToken, method.returnType, excludeNames, FIELD, method.modifiers); + findVariableNames(this.completionToken, method.returnType, excludeNames, null, FIELD, method.modifiers); } } else if (astNode instanceof CompletionOnFieldName) { if (!this.requestor.isIgnored(CompletionProposal.VARIABLE_DECLARATION)) { @@ -1272,29 +1274,31 @@ this.completionToken = field.realName; - findVariableNames(field.realName, field.type, excludeNames, FIELD, field.modifiers); + findVariableNames(field.realName, field.type, excludeNames, null, FIELD, field.modifiers); } } else if (astNode instanceof CompletionOnLocalName || astNode instanceof CompletionOnArgumentName) { if (!this.requestor.isIgnored(CompletionProposal.VARIABLE_DECLARATION)) { LocalDeclaration variable = (LocalDeclaration) astNode; LocalVariableBinding[] locals = ((BlockScope)scope).locals; - char[][] excludeNames = new char[locals.length][]; + char[][] discouragedNames = new char[locals.length][]; int localCount = 0; for(int i = 0 ; i < locals.length ; i++){ if (locals[i] != null) { - excludeNames[localCount++] = locals[i].name; + discouragedNames[localCount++] = locals[i].name; } } - System.arraycopy(excludeNames, 0, excludeNames = new char[localCount][], 0, localCount); + System.arraycopy(discouragedNames, 0, discouragedNames = new char[localCount][], 0, localCount); if (variable instanceof CompletionOnLocalName){ this.completionToken = ((CompletionOnLocalName) variable).realName; - findVariableNames(this.completionToken, variable.type, excludeNames, LOCAL, variable.modifiers); + char[][] forbiddenNames = findVariableFromUnresolvedReference(variable, (BlockScope)scope, discouragedNames); + findVariableNames(this.completionToken, variable.type, discouragedNames, forbiddenNames, LOCAL, variable.modifiers); } else { CompletionOnArgumentName arg = (CompletionOnArgumentName) variable; this.completionToken = arg.realName; - findVariableNames(this.completionToken, variable.type, excludeNames, arg.isCatchArgument ? LOCAL : ARGUMENT, variable.modifiers); + char[][] forbiddenNames = findVariableFromUnresolvedReference(variable, (BlockScope)scope, discouragedNames); + findVariableNames(this.completionToken, variable.type, discouragedNames, forbiddenNames, arg.isCatchArgument ? LOCAL : ARGUMENT, variable.modifiers); } } } else if (astNode instanceof CompletionOnKeyword) { @@ -6232,6 +6236,92 @@ } } } + private char[][] findVariableFromUnresolvedReference(LocalDeclaration variable, BlockScope scope, final char[][] discouragedNames) { + final TypeReference type = variable.type; + if(type != null && + type.resolvedType != null && + type.resolvedType.problemId() == ProblemReasons.NoError){ + + final int discouragedNamesCount = discouragedNames == null ? 0 : discouragedNames.length; + final ArrayList proposedNames = new ArrayList(); + + UnresolvedReferenceNameFinder.UnresolvedReferenceNameRequestor nameRequestor = + new UnresolvedReferenceNameFinder.UnresolvedReferenceNameRequestor() { + public void acceptName(char[] name) { + for (int i = 0; i < discouragedNamesCount; i++) { + if (CharOperation.equals(discouragedNames[i], name, false)) return; + } + + int relevance = computeBaseRelevance(); + relevance += computeRelevanceForInterestingProposal(); + relevance += computeRelevanceForCaseMatching(completionToken, name); + relevance += R_NAME_FIRST_PREFIX; + relevance += R_NAME_FIRST_SUFFIX; + relevance += R_NAME_LESS_NEW_CHARACTERS; + relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no access restriction for variable name + + // accept result + CompletionEngine.this.noProposal = false; + if(!CompletionEngine.this.requestor.isIgnored(CompletionProposal.VARIABLE_DECLARATION)) { + CompletionProposal proposal = CompletionEngine.this.createProposal(CompletionProposal.VARIABLE_DECLARATION, CompletionEngine.this.actualCompletionPosition); + proposal.setSignature(getSignature(type.resolvedType)); + proposal.setPackageName(type.resolvedType.qualifiedPackageName()); + proposal.setTypeName(type.resolvedType.qualifiedSourceName()); + proposal.setName(name); + proposal.setCompletion(name); + //proposal.setFlags(Flags.AccDefault); + proposal.setReplaceRange(CompletionEngine.this.startPosition - CompletionEngine.this.offset, CompletionEngine.this.endPosition - CompletionEngine.this.offset); + proposal.setRelevance(relevance); + CompletionEngine.this.requestor.accept(proposal); + if(DEBUG) { + CompletionEngine.this.printDebug(proposal); + } + } + proposedNames.add(name); + } + }; + + ReferenceContext referenceContext = scope.referenceContext(); + if (referenceContext instanceof AbstractMethodDeclaration) { + AbstractMethodDeclaration md = (AbstractMethodDeclaration)referenceContext; + + UnresolvedReferenceNameFinder nameFinder = new UnresolvedReferenceNameFinder(this); + nameFinder.find( + completionToken, + md, + variable.declarationSourceEnd + 1, + nameRequestor); + } else if (referenceContext instanceof TypeDeclaration) { + TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext; + FieldDeclaration[] fields = typeDeclaration.fields; + if (fields != null) { + done : for (int i = 0; i < fields.length; i++) { + if (fields[i] instanceof Initializer) { + Initializer initializer = (Initializer) fields[i]; + if (initializer.bodyStart <= variable.sourceStart && + variable.sourceStart < initializer.bodyEnd) { + UnresolvedReferenceNameFinder nameFinder = new UnresolvedReferenceNameFinder(this); + nameFinder.find( + completionToken, + initializer, + typeDeclaration.scope, + variable.declarationSourceEnd + 1, + nameRequestor); + break done; + } + } + } + } + } + + int proposedNamesCount = proposedNames.size(); + if (proposedNamesCount > 0) { + return (char[][])proposedNames.toArray(new char[proposedNamesCount][]); + } + } + + return null; + } // Helper method for private void findVariableNames(char[] name, TypeReference type ) private void findVariableName( char[] token, @@ -6239,7 +6329,8 @@ char[] qualifiedSourceName, char[] sourceName, final TypeBinding typeBinding, - char[][] excludeNames, + char[][] discouragedNames, + final char[][] forbiddenNames, int dim, int kind, int modifiers){ @@ -6283,6 +6374,11 @@ accept(name, 0, reusedCharacters); } void accept(char[] name, int prefixAndSuffixRelevance, int reusedCharacters){ + int l = forbiddenNames == null ? 0 : forbiddenNames.length; + for (int i = 0; i < l; i++) { + if (CharOperation.equals(forbiddenNames[i], name, false)) return; + } + if (CharOperation.prefixEquals(t, name, false)) { int relevance = computeBaseRelevance(); relevance += computeRelevanceForInterestingProposal(); @@ -6321,7 +6417,7 @@ dim, modifiers, token, - excludeNames, + discouragedNames, namingRequestor); break; case LOCAL : @@ -6331,7 +6427,7 @@ qualifiedSourceName, dim, token, - excludeNames, + discouragedNames, namingRequestor); break; case ARGUMENT : @@ -6341,13 +6437,13 @@ qualifiedSourceName, dim, token, - excludeNames, + discouragedNames, namingRequestor); break; } } - private void findVariableNames(char[] name, TypeReference type , char[][] excludeNames, int kind, int modifiers){ + private void findVariableNames(char[] name, TypeReference type , char[][] discouragedNames, char[][] forbiddenNames, int kind, int modifiers){ if(type != null && type.resolvedType != null && @@ -6359,7 +6455,8 @@ tb.leafComponentType().qualifiedSourceName(), tb.leafComponentType().sourceName(), tb, - excludeNames, + discouragedNames, + forbiddenNames, type.dimensions(), kind, modifiers); Index: codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionScanner.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionScanner.java,v retrieving revision 1.59 diff -u -r1.59 CompletionScanner.java --- codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionScanner.java 28 Mar 2006 20:29:57 -0000 1.59 +++ codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionScanner.java 19 Oct 2006 14:12:30 -0000 @@ -40,6 +40,14 @@ public static final char[] EmptyCompletionIdentifier = {}; + private boolean record = false; + public char[] prefix; + private int currentToken; + private int currentTokenStart; + public int potentialVariableNamesPtr; + public char[][] potentialVariableNames; + public int[] potentialVariableNameStarts; + public CompletionScanner(long sourceLevel) { super( false /*comment*/, @@ -50,6 +58,25 @@ null/*taskPriorities*/, true/*taskCaseSensitive*/); } +private void addPotentialName(char[] name, int start) { + int length = this.potentialVariableNames.length; + if (this.potentialVariableNamesPtr >= length - 1) { + System.arraycopy( + this.potentialVariableNames, + 0, + this.potentialVariableNames = new char[length * 2][], + 0, + length); + System.arraycopy( + this.potentialVariableNameStarts, + 0, + this.potentialVariableNameStarts = new int[length * 2], + 0, + length); + } + this.potentialVariableNames[++this.potentialVariableNamesPtr] = name; + this.potentialVariableNameStarts[this.potentialVariableNamesPtr] = start; +} /* * Truncate the current identifier if it is containing the cursor location. Since completion is performed * on an identifier prefix. @@ -102,6 +129,32 @@ return super.getCurrentTokenSourceString(); } public int getNextToken() throws InvalidInputException { + int nextToken = this.getNextToken0(); + if (this.record) { + switch (nextToken) { + case TokenNameIdentifier: + if (this.currentToken != TokenNameDOT) { + char[] identifier = this.getCurrentIdentifierSource(); + if (!Character.isUpperCase(identifier[0]) && + CharOperation.prefixEquals(this.prefix, identifier, true)) { + this.addPotentialName(identifier, this.startPosition); + } + } + break; + case TokenNameLPAREN : + case TokenNameLBRACE : + if (this.currentToken == TokenNameIdentifier) { + this.removePotentialNamesAt(this.currentTokenStart); + + } + break; + } + } + this.currentToken = nextToken; + this.currentTokenStart = this.startPosition; + return nextToken; +} +private int getNextToken0() throws InvalidInputException { this.wasAcr = false; this.unicodeCharSize = 0; @@ -807,6 +860,17 @@ throw new InvalidCursorLocation(InvalidCursorLocation.NO_COMPLETION_INSIDE_UNICODE); } } +public final void jumpOverBlock() { + this.jumpOverMethodBody(); +} +public void removePotentialNamesAt(int position) { + for (int i = 0; i <= this.potentialVariableNamesPtr; i++) { + int namePosition = this.potentialVariableNameStarts[i]; + if (namePosition == position) { + this.potentialVariableNames[i] = null; + } + } +} ///* // * In case we actually read a keyword, but the cursor is located inside, // * we pretend we read an identifier. @@ -834,4 +898,15 @@ } return token; } + +public void startRecordingIdentifiers() { + this.record = true; + + this.potentialVariableNamesPtr = -1; + this.potentialVariableNames = new char[10][]; + this.potentialVariableNameStarts = new int[10]; +} +public void stopRecordingIdentifiers() { + this.record = true; +} } 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.160 diff -u -r1.160 CompletionParser.java --- codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 12 Oct 2006 14:00:59 -0000 1.160 +++ codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 19 Oct 2006 14:12:30 -0000 @@ -73,6 +73,7 @@ protected static final int K_LABEL = COMPLETION_PARSER + 36; public final static char[] FAKE_TYPE_NAME = new char[]{' '}; + public final static char[] FAKE_METHOD_NAME = new char[]{' '}; public final static char[] VALUE = new char[]{'v', 'a', 'l', 'u', 'e'}; /* public fields */ @@ -3601,6 +3602,49 @@ canBeExplicitConstructor = 1; super.parseBlockStatements(cd, unit); } +public MethodDeclaration parseStatementsAfterCompletion(int start, int end, CompilationUnitDeclaration unit) { + this.methodRecoveryActivated = true; + + initialize(); + + // simulate goForMethodBody except that we don't want to balance brackets because they are not going to be balanced + goForBlockStatementsopt(); + + MethodDeclaration fakeMethod = new MethodDeclaration(unit.compilationResult()); + fakeMethod.selector = FAKE_METHOD_NAME; + fakeMethod.bodyStart = start; + fakeMethod.bodyEnd = end; + fakeMethod.declarationSourceStart = start; + fakeMethod.declarationSourceEnd = end; + fakeMethod.sourceStart = start; + fakeMethod.sourceEnd = start; //fake method must ignore the method header + + referenceContext = fakeMethod; + compilationUnit = unit; + + scanner.resetTo(start, end); + consumeNestedMethod(); + try { + parse(); + } catch (AbortCompilation ex) { + lastAct = ERROR_ACTION; + } finally { + nestedMethod[nestedType]--; + } + if (!this.hasError) { + int length; + if (astLengthPtr > -1 && (length = this.astLengthStack[this.astLengthPtr--]) != 0) { + System.arraycopy( + this.astStack, + (this.astPtr -= length) + 1, + fakeMethod.statements = new Statement[length], + 0, + length); + } + } + + return fakeMethod; +} /* * Prepares the state of the parser to go for BlockStatements. */ Index: codeassist/org/eclipse/jdt/internal/codeassist/UnresolvedReferenceNameFinder.java =================================================================== RCS file: codeassist/org/eclipse/jdt/internal/codeassist/UnresolvedReferenceNameFinder.java diff -N codeassist/org/eclipse/jdt/internal/codeassist/UnresolvedReferenceNameFinder.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ codeassist/org/eclipse/jdt/internal/codeassist/UnresolvedReferenceNameFinder.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,302 @@ +/******************************************************************************* + * Copyright (c) 2006 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 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.codeassist; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.codeassist.complete.CompletionParser; +import org.eclipse.jdt.internal.codeassist.complete.CompletionScanner; +import org.eclipse.jdt.internal.compiler.ASTVisitor; +import org.eclipse.jdt.internal.compiler.ast.ASTNode; +import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.Argument; +import org.eclipse.jdt.internal.compiler.ast.Block; +import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration; +import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; +import org.eclipse.jdt.internal.compiler.ast.Initializer; +import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; +import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.Statement; +import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.lookup.BlockScope; +import org.eclipse.jdt.internal.compiler.lookup.ClassScope; +import org.eclipse.jdt.internal.compiler.lookup.MethodScope; +import org.eclipse.jdt.internal.compiler.lookup.Scope; +import org.eclipse.jdt.internal.compiler.util.SimpleSet; + +public class UnresolvedReferenceNameFinder extends ASTVisitor { + public static interface UnresolvedReferenceNameRequestor { + public void acceptName(char[] name); + } + + private UnresolvedReferenceNameRequestor requestor; + + private CompletionParser parser; + private CompletionScanner completionScanner; + + private int parentsPtr; + private ASTNode[] parentsz; + + private int potentialVariableNamesPtr; + private char[][] potentialVariableNames; + private int[] potentialVariableNameStarts; + + private SimpleSet acceptedNames = new SimpleSet(); + + public UnresolvedReferenceNameFinder(CompletionEngine completionEngine) { + this.parser = completionEngine.parser; + this.completionScanner = (CompletionScanner) parser.scanner; + } + + private void acceptName(char[] name) { + if (acceptedNames.includes(name)) return; + + this.acceptedNames.add(name); + + // accept result + this.requestor.acceptName(name); + } + + public void find(char[] startWith, Initializer initializer, ClassScope scope, int from, UnresolvedReferenceNameRequestor nameRequestor) { + MethodDeclaration fakeMethod = this.find(startWith, scope, from, initializer.bodyEnd, nameRequestor); + fakeMethod.traverse(this, scope); + } + + public void find(char[] startWith, AbstractMethodDeclaration methodDeclaration, int from, UnresolvedReferenceNameRequestor nameRequestor) { + MethodDeclaration fakeMethod = this.find(startWith, methodDeclaration.scope, from, methodDeclaration.bodyEnd, nameRequestor); + fakeMethod.traverse(this, methodDeclaration.scope.classScope()); + } + + private MethodDeclaration find(char[] startWith, Scope s, int from, int to, UnresolvedReferenceNameRequestor nameRequestor) { + this.requestor = nameRequestor; + + // reinitialize completion scanner to be usable as a normal scanner + this.completionScanner.cursorLocation = 0; + + // reinitialize completionIdentifier + this.completionScanner.prefix = startWith; + + // compute location of the end of the current block + this.completionScanner.resetTo(from + 1, to); + this.completionScanner.jumpOverBlock(); + + this.completionScanner.startRecordingIdentifiers(); + + MethodDeclaration fakeMethod = this.parser.parseStatementsAfterCompletion( + from, + this.completionScanner.startPosition - 1, + s.compilationUnitScope().referenceContext); + + this.completionScanner.stopRecordingIdentifiers(); + + this.potentialVariableNames = this.completionScanner.potentialVariableNames; + this.potentialVariableNameStarts = this.completionScanner.potentialVariableNameStarts; + this.potentialVariableNamesPtr = this.completionScanner.potentialVariableNamesPtr; + + this.parentsPtr = -1; + this.parentsz = new ASTNode[10]; + + return fakeMethod; + } + + private void popParent() { + this.parentsPtr--; + } + private void pushParent(ASTNode parent) { + int length = this.parentsz.length; + if (this.parentsPtr >= length - 1) { + System.arraycopy(this.parentsz, 0, this.parentsz = new ASTNode[length * 2], 0, length); + } + this.parentsz[++this.parentsPtr] = parent; + } + + private ASTNode getEnclosingDeclaration() { + int i = this.parentsPtr; + while (i > -1) { + ASTNode parent = parentsz[i]; + if (parent instanceof AbstractMethodDeclaration) { + return parent; + } else if (parent instanceof Initializer) { + return parent; + } else if (parent instanceof FieldDeclaration) { + return parent; + } else if (parent instanceof TypeDeclaration) { + return parent; + } + i--; + } + return null; + } + + public boolean visit(Block block, BlockScope blockScope) { + pushParent(block); + return true; + } + + public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope classScope) { + pushParent(constructorDeclaration); + return true; + } + + public boolean visit(FieldDeclaration fieldDeclaration, MethodScope methodScope) { + pushParent(fieldDeclaration); + return true; + } + + public boolean visit(Initializer initializer, MethodScope methodScope) { + pushParent(initializer); + return true; + } + + public boolean visit(MethodDeclaration methodDeclaration, ClassScope classScope) { + pushParent(methodDeclaration); + return true; + } + + public boolean visit(TypeDeclaration localTypeDeclaration, BlockScope blockScope) { + removeFields(localTypeDeclaration); + pushParent(localTypeDeclaration); + return true; + } + + public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope classScope) { + removeFields(memberTypeDeclaration); + pushParent(memberTypeDeclaration); + return true; + } + + public void endVisit(Block block, BlockScope blockScope) { + ASTNode enclosingDeclaration = getEnclosingDeclaration(); + removeLocals(block.statements, enclosingDeclaration.sourceStart, block.sourceEnd); + popParent(); + } + + public void endVisit(Argument argument, BlockScope blockScope) { + endVisitRemoved(argument.declarationSourceStart, argument.sourceEnd); + } + + public void endVisit(Argument argument, ClassScope classScope) { + endVisitRemoved(argument.declarationSourceStart, argument.sourceEnd); + } + + public void endVisit(ConstructorDeclaration constructorDeclaration, ClassScope classScope) { + if (!constructorDeclaration.isDefaultConstructor && !constructorDeclaration.isClinit()) { + endVisitPreserved(constructorDeclaration.bodyStart, constructorDeclaration.bodyEnd); + } + popParent(); + } + + public void endVisit(FieldDeclaration fieldDeclaration, MethodScope methodScope) { + endVisitRemoved(fieldDeclaration.declarationSourceStart, fieldDeclaration.sourceEnd); + endVisitPreserved(fieldDeclaration.sourceEnd, fieldDeclaration.declarationEnd); + popParent(); + } + + public void endVisit(Initializer initializer, MethodScope methodScope) { + endVisitPreserved(initializer.bodyStart, initializer.bodyEnd); + popParent(); + } + + public void endVisit(LocalDeclaration localDeclaration, BlockScope blockScope) { + endVisitRemoved(localDeclaration.declarationSourceStart, localDeclaration.sourceEnd); + } + + public void endVisit(MethodDeclaration methodDeclaration, ClassScope classScope) { + removeLocals( + methodDeclaration.arguments, + methodDeclaration.declarationSourceStart, + methodDeclaration.declarationSourceEnd); + removeLocals( + methodDeclaration.statements, + methodDeclaration.declarationSourceStart, + methodDeclaration.declarationSourceEnd); + endVisitPreserved( + methodDeclaration.bodyStart, + methodDeclaration.bodyEnd); + popParent(); + } + + public void endVisit(TypeDeclaration typeDeclaration, BlockScope blockScope) { + removeFields(typeDeclaration); + endVisitRemoved(typeDeclaration.sourceStart, typeDeclaration.declarationSourceEnd); + popParent(); + } + + public void endVisit(TypeDeclaration typeDeclaration, ClassScope classScope) { + endVisitRemoved(typeDeclaration.sourceStart, typeDeclaration.declarationSourceEnd); + popParent(); + } + + private void endVisitPreserved(int start, int end) { + for (int i = 0; i <= this.potentialVariableNamesPtr; i++) { + char[] name = this.potentialVariableNames[i]; + if (name != null) { + int nameStart = this.potentialVariableNameStarts[i]; + if (start < nameStart && nameStart < end) { + this.potentialVariableNames[i] = null; + this.acceptName(name); + } + } + } + } + + private void endVisitRemoved(int start, int end) { + for (int i = 0; i <= this.potentialVariableNamesPtr; i++) { + if (this.potentialVariableNames[i] != null) { + int nameStart = this.potentialVariableNameStarts[i]; + if (start < nameStart && nameStart < end) { + this.potentialVariableNames[i] = null; + } + } + } + } + + private void removeLocals(Statement[] statements, int start, int end) { + if (statements != null) { + for (int i = 0; i < statements.length; i++) { + if (statements[i] instanceof LocalDeclaration) { + LocalDeclaration localDeclaration = (LocalDeclaration) statements[i]; + for (int j = 0; j <= this.potentialVariableNamesPtr; j++) { + char[] name = this.potentialVariableNames[j]; + if (name != null) { + int nameStart = this.potentialVariableNameStarts[j]; + if(start <= nameStart && nameStart <= end) { + if (CharOperation.equals(name, localDeclaration.name, false)) { + this.potentialVariableNames[j] = null; + } + } + } + } + } + } + + } + } + + private void removeFields(TypeDeclaration typeDeclaration) { + FieldDeclaration[] fieldDeclarations = typeDeclaration.fields; + if (fieldDeclarations != null) { + for (int i = 0; i < fieldDeclarations.length; i++) { + for (int j = 0; j <= this.potentialVariableNamesPtr; j++) { + char[] name = this.potentialVariableNames[j]; + if (name != null) { + int nameStart = this.potentialVariableNameStarts[j]; + if(typeDeclaration.declarationSourceStart <= nameStart && + nameStart <= typeDeclaration.declarationSourceEnd) { + if (CharOperation.equals(name, fieldDeclarations[i].name, false)) { + this.potentialVariableNames[j] = null; + } + } + } + } + } + } + } +} #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.131 diff -u -r1.131 CompletionTests.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests.java 12 Oct 2006 09:22:02 -0000 1.131 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests.java 19 Oct 2006 14:12:50 -0000 @@ -9990,6 +9990,478 @@ JavaCore.setOptions(options); } } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 +public void testCompletionVariableName16() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "public class Test {\n"+ + " void foo(){\n"+ + " Object ;\n"+ + " foo = null;\n"+ + " }\n"+ + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "Object "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "object[VARIABLE_DECLARATION]{object, null, Ljava.lang.Object;, object, null, "+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo[VARIABLE_DECLARATION]{foo, null, Ljava.lang.Object;, foo, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 +public void testCompletionVariableName17() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "public class Test {\n"+ + " void foo(){\n"+ + " Object foo1;\n"+ + " /*here*/Object ;\n"+ + " Object foo3;\n"+ + " foo1 = null;\n"+ + " foo2 = null;\n"+ + " foo3 = null;\n"+ + " }\n"+ + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "/*here*/Object "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "object[VARIABLE_DECLARATION]{object, null, Ljava.lang.Object;, object, null, "+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo2[VARIABLE_DECLARATION]{foo2, null, Ljava.lang.Object;, foo2, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 +public void testCompletionVariableName18() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "public class Test {\n"+ + " void foo(){\n"+ + " Object ;\n"+ + " foo = Test.class;\n"+ + " }\n"+ + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "Object "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "object[VARIABLE_DECLARATION]{object, null, Ljava.lang.Object;, object, null, "+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo[VARIABLE_DECLARATION]{foo, null, Ljava.lang.Object;, foo, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 +public void testCompletionVariableName19() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "public class Test {\n"+ + " void foo(){\n"+ + " Object ;\n"+ + " object = null;\n"+ + " }\n"+ + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "Object "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "object[VARIABLE_DECLARATION]{object, null, Ljava.lang.Object;, object, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 +public void testCompletionVariableName20() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "public class Test {\n"+ + " void foo(){\n"+ + " /*here*/Object ;\n"+ + " class X {\n"+ + " Object foo1 = foo2;\n"+ + " void bar() {\n"+ + " foo1 = null;\n"+ + " Object foo3 = foo4;\n"+ + " foo3 = null;\n"+ + " }\n"+ + " }\n"+ + " foo5 = null;\n"+ + " }\n"+ + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "/*here*/Object "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "object[VARIABLE_DECLARATION]{object, null, Ljava.lang.Object;, object, null, "+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo2[VARIABLE_DECLARATION]{foo2, null, Ljava.lang.Object;, foo2, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo4[VARIABLE_DECLARATION]{foo4, null, Ljava.lang.Object;, foo4, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo5[VARIABLE_DECLARATION]{foo5, null, Ljava.lang.Object;, foo5, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 +public void testCompletionVariableName21() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "public class Test {\n"+ + " void foo(){\n"+ + " {\n"+ + " /*here*/Object ;\n"+ + " foo1 = null;\n"+ + " }\n"+ + " foo2 = null;\n"+ + " }\n"+ + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "/*here*/Object "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "object[VARIABLE_DECLARATION]{object, null, Ljava.lang.Object;, object, null, "+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo1[VARIABLE_DECLARATION]{foo1, null, Ljava.lang.Object;, foo1, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 +public void testCompletionVariableName22() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "public class Test {\n"+ + " void foo(){\n"+ + " Object foo1;\n"+ + " /*here*/Object ;\n"+ + " {\n"+ + " Object foo3;\n"+ + " foo1 = null;\n"+ + " foo2 = null;\n"+ + " foo3 = null;\n"+ + " }\n"+ + " }\n"+ + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "/*here*/Object "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "object[VARIABLE_DECLARATION]{object, null, Ljava.lang.Object;, object, null, "+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo2[VARIABLE_DECLARATION]{foo2, null, Ljava.lang.Object;, foo2, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 +public void testCompletionVariableName23() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "public class Test {\n"+ + " void foo(){\n"+ + " /*here*/Object ;\n"+ + " foo1 = null;\n"+ + " #\n"+ + " }\n"+ + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "/*here*/Object "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "object[VARIABLE_DECLARATION]{object, null, Ljava.lang.Object;, object, null, "+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo1[VARIABLE_DECLARATION]{foo1, null, Ljava.lang.Object;, foo1, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 +public void testCompletionVariableName24() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "public class Test {\n"+ + " void foo(){\n"+ + " /*here*/Object ;\n"+ + " #\n"+ + " foo1 = null;\n"+ + " }\n"+ + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "/*here*/Object "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "object[VARIABLE_DECLARATION]{object, null, Ljava.lang.Object;, object, null, "+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo1[VARIABLE_DECLARATION]{foo1, null, Ljava.lang.Object;, foo1, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 +public void testCompletionVariableName25() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "public class Test {\n"+ + " void foo(){\n"+ + " /*here*/Object ;\n"+ + " #\n"+ + " foo1 = null;\n"+ + " #\n"+ + " foo2 = null;\n"+ + " }\n"+ + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "/*here*/Object "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "object[VARIABLE_DECLARATION]{object, null, Ljava.lang.Object;, object, null, "+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo1[VARIABLE_DECLARATION]{foo1, null, Ljava.lang.Object;, foo1, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo2[VARIABLE_DECLARATION]{foo2, null, Ljava.lang.Object;, foo2, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 +public void testCompletionVariableName26() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "public class Test {\n"+ + " void foo(){\n"+ + " /*here*/Object ;\n"+ + " #\n"+ + " foo1 = null;\n"+ + " #\n"+ + " foo2 = null;\n"+ + " #\n"+ + " }\n"+ + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "/*here*/Object "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "object[VARIABLE_DECLARATION]{object, null, Ljava.lang.Object;, object, null, "+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo1[VARIABLE_DECLARATION]{foo1, null, Ljava.lang.Object;, foo1, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo2[VARIABLE_DECLARATION]{foo2, null, Ljava.lang.Object;, foo2, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 +public void testCompletionVariableName27() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "public class Test {\n"+ + " void foo(){\n"+ + " /*here*/Object ;\n"+ + " Object foo0 = null;\n"+ + " foo0 = null;\n"+ + " #\n"+ + " class X {\n"+ + " Object foo1 = foo2;\n"+ + " void bar() {\n"+ + " foo1 = null;\n"+ + " Object foo3 = foo4;\n"+ + " foo3 = null;\n"+ + " }\n"+ + " }\n"+ + " foo5 = null;\n"+ + " }\n"+ + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "/*here*/Object "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "object[VARIABLE_DECLARATION]{object, null, Ljava.lang.Object;, object, null, "+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo2[VARIABLE_DECLARATION]{foo2, null, Ljava.lang.Object;, foo2, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo4[VARIABLE_DECLARATION]{foo4, null, Ljava.lang.Object;, foo4, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo5[VARIABLE_DECLARATION]{foo5, null, Ljava.lang.Object;, foo5, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 +public void testCompletionVariableName28() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "public class Test {\n"+ + " void foo(){\n"+ + " /*here*/Object ;\n"+ + " Object foo1 = null;\n"+ + " foo1.foo2 = null;\n"+ + " foo3.foo4 = null;\n"+ + " }\n"+ + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "/*here*/Object "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "object[VARIABLE_DECLARATION]{object, null, Ljava.lang.Object;, object, null, "+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo3[VARIABLE_DECLARATION]{foo3, null, Ljava.lang.Object;, foo3, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 +public void testCompletionVariableName29() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "public class Test {\n"+ + " void foo(){\n"+ + " /*here*/Object ;\n"+ + " class X {\n"+ + " void bar1() {\n"+ + " var1 = null;\n"+ + " }\n"+ + " void bar2() {\n"+ + " Object var2 = null;\n"+ + " var2 = null;\n"+ + " }\n"+ + " void bar3() {\n"+ + " Object var3 = null;\n"+ + " {\n"+ + " var3 = null;\n"+ + " Object var4 = null;\n"+ + " }\n"+ + " var4 = null;\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "/*here*/Object "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "object[VARIABLE_DECLARATION]{object, null, Ljava.lang.Object;, object, null, "+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "var1[VARIABLE_DECLARATION]{var1, null, Ljava.lang.Object;, var1, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "var4[VARIABLE_DECLARATION]{var4, null, Ljava.lang.Object;, var4, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 +public void testCompletionVariableName30() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "public class Test {\n"+ + " public Test(){\n"+ + " Object ;\n"+ + " foo = null;\n"+ + " }\n"+ + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "Object "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "object[VARIABLE_DECLARATION]{object, null, Ljava.lang.Object;, object, null, "+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo[VARIABLE_DECLARATION]{foo, null, Ljava.lang.Object;, foo, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 +public void testCompletionVariableName31() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "public class Test {\n"+ + " {\n"+ + " Object ;\n"+ + " foo = null;\n"+ + " }\n"+ + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "Object "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "object[VARIABLE_DECLARATION]{object, null, Ljava.lang.Object;, object, null, "+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo[VARIABLE_DECLARATION]{foo, null, Ljava.lang.Object;, foo, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 +public void testCompletionVariableName32() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "public class Test {\n"+ + " void bar(Object ) {\n"+ + " foo = null;\n"+ + " }\n"+ + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "Object "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "object[VARIABLE_DECLARATION]{object, null, Ljava.lang.Object;, object, null, "+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}\n"+ + "foo[VARIABLE_DECLARATION]{foo, null, Ljava.lang.Object;, foo, null, "+(R_DEFAULT + R_INTERESTING + R_NAME_FIRST_SUFFIX + R_NAME_FIRST_PREFIX + R_NAME_LESS_NEW_CHARACTERS + R_CASE + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} public void testCompletionNonEmptyToken1() throws JavaModelException { CompletionTestsRequestor requestor = new CompletionTestsRequestor(); ICompilationUnit cu= getCompilationUnit("Completion", "src", "", "CompletionNonEmptyToken1.java");