View | Details | Raw Unified | Return to bug 202470 | Differences between
and this patch

Collapse All | Expand All

(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java (-3 / +81 lines)
Lines 26-31 Link Here
26
import org.eclipse.jdt.internal.compiler.ast.*;
26
import org.eclipse.jdt.internal.compiler.ast.*;
27
import org.eclipse.jdt.internal.compiler.parser.*;
27
import org.eclipse.jdt.internal.compiler.parser.*;
28
import org.eclipse.jdt.internal.compiler.problem.*;
28
import org.eclipse.jdt.internal.compiler.problem.*;
29
import org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToInt;
29
import org.eclipse.jdt.internal.compiler.util.Util;
30
import org.eclipse.jdt.internal.compiler.util.Util;
30
import org.eclipse.jdt.core.compiler.CharOperation;
31
import org.eclipse.jdt.core.compiler.CharOperation;
31
import org.eclipse.jdt.internal.codeassist.impl.*;
32
import org.eclipse.jdt.internal.codeassist.impl.*;
Lines 160-169 Link Here
160
	
161
	
161
	CompletionOnAnnotationOfType pendingAnnotation;
162
	CompletionOnAnnotationOfType pendingAnnotation;
162
	
163
	
163
public CompletionParser(ProblemReporter problemReporter) {
164
	private boolean storeSourceEnds;
165
	public HashtableOfObjectToInt sourceEnds;
166
	
167
public CompletionParser(ProblemReporter problemReporter, boolean storeExtraSourceEnds) {
164
	super(problemReporter);
168
	super(problemReporter);
165
	this.reportSyntaxErrorIsRequired = false;
169
	this.reportSyntaxErrorIsRequired = false;
166
	this.javadocParser.checkDocComment = true;
170
	this.javadocParser.checkDocComment = true;
171
	if (storeExtraSourceEnds) {
172
		this.storeSourceEnds = true;
173
		this.sourceEnds = new HashtableOfObjectToInt();
174
	}
167
}
175
}
168
private void addPotentialName(char[] potentialVariableName, int start, int end) {
176
private void addPotentialName(char[] potentialVariableName, int start, int end) {
169
	int length = this.potentialVariableNames.length;
177
	int length = this.potentialVariableNames.length;
Lines 2118-2123 Link Here
2118
2126
2119
	/* no need to take action if not inside assist identifiers */
2127
	/* no need to take action if not inside assist identifiers */
2120
	if (indexOfAssistIdentifier() < 0) {
2128
	if (indexOfAssistIdentifier() < 0) {
2129
		long selectorSourcePositions = this.identifierPositionStack[this.identifierPtr];
2130
		int selectorSourceEnd = (int) selectorSourcePositions;
2131
		int currentAstPtr = this.astPtr;
2121
		/* recovering - might be an empty message send */
2132
		/* recovering - might be an empty message send */
2122
		if (this.currentElement != null && this.lastIgnoredToken == TokenNamenew){ // was an allocation expression
2133
		if (this.currentElement != null && this.lastIgnoredToken == TokenNamenew){ // was an allocation expression
2123
			super.consumeConstructorHeaderName();
2134
			super.consumeConstructorHeaderName();
Lines 2128-2133 Link Here
2128
				this.pendingAnnotation = null;
2139
				this.pendingAnnotation = null;
2129
			}
2140
			}
2130
		}
2141
		}
2142
		if (this.sourceEnds != null && this.astPtr > currentAstPtr) { // if ast node was pushed on the ast stack
2143
			this.sourceEnds.put(this.astStack[this.astPtr], selectorSourceEnd);
2144
		}
2131
		return;
2145
		return;
2132
	}
2146
	}
2133
2147
Lines 2140-2145 Link Here
2140
	this.restartRecovery = true;
2154
	this.restartRecovery = true;
2141
}
2155
}
2142
protected void consumeConstructorHeaderNameWithTypeParameters() {
2156
protected void consumeConstructorHeaderNameWithTypeParameters() {
2157
	long selectorSourcePositions = this.identifierPositionStack[this.identifierPtr];
2158
	int selectorSourceEnd = (int) selectorSourcePositions;
2159
	int currentAstPtr = this.astPtr;
2143
	if (this.currentElement != null && this.lastIgnoredToken == TokenNamenew){ // was an allocation expression
2160
	if (this.currentElement != null && this.lastIgnoredToken == TokenNamenew){ // was an allocation expression
2144
		super.consumeConstructorHeaderNameWithTypeParameters();
2161
		super.consumeConstructorHeaderNameWithTypeParameters();
2145
	} else {
2162
	} else {
Lines 2149-2154 Link Here
2149
			this.pendingAnnotation = null;
2166
			this.pendingAnnotation = null;
2150
		}
2167
		}
2151
	}
2168
	}
2169
	if (this.sourceEnds != null && this.astPtr > currentAstPtr) { // if ast node was pushed on the ast stack
2170
		this.sourceEnds.put(this.astStack[this.astPtr], selectorSourceEnd);
2171
	}
2152
}
2172
}
2153
protected void consumeDefaultLabel() {
2173
protected void consumeDefaultLabel() {
2154
	super.consumeDefaultLabel();
2174
	super.consumeDefaultLabel();
Lines 2269-2274 Link Here
2269
		this.pendingAnnotation = null;
2289
		this.pendingAnnotation = null;
2270
	}
2290
	}
2271
}
2291
}
2292
protected void consumeEnumConstantNoClassBody() {
2293
	super.consumeEnumConstantNoClassBody();
2294
	if ((currentToken == TokenNameCOMMA || currentToken == TokenNameSEMICOLON)
2295
			&& this.astStack[this.astPtr] instanceof FieldDeclaration) {
2296
		if (this.sourceEnds != null) {
2297
			this.sourceEnds.put(this.astStack[this.astPtr], this.scanner.currentPosition - 1);
2298
		}
2299
	}
2300
}
2301
protected void consumeEnumConstantWithClassBody() {
2302
	super.consumeEnumConstantWithClassBody();
2303
	if ((currentToken == TokenNameCOMMA || currentToken == TokenNameSEMICOLON)
2304
			&& astStack[astPtr] instanceof FieldDeclaration) {
2305
		if (this.sourceEnds != null) {
2306
			this.sourceEnds.put(this.astStack[this.astPtr], this.scanner.currentPosition - 1);
2307
		}
2308
	}
2309
}
2272
protected void consumeEnumHeaderName() {
2310
protected void consumeEnumHeaderName() {
2273
	super.consumeEnumHeaderName();
2311
	super.consumeEnumHeaderName();
2274
	this.hasUnusedModifiers = false;
2312
	this.hasUnusedModifiers = false;
Lines 2304-2310 Link Here
2304
}
2342
}
2305
protected void consumeExitVariableWithInitialization() {
2343
protected void consumeExitVariableWithInitialization() {
2306
	super.consumeExitVariableWithInitialization();
2344
	super.consumeExitVariableWithInitialization();
2307
2345
	if ((currentToken == TokenNameCOMMA || currentToken == TokenNameSEMICOLON)
2346
			&& this.astStack[this.astPtr] instanceof FieldDeclaration) {
2347
		if (this.sourceEnds != null) {
2348
			this.sourceEnds.put(this.astStack[this.astPtr], this.scanner.currentPosition - 1);
2349
		}
2350
	}
2351
	
2308
	// does not keep the initialization if completion is not inside
2352
	// does not keep the initialization if completion is not inside
2309
	AbstractVariableDeclaration variable = (AbstractVariableDeclaration) astStack[astPtr];
2353
	AbstractVariableDeclaration variable = (AbstractVariableDeclaration) astStack[astPtr];
2310
	if (cursorLocation + 1 < variable.initialization.sourceStart ||
2354
	if (cursorLocation + 1 < variable.initialization.sourceStart ||
Lines 2314-2319 Link Here
2314
		assistNodeParent = variable;
2358
		assistNodeParent = variable;
2315
	}
2359
	}
2316
}
2360
}
2361
protected void consumeExitVariableWithoutInitialization() {
2362
	// ExitVariableWithoutInitialization ::= $empty
2363
	// do nothing by default
2364
	super.consumeExitVariableWithoutInitialization();
2365
	if ((currentToken == TokenNameCOMMA || currentToken == TokenNameSEMICOLON)
2366
			&& astStack[astPtr] instanceof FieldDeclaration) {
2367
		if (this.sourceEnds != null) {
2368
			this.sourceEnds.put(this.astStack[this.astPtr], this.scanner.currentPosition - 1);
2369
		}
2370
	}
2371
}
2317
protected void consumeExplicitConstructorInvocation(int flag, int recFlag) {
2372
protected void consumeExplicitConstructorInvocation(int flag, int recFlag) {
2318
	popElement(K_SELECTOR_QUALIFIER);
2373
	popElement(K_SELECTOR_QUALIFIER);
2319
	popElement(K_SELECTOR_INVOCATION_TYPE);
2374
	popElement(K_SELECTOR_INVOCATION_TYPE);
Lines 2561-2567 Link Here
2561
			this.identifierLengthStack[this.identifierLengthPtr] != this.genericsIdentifiersLengthStack[this.genericsIdentifiersLengthPtr]) {
2616
			this.identifierLengthStack[this.identifierLengthPtr] != this.genericsIdentifiersLengthStack[this.genericsIdentifiersLengthPtr]) {
2562
			identifierPtr++;
2617
			identifierPtr++;
2563
			identifierLengthPtr++;
2618
			identifierLengthPtr++;
2619
			long selectorSourcePositions = this.identifierPositionStack[this.identifierPtr];
2620
			int selectorSourceEnd = (int) selectorSourcePositions;
2621
			int currentAstPtr = this.astPtr;
2564
			super.consumeMethodHeaderName(isAnnotationMethod);
2622
			super.consumeMethodHeaderName(isAnnotationMethod);
2623
			if (this.sourceEnds != null && this.astPtr > currentAstPtr) { // if ast node was pushed on the ast stack
2624
				this.sourceEnds.put(this.astStack[this.astPtr], selectorSourceEnd);
2625
			}
2565
			if (this.pendingAnnotation != null) {
2626
			if (this.pendingAnnotation != null) {
2566
				this.pendingAnnotation.potentialAnnotatedNode = this.astStack[this.astPtr];
2627
				this.pendingAnnotation.potentialAnnotatedNode = this.astStack[this.astPtr];
2567
				this.pendingAnnotation = null;
2628
				this.pendingAnnotation = null;
Lines 2681-2687 Link Here
2681
	}
2742
	}
2682
}
2743
}
2683
protected void consumeMethodHeaderNameWithTypeParameters( boolean isAnnotationMethod) {
2744
protected void consumeMethodHeaderNameWithTypeParameters( boolean isAnnotationMethod) {
2745
	long selectorSourcePositions = this.identifierPositionStack[this.identifierPtr];
2746
	int selectorSourceEnd = (int) selectorSourcePositions;
2747
	int currentAstPtr = this.astPtr;
2684
	super.consumeMethodHeaderNameWithTypeParameters(isAnnotationMethod);
2748
	super.consumeMethodHeaderNameWithTypeParameters(isAnnotationMethod);
2749
	if (this.sourceEnds != null && this.astPtr > currentAstPtr) {// if ast node was pushed on the ast stack
2750
		this.sourceEnds.put(this.astStack[this.astPtr], selectorSourceEnd);
2751
	}
2685
	if (this.pendingAnnotation != null) {
2752
	if (this.pendingAnnotation != null) {
2686
		this.pendingAnnotation.potentialAnnotatedNode = this.astStack[this.astPtr];
2753
		this.pendingAnnotation.potentialAnnotatedNode = this.astStack[this.astPtr];
2687
		this.pendingAnnotation = null;
2754
		this.pendingAnnotation = null;
Lines 3730-3736 Link Here
3730
		}
3797
		}
3731
	}
3798
	}
3732
}
3799
}
3733
3800
public MethodDeclaration convertToMethodDeclaration(ConstructorDeclaration c, CompilationResult compilationResult) {
3801
	MethodDeclaration methodDeclaration = super.convertToMethodDeclaration(c, compilationResult);
3802
	if (this.sourceEnds != null) {
3803
		int selectorSourceEnd = this.sourceEnds.removeKey(c);
3804
		if (selectorSourceEnd != -1)
3805
			this.sourceEnds.put(methodDeclaration, selectorSourceEnd);
3806
	}
3807
	return methodDeclaration;
3808
}
3734
public ImportReference createAssistImportReference(char[][] tokens, long[] positions, int mod){
3809
public ImportReference createAssistImportReference(char[][] tokens, long[] positions, int mod){
3735
	return new CompletionOnImportReference(tokens, positions, mod);
3810
	return new CompletionOnImportReference(tokens, positions, mod);
3736
}
3811
}
Lines 4420-4425 Link Here
4420
public void reset() {
4495
public void reset() {
4421
	super.reset();
4496
	super.reset();
4422
	this.cursorLocation = 0;
4497
	this.cursorLocation = 0;
4498
	if (this.storeSourceEnds) {
4499
		this.sourceEnds = new HashtableOfObjectToInt();
4500
	}
4423
}
4501
}
4424
/*
4502
/*
4425
 * Reset internal state after completion is over
4503
 * Reset internal state after completion is over
(-)dom/org/eclipse/jdt/core/dom/TypeBinding.java (-187 / +7 lines)
Lines 11-37 Link Here
11
11
12
package org.eclipse.jdt.core.dom;
12
package org.eclipse.jdt.core.dom;
13
13
14
import java.io.File;
15
16
import org.eclipse.core.resources.IContainer;
17
import org.eclipse.core.resources.IWorkspaceRoot;
18
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.runtime.Path;
20
import org.eclipse.jdt.core.IClassFile;
21
import org.eclipse.jdt.core.ICompilationUnit;
22
import org.eclipse.jdt.core.IJavaElement;
14
import org.eclipse.jdt.core.IJavaElement;
23
import org.eclipse.jdt.core.IJavaProject;
24
import org.eclipse.jdt.core.IMethod;
25
import org.eclipse.jdt.core.IPackageFragment;
26
import org.eclipse.jdt.core.IPackageFragmentRoot;
27
import org.eclipse.jdt.core.IType;
28
import org.eclipse.jdt.core.JavaCore;
29
import org.eclipse.jdt.core.JavaModelException;
15
import org.eclipse.jdt.core.JavaModelException;
30
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.core.compiler.CharOperation;
31
import org.eclipse.jdt.internal.compiler.ast.Expression;
17
import org.eclipse.jdt.internal.compiler.ast.Expression;
32
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
18
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
33
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
19
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
34
import org.eclipse.jdt.internal.compiler.env.IDependent;
35
import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
20
import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
36
import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding;
21
import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding;
37
import org.eclipse.jdt.internal.compiler.lookup.Binding;
22
import org.eclipse.jdt.internal.compiler.lookup.Binding;
Lines 49-57 Link Here
49
import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;
34
import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;
50
import org.eclipse.jdt.internal.compiler.lookup.WildcardBinding;
35
import org.eclipse.jdt.internal.compiler.lookup.WildcardBinding;
51
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
36
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
52
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
53
import org.eclipse.jdt.internal.compiler.util.Util;
54
import org.eclipse.jdt.internal.core.ClassFile;
55
import org.eclipse.jdt.internal.core.CompilationUnit;
37
import org.eclipse.jdt.internal.core.CompilationUnit;
56
import org.eclipse.jdt.internal.core.JavaElement;
38
import org.eclipse.jdt.internal.core.JavaElement;
57
import org.eclipse.jdt.internal.core.PackageFragment;
39
import org.eclipse.jdt.internal.core.PackageFragment;
Lines 184-229 Link Here
184
	}
166
	}
185
167
186
	/*
168
	/*
187
	 * Returns the class file for the given file name, or null if not found.
188
	 * @see org.eclipse.jdt.internal.compiler.env.IDependent#getFileName()
189
	 */
190
	private IClassFile getClassFile(char[] fileName) {
191
		int jarSeparator = CharOperation.indexOf(IDependent.JAR_FILE_ENTRY_SEPARATOR, fileName);
192
		int pkgEnd = CharOperation.lastIndexOf('/', fileName); // pkgEnd is exclusive
193
		if (pkgEnd == -1)
194
			pkgEnd = CharOperation.lastIndexOf(File.separatorChar, fileName);
195
		if (jarSeparator != -1 && pkgEnd < jarSeparator) // if in a jar and no slash, it is a default package -> pkgEnd should be equal to jarSeparator
196
			pkgEnd = jarSeparator;
197
		if (pkgEnd == -1)
198
			return null;
199
		IPackageFragment pkg = getPackageFragment(fileName, pkgEnd, jarSeparator);
200
		if (pkg == null) return null;
201
		int start;
202
		return pkg.getClassFile(new String(fileName, start = pkgEnd + 1, fileName.length - start));
203
	}
204
205
	/*
206
	 * Returns the compilation unit for the given file name, or null if not found.
207
	 * @see org.eclipse.jdt.internal.compiler.env.IDependent#getFileName()
208
	 */
209
	private ICompilationUnit getCompilationUnit(char[] fileName) {
210
		char[] slashSeparatedFileName = CharOperation.replaceOnCopy(fileName, File.separatorChar, '/');
211
		int pkgEnd = CharOperation.lastIndexOf('/', slashSeparatedFileName); // pkgEnd is exclusive
212
		if (pkgEnd == -1)
213
			return null;
214
		IPackageFragment pkg = getPackageFragment(slashSeparatedFileName, pkgEnd, -1/*no jar separator for .java files*/);
215
		if (pkg == null) return null;
216
		int start;
217
		ICompilationUnit cu = pkg.getCompilationUnit(new String(slashSeparatedFileName, start =  pkgEnd+1, slashSeparatedFileName.length - start));
218
		if (this.resolver instanceof DefaultBindingResolver) {
219
			ICompilationUnit workingCopy = cu.findWorkingCopy(((DefaultBindingResolver) this.resolver).workingCopyOwner);
220
			if (workingCopy != null)
221
				return workingCopy;
222
		}
223
		return cu;
224
	}
225
226
	/*
227
	 * @see ITypeBinding#getComponentType()
169
	 * @see ITypeBinding#getComponentType()
228
	 */
170
	 */
229
	public ITypeBinding getComponentType() {
171
	public ITypeBinding getComponentType() {
Lines 545-643 Link Here
545
		return getUnresolvedJavaElement(this.binding);
487
		return getUnresolvedJavaElement(this.binding);
546
	}
488
	}
547
	private JavaElement getUnresolvedJavaElement(org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding ) {
489
	private JavaElement getUnresolvedJavaElement(org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding ) {
548
		if (typeBinding == null)
490
		if (this.resolver instanceof DefaultBindingResolver) {
549
			return null;
491
			DefaultBindingResolver defaultBindingResolver = (DefaultBindingResolver) this.resolver;
550
		switch (typeBinding.kind()) {
492
			return org.eclipse.jdt.internal.core.util.Util.getUnresolvedJavaElement(
551
			case Binding.ARRAY_TYPE :
493
					typeBinding,
552
				typeBinding = ((ArrayBinding) typeBinding).leafComponentType();
494
					defaultBindingResolver.workingCopyOwner,
553
				return getUnresolvedJavaElement(typeBinding);
495
					defaultBindingResolver.getBindingsToNodesMap());
554
			case Binding.BASE_TYPE :
555
			case Binding.WILDCARD_TYPE :
556
			case Binding.INTERSECTION_TYPE:
557
				return null;
558
			default :
559
				if (typeBinding.isCapture())
560
					return null;
561
		}
562
		ReferenceBinding referenceBinding;
563
		if (typeBinding.isParameterizedType() || typeBinding.isRawType())
564
			referenceBinding = (ReferenceBinding) typeBinding.erasure();
565
		else
566
			referenceBinding = (ReferenceBinding) typeBinding;
567
		char[] fileName = referenceBinding.getFileName();
568
		if (referenceBinding.isLocalType() || referenceBinding.isAnonymousType()) {
569
			// local or anonymous type
570
			if (Util.isClassFileName(fileName)) {
571
				int jarSeparator = CharOperation.indexOf(IDependent.JAR_FILE_ENTRY_SEPARATOR, fileName);
572
				int pkgEnd = CharOperation.lastIndexOf('/', fileName); // pkgEnd is exclusive
573
				if (pkgEnd == -1)
574
					pkgEnd = CharOperation.lastIndexOf(File.separatorChar, fileName);
575
				if (jarSeparator != -1 && pkgEnd < jarSeparator) // if in a jar and no slash, it is a default package -> pkgEnd should be equal to jarSeparator
576
					pkgEnd = jarSeparator;
577
				if (pkgEnd == -1)
578
					return null;
579
				IPackageFragment pkg = getPackageFragment(fileName, pkgEnd, jarSeparator);
580
				char[] constantPoolName = referenceBinding.constantPoolName();
581
				if (constantPoolName == null) {
582
					ClassFile classFile = (ClassFile) getClassFile(fileName);
583
					return classFile == null ? null : (JavaElement) classFile.getType();
584
				}
585
				pkgEnd = CharOperation.lastIndexOf('/', constantPoolName);
586
				char[] classFileName = CharOperation.subarray(constantPoolName, pkgEnd+1, constantPoolName.length);
587
				ClassFile classFile = (ClassFile) pkg.getClassFile(new String(classFileName) + SuffixConstants.SUFFIX_STRING_class);
588
				return (JavaElement) classFile.getType();
589
			}
590
			ICompilationUnit cu = getCompilationUnit(fileName);
591
			if (cu == null) return null;
592
			// must use getElementAt(...) as there is no back pointer to the defining method (scope is null after resolution has ended)
593
			try {
594
				int sourceStart = ((LocalTypeBinding) referenceBinding).sourceStart;
595
				return (JavaElement) cu.getElementAt(sourceStart);
596
			} catch (JavaModelException e) {
597
				// does not exist
598
				return null;
599
			}
600
		} else if (referenceBinding.isTypeVariable()) {
601
			// type parameter
602
			final String typeVariableName = new String(referenceBinding.sourceName());
603
			Binding declaringElement = ((TypeVariableBinding) referenceBinding).declaringElement;
604
			IBinding declaringTypeBinding = null;
605
			if (declaringElement instanceof MethodBinding) {
606
				declaringTypeBinding = this.resolver.getMethodBinding((MethodBinding) declaringElement);
607
				IMethod declaringMethod = (IMethod) declaringTypeBinding.getJavaElement();
608
				return (JavaElement) declaringMethod.getTypeParameter(typeVariableName);
609
			} else {
610
				ITypeBinding typeBinding2 = this.resolver.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) declaringElement);
611
				if (typeBinding2 == null) return null;
612
				declaringTypeBinding = typeBinding2;
613
				IType declaringType = (IType) declaringTypeBinding.getJavaElement();
614
				return (JavaElement) declaringType.getTypeParameter(typeVariableName);
615
			}
616
		} else {
496
		} else {
617
			if (fileName == null) return null; // case of a WilCardBinding that doesn't have a corresponding Java element
497
			return org.eclipse.jdt.internal.core.util.Util.getUnresolvedJavaElement(typeBinding, null, null);
618
			// member or top level type
619
			ITypeBinding declaringTypeBinding = null;
620
			if (this.isArray()) {
621
				declaringTypeBinding = this.getElementType().getDeclaringClass();
622
			} else {
623
				declaringTypeBinding = this.getDeclaringClass();
624
			}
625
			if (declaringTypeBinding == null) {
626
				// top level type
627
				if (Util.isClassFileName(fileName)) {
628
					ClassFile classFile = (ClassFile) getClassFile(fileName);
629
					if (classFile == null) return null;
630
					return (JavaElement) classFile.getType();
631
				}
632
				ICompilationUnit cu = getCompilationUnit(fileName);
633
				if (cu == null) return null;
634
				return (JavaElement) cu.getType(new String(referenceBinding.sourceName()));
635
			} else {
636
				// member type
637
				IType declaringType = (IType) declaringTypeBinding.getJavaElement();
638
				if (declaringType == null) return null;
639
				return (JavaElement) declaringType.getType(new String(referenceBinding.sourceName()));
640
			}
641
		}
498
		}
642
	}
499
	}
643
500
Lines 781-823 Link Here
781
		return this.resolver.getPackageBinding(referenceBinding.getPackage());
638
		return this.resolver.getPackageBinding(referenceBinding.getPackage());
782
	}
639
	}
783
640
784
	/*
785
	 * Returns the package that includes the given file name, or null if not found.
786
	 * pkgEnd == jarSeparator if default package in a jar
787
	 * pkgEnd > jarSeparator if non default package in a jar
788
	 * pkgEnd > 0 if package not in a jar
789
	 *
790
	 * @see org.eclipse.jdt.internal.compiler.env.IDependent#getFileName()
791
	 */
792
	private IPackageFragment getPackageFragment(char[] fileName, int pkgEnd, int jarSeparator) {
793
		if (jarSeparator != -1) {
794
			String jarMemento = new String(fileName, 0, jarSeparator);
795
			IPackageFragmentRoot root = (IPackageFragmentRoot) JavaCore.create(jarMemento);
796
			if (pkgEnd == jarSeparator)
797
				return root.getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
798
			char[] pkgName = CharOperation.subarray(fileName, jarSeparator+1, pkgEnd);
799
			CharOperation.replace(pkgName, '/', '.');
800
			return root.getPackageFragment(new String(pkgName));
801
		} else {
802
			Path path = new Path(new String(fileName, 0, pkgEnd));
803
			IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
804
			IContainer folder = path.segmentCount() == 1 ? workspaceRoot.getProject(path.lastSegment()) : (IContainer) workspaceRoot.getFolder(path);
805
			IJavaElement element = JavaCore.create(folder);
806
			if (element == null) return null;
807
			switch (element.getElementType()) {
808
				case IJavaElement.PACKAGE_FRAGMENT:
809
					return (IPackageFragment) element;
810
				case IJavaElement.PACKAGE_FRAGMENT_ROOT:
811
					return ((IPackageFragmentRoot) element).getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
812
				case IJavaElement.JAVA_PROJECT:
813
					IPackageFragmentRoot root = ((IJavaProject) element).getPackageFragmentRoot(folder);
814
					if (root == null) return null;
815
					return root.getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
816
			}
817
			return null;
818
		}
819
	}
820
821
	/**
641
	/**
822
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#getQualifiedName()
642
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#getQualifiedName()
823
	 */
643
	 */
(-)dom/org/eclipse/jdt/core/dom/MethodBinding.java (-70 / +6 lines)
Lines 11-25 Link Here
11
11
12
package org.eclipse.jdt.core.dom;
12
package org.eclipse.jdt.core.dom;
13
13
14
import java.util.ArrayList;
15
import java.util.Iterator;
16
17
import org.eclipse.jdt.core.IJavaElement;
14
import org.eclipse.jdt.core.IJavaElement;
18
import org.eclipse.jdt.core.IMethod;
19
import org.eclipse.jdt.core.IType;
20
import org.eclipse.jdt.core.JavaModelException;
21
import org.eclipse.jdt.core.Signature;
22
import org.eclipse.jdt.core.compiler.CharOperation;
23
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
15
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
24
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
16
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
25
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding;
17
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding;
Lines 29-35 Link Here
29
import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;
21
import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;
30
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
22
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
31
import org.eclipse.jdt.internal.core.JavaElement;
23
import org.eclipse.jdt.internal.core.JavaElement;
32
import org.eclipse.jdt.internal.core.Member;
33
import org.eclipse.jdt.internal.core.util.Util;
24
import org.eclipse.jdt.internal.core.util.Util;
34
25
35
/**
26
/**
Lines 252-319 Link Here
252
	}
243
	}
253
244
254
	private JavaElement getUnresolvedJavaElement() {
245
	private JavaElement getUnresolvedJavaElement() {
255
		IType declaringType = (IType) getDeclaringClass().getJavaElement();
256
		if (declaringType == null) return null;
257
		if (!(this.resolver instanceof DefaultBindingResolver)) return null;
246
		if (!(this.resolver instanceof DefaultBindingResolver)) return null;
258
		ASTNode node = (ASTNode) ((DefaultBindingResolver) this.resolver).bindingsToAstNodes.get(this);
247
		
259
		if (node != null && declaringType.getParent().getElementType() != IJavaElement.CLASS_FILE) {
248
		DefaultBindingResolver defaultBindingResolver = (DefaultBindingResolver) this.resolver;
260
			if (node instanceof MethodDeclaration) {
249
		return Util.getUnresolvedJavaElement(
261
				MethodDeclaration methodDeclaration = (MethodDeclaration) node;
250
				this.binding,
262
				ArrayList parameterSignatures = new ArrayList();
251
				defaultBindingResolver.workingCopyOwner,
263
				Iterator iterator = methodDeclaration.parameters().iterator();
252
				defaultBindingResolver.getBindingsToNodesMap());
264
				while (iterator.hasNext()) {
265
					SingleVariableDeclaration parameter = (SingleVariableDeclaration) iterator.next();
266
					Type type = parameter.getType();
267
					String typeSig = Util.getSignature(type);
268
					int arrayDim = parameter.getExtraDimensions();
269
					if (parameter.getAST().apiLevel() >= AST.JLS3 && parameter.isVarargs()) {
270
						arrayDim++;
271
					}
272
					if (arrayDim > 0) {
273
						typeSig = Signature.createArraySignature(typeSig, arrayDim);
274
					}
275
					parameterSignatures.add(typeSig);
276
				}
277
				int parameterCount = parameterSignatures.size();
278
				String[] parameters = new String[parameterCount];
279
				parameterSignatures.toArray(parameters);
280
				return (JavaElement) declaringType.getMethod(getName(), parameters);
281
			} else {
282
				// annotation type member declaration
283
				AnnotationTypeMemberDeclaration typeMemberDeclaration = (AnnotationTypeMemberDeclaration) node;
284
				return (JavaElement) declaringType.getMethod(typeMemberDeclaration.getName().getIdentifier(), CharOperation.NO_STRINGS); // annotation type members don't have parameters
285
			}
286
		} else {
287
			// case of method not in the created AST, or a binary method
288
			org.eclipse.jdt.internal.compiler.lookup.MethodBinding original = this.binding.original();
289
			String selector = original.isConstructor() ? declaringType.getElementName() : new String(original.selector);
290
			boolean isBinary = declaringType.isBinary();
291
			ReferenceBinding enclosingType = original.declaringClass.enclosingType();
292
			boolean isInnerBinaryTypeConstructor = isBinary && original.isConstructor() && enclosingType != null;
293
			TypeBinding[] parameters = original.parameters;
294
			int length = parameters == null ? 0 : parameters.length;
295
			int declaringIndex = isInnerBinaryTypeConstructor ? 1 : 0;
296
			String[] parameterSignatures = new String[declaringIndex + length];
297
			if (isInnerBinaryTypeConstructor)
298
				parameterSignatures[0] = new String(enclosingType.genericTypeSignature()).replace('/', '.');
299
			for (int i = 0;  i < length; i++) {
300
				parameterSignatures[declaringIndex + i] = new String(parameters[i].genericTypeSignature()).replace('/', '.');
301
			}
302
			IMethod result = declaringType.getMethod(selector, parameterSignatures);
303
			if (isBinary)
304
				return (JavaElement) result;
305
			IMethod[] methods = null;
306
			try {
307
				methods = declaringType.getMethods();
308
			} catch (JavaModelException e) {
309
				// declaring type doesn't exist
310
				return null;
311
			}
312
			IMethod[] candidates = Member.findMethods(result, methods);
313
			if (candidates == null || candidates.length == 0)
314
				return null;
315
			return (JavaElement) candidates[0];
316
		}
317
	}
253
	}
318
254
319
	/**
255
	/**
(-)dom/org/eclipse/jdt/core/dom/VariableBinding.java (-7 / +10 lines)
Lines 12-18 Link Here
12
package org.eclipse.jdt.core.dom;
12
package org.eclipse.jdt.core.dom;
13
13
14
import org.eclipse.jdt.core.IJavaElement;
14
import org.eclipse.jdt.core.IJavaElement;
15
import org.eclipse.jdt.core.IType;
16
import org.eclipse.jdt.core.util.IModifierConstants;
15
import org.eclipse.jdt.core.util.IModifierConstants;
17
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
16
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
18
import org.eclipse.jdt.internal.compiler.impl.Constant;
17
import org.eclipse.jdt.internal.compiler.impl.Constant;
Lines 22-27 Link Here
22
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
21
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
23
import org.eclipse.jdt.internal.core.JavaElement;
22
import org.eclipse.jdt.internal.core.JavaElement;
24
import org.eclipse.jdt.internal.core.LocalVariable;
23
import org.eclipse.jdt.internal.core.LocalVariable;
24
import org.eclipse.jdt.internal.core.util.Util;
25
25
26
/**
26
/**
27
 * Internal implementation of variable bindings.
27
 * Internal implementation of variable bindings.
Lines 201-212 Link Here
201
201
202
	private JavaElement getUnresolvedJavaElement() {
202
	private JavaElement getUnresolvedJavaElement() {
203
		if (isField()) {
203
		if (isField()) {
204
			// field
204
			if (this.resolver instanceof DefaultBindingResolver) {
205
			FieldBinding fieldBinding = (FieldBinding) this.binding;
205
				DefaultBindingResolver defaultBindingResolver = (DefaultBindingResolver) this.resolver;
206
			if (fieldBinding.declaringClass == null) return null; // arraylength
206
				return Util.getUnresolvedJavaElement(
207
			IType declaringType = (IType) getDeclaringClass().getJavaElement();
207
						(FieldBinding) this.binding,
208
			if (declaringType == null) return null;
208
						defaultBindingResolver.workingCopyOwner,
209
			return (JavaElement) declaringType.getField(getName());
209
						defaultBindingResolver.getBindingsToNodesMap());
210
			} else {
211
				return Util.getUnresolvedJavaElement((FieldBinding) this.binding, null, null);
212
			}
210
		}
213
		}
211
		// local variable
214
		// local variable
212
		IMethodBinding declaringMethod = getDeclaringMethod();
215
		IMethodBinding declaringMethod = getDeclaringMethod();
(-)dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java (+10 lines)
Lines 61-66 Link Here
61
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
61
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
62
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
62
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
63
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
63
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
64
import org.eclipse.jdt.internal.core.util.Util;
64
65
65
/**
66
/**
66
 * Internal class for resolving bindings using old ASTs.
67
 * Internal class for resolving bindings using old ASTs.
Lines 208-213 Link Here
208
		}
209
		}
209
		return null;
210
		return null;
210
	}
211
	}
212
	
213
	Util.BindingsToNodesMap getBindingsToNodesMap() {
214
		return new Util.BindingsToNodesMap() {
215
			public org.eclipse.jdt.internal.compiler.ast.ASTNode get(Binding binding) {
216
				return (org.eclipse.jdt.internal.compiler.ast.ASTNode)
217
					DefaultBindingResolver.this.newAstToOldAst.get(DefaultBindingResolver.this.bindingsToAstNodes.get(binding));
218
			}
219
		};
220
	}
211
221
212
	synchronized org.eclipse.jdt.internal.compiler.ast.ASTNode getCorrespondingNode(ASTNode currentNode) {
222
	synchronized org.eclipse.jdt.internal.compiler.ast.ASTNode getCorrespondingNode(ASTNode currentNode) {
213
		return (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(currentNode);
223
		return (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(currentNode);
(-)model/org/eclipse/jdt/internal/core/PackageDeclaration.java (-1 / +1 lines)
Lines 17-23 Link Here
17
 * @see IPackageDeclaration
17
 * @see IPackageDeclaration
18
 */
18
 */
19
19
20
/* package */ class PackageDeclaration extends SourceRefElement implements IPackageDeclaration {
20
public class PackageDeclaration extends SourceRefElement implements IPackageDeclaration {
21
	
21
	
22
	String name;
22
	String name;
23
	
23
	
(-)model/org/eclipse/jdt/internal/core/SourceType.java (-2 / +2 lines)
Lines 81-87 Link Here
81
	
81
	
82
	JavaProject project = (JavaProject) getJavaProject();
82
	JavaProject project = (JavaProject) getJavaProject();
83
	SearchableEnvironment environment = project.newSearchableNameEnvironment(owner);
83
	SearchableEnvironment environment = project.newSearchableNameEnvironment(owner);
84
	CompletionEngine engine = new CompletionEngine(environment, requestor, project.getOptions(true), project);
84
	CompletionEngine engine = new CompletionEngine(environment, requestor, project.getOptions(true), project, owner);
85
85
86
	String source = getCompilationUnit().getSource();
86
	String source = getCompilationUnit().getSource();
87
	if (source != null && insertion > -1 && insertion < source.length()) {
87
	if (source != null && insertion > -1 && insertion < source.length()) {
Lines 97-103 Link Here
97
				getElementName(),
97
				getElementName(),
98
				getParent());
98
				getParent());
99
99
100
		engine.complete(cu, prefix.length + position, prefix.length);
100
		engine.complete(cu, prefix.length + position, prefix.length, null);
101
	} else {
101
	} else {
102
		engine.complete(this, snippet, position, localVariableTypeNames, localVariableNames, localVariableModifiers, isStatic);
102
		engine.complete(this, snippet, position, localVariableTypeNames, localVariableNames, localVariableModifiers, isStatic);
103
	}
103
	}
(-)model/org/eclipse/jdt/internal/core/ClassFile.java (-1 / +1 lines)
Lines 136-142 Link Here
136
				null,
136
				null,
137
				type.sourceFileName((IBinaryType) type.getElementInfo()),
137
				type.sourceFileName((IBinaryType) type.getElementInfo()),
138
				getJavaProject()); // use project to retrieve corresponding .java IFile
138
				getJavaProject()); // use project to retrieve corresponding .java IFile
139
		codeComplete(cu, cu, offset, requestor, owner);
139
		codeComplete(cu, cu, offset, requestor, owner, null);
140
	}
140
	}
141
}
141
}
142
142
(-)model/org/eclipse/jdt/internal/core/Openable.java (-3 / +8 lines)
Lines 96-102 Link Here
96
protected void closing(Object info) {
96
protected void closing(Object info) {
97
	closeBuffer();
97
	closeBuffer();
98
}
98
}
99
protected void codeComplete(org.eclipse.jdt.internal.compiler.env.ICompilationUnit cu, org.eclipse.jdt.internal.compiler.env.ICompilationUnit unitToSkip, int position, CompletionRequestor requestor, WorkingCopyOwner owner) throws JavaModelException {
99
protected void codeComplete(
100
		org.eclipse.jdt.internal.compiler.env.ICompilationUnit cu,
101
		org.eclipse.jdt.internal.compiler.env.ICompilationUnit unitToSkip,
102
		int position, CompletionRequestor requestor,
103
		WorkingCopyOwner owner,
104
		ITypeRoot typeRoot) throws JavaModelException {
100
	if (requestor == null) {
105
	if (requestor == null) {
101
		throw new IllegalArgumentException("Completion requestor cannot be null"); //$NON-NLS-1$
106
		throw new IllegalArgumentException("Completion requestor cannot be null"); //$NON-NLS-1$
102
	}
107
	}
Lines 120-127 Link Here
120
	environment.unitToSkip = unitToSkip;
125
	environment.unitToSkip = unitToSkip;
121
126
122
	// code complete
127
	// code complete
123
	CompletionEngine engine = new CompletionEngine(environment, requestor, project.getOptions(true), project);
128
	CompletionEngine engine = new CompletionEngine(environment, requestor, project.getOptions(true), project, owner);
124
	engine.complete(cu, position, 0);
129
	engine.complete(cu, position, 0, typeRoot);
125
	if(performanceStats != null) {
130
	if(performanceStats != null) {
126
		performanceStats.endRun();
131
		performanceStats.endRun();
127
	}
132
	}
(-)model/org/eclipse/jdt/internal/core/BinaryType.java (-2 / +2 lines)
Lines 92-98 Link Here
92
	}
92
	}
93
	JavaProject project = (JavaProject) getJavaProject();
93
	JavaProject project = (JavaProject) getJavaProject();
94
	SearchableEnvironment environment = project.newSearchableNameEnvironment(owner);
94
	SearchableEnvironment environment = project.newSearchableNameEnvironment(owner);
95
	CompletionEngine engine = new CompletionEngine(environment, requestor, project.getOptions(true), project);
95
	CompletionEngine engine = new CompletionEngine(environment, requestor, project.getOptions(true), project, owner);
96
96
97
	String source = getClassFile().getSource();
97
	String source = getClassFile().getSource();
98
	if (source != null && insertion > -1 && insertion < source.length()) {
98
	if (source != null && insertion > -1 && insertion < source.length()) {
Lines 109-115 Link Here
109
				getElementName(),
109
				getElementName(),
110
				project); // use project to retrieve corresponding .java IFile
110
				project); // use project to retrieve corresponding .java IFile
111
111
112
		engine.complete(cu, prefix.length + position, prefix.length);
112
		engine.complete(cu, prefix.length + position, prefix.length, null);
113
	} else {
113
	} else {
114
		engine.complete(this, snippet, position, localVariableTypeNames, localVariableNames, localVariableModifiers, isStatic);
114
		engine.complete(this, snippet, position, localVariableTypeNames, localVariableNames, localVariableModifiers, isStatic);
115
	}
115
	}
(-)model/org/eclipse/jdt/internal/core/ResolvedSourceField.java (-1 / +1 lines)
Lines 47-53 Link Here
47
		super.toStringInfo(tab, buffer, info, showResolvedInfo);
47
		super.toStringInfo(tab, buffer, info, showResolvedInfo);
48
		if (showResolvedInfo) {
48
		if (showResolvedInfo) {
49
			buffer.append(" {key="); //$NON-NLS-1$
49
			buffer.append(" {key="); //$NON-NLS-1$
50
			buffer.append(this.uniqueKey);
50
			buffer.append(this.getKey());
51
			buffer.append("}"); //$NON-NLS-1$
51
			buffer.append("}"); //$NON-NLS-1$
52
		}
52
		}
53
	}
53
	}
(-)model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java (-21 / +52 lines)
Lines 126-132 Link Here
126
126
127
	ICompilationUnit parentCU= (ICompilationUnit)parentHandle;
127
	ICompilationUnit parentCU= (ICompilationUnit)parentHandle;
128
	//create the import container and its info
128
	//create the import container and its info
129
	ImportContainer importContainer= (ImportContainer)parentCU.getImportContainer();
129
	ImportContainer importContainer= createImportContainer(parentCU);
130
	if (this.importContainerInfo == null) {
130
	if (this.importContainerInfo == null) {
131
		this.importContainerInfo = new JavaElementInfo();
131
		this.importContainerInfo = new JavaElementInfo();
132
		JavaElementInfo parentInfo = (JavaElementInfo) this.infoStack.peek();
132
		JavaElementInfo parentInfo = (JavaElementInfo) this.infoStack.peek();
Lines 135-141 Link Here
135
	}
135
	}
136
	
136
	
137
	String elementName = JavaModelManager.getJavaModelManager().intern(new String(CharOperation.concatWith(tokens, '.')));
137
	String elementName = JavaModelManager.getJavaModelManager().intern(new String(CharOperation.concatWith(tokens, '.')));
138
	ImportDeclaration handle = new ImportDeclaration(importContainer, elementName, onDemand);
138
	ImportDeclaration handle = createImportDeclaration(importContainer, elementName, onDemand);
139
	resolveDuplicates(handle);
139
	resolveDuplicates(handle);
140
	
140
	
141
	ImportDeclarationElementInfo info = new ImportDeclarationElementInfo();
141
	ImportDeclarationElementInfo info = new ImportDeclarationElementInfo();
Lines 167-173 Link Here
167
		
167
		
168
		if (parentHandle.getElementType() == IJavaElement.COMPILATION_UNIT) {
168
		if (parentHandle.getElementType() == IJavaElement.COMPILATION_UNIT) {
169
			char[] name = CharOperation.concatWith(importReference.getImportName(), '.');
169
			char[] name = CharOperation.concatWith(importReference.getImportName(), '.');
170
			handle = new PackageDeclaration((CompilationUnit) parentHandle, new String(name));
170
			handle = createPackageDeclaration(parentHandle, new String(name));
171
		}
171
		}
172
		else {
172
		else {
173
			Assert.isTrue(false); // Should not happen
173
			Assert.isTrue(false); // Should not happen
Lines 200-210 Link Here
200
		this.children.put(parentInfo, childrenList = new ArrayList());
200
		this.children.put(parentInfo, childrenList = new ArrayList());
201
	childrenList.add(handle);
201
	childrenList.add(handle);
202
}
202
}
203
protected Annotation createAnnotation(JavaElement parent, String name) {
204
	return new Annotation(parent, name);
205
}
206
protected SourceField createField(JavaElement parent, FieldInfo fieldInfo) {
207
	String fieldName = JavaModelManager.getJavaModelManager().intern(new String(fieldInfo.name));
208
	return new SourceField(parent, fieldName);
209
}
210
protected ImportContainer createImportContainer(ICompilationUnit parent) {
211
	return (ImportContainer)parent.getImportContainer();
212
}
213
protected ImportDeclaration createImportDeclaration(ImportContainer parent, String name, boolean onDemand) {
214
	return new ImportDeclaration(parent, name, onDemand);
215
}
216
protected Initializer createInitializer(JavaElement parent) {
217
	return new Initializer(parent, 1);
218
}
219
protected SourceMethod createMethod(JavaElement parent, MethodInfo methodInfo) {
220
	String selector = JavaModelManager.getJavaModelManager().intern(new String(methodInfo.name));
221
	String[] parameterTypeSigs = convertTypeNamesToSigs(methodInfo.parameterTypes);
222
	return new SourceMethod(parent, selector, parameterTypeSigs);
223
}
224
protected PackageDeclaration createPackageDeclaration(JavaElement parent, String name) {
225
	return new PackageDeclaration((CompilationUnit) parent, name);
226
}
227
protected SourceType createType(JavaElement parent, TypeInfo typeInfo) {
228
	String nameString= new String(typeInfo.name);
229
	return new SourceType(parent, nameString);
230
}
231
protected TypeParameter createTypeParameter(JavaElement parent, String name) {
232
	return new TypeParameter(parent, name);
233
}
203
/**
234
/**
204
 * Convert these type names to signatures.
235
 * Convert these type names to signatures.
205
 * @see Signature
236
 * @see Signature
206
 */
237
 */
207
/* default */ static String[] convertTypeNamesToSigs(char[][] typeNames) {
238
protected static String[] convertTypeNamesToSigs(char[][] typeNames) {
208
	if (typeNames == null)
239
	if (typeNames == null)
209
		return CharOperation.NO_STRINGS;
240
		return CharOperation.NO_STRINGS;
210
	int n = typeNames.length;
241
	int n = typeNames.length;
Lines 219-225 Link Here
219
}
250
}
220
protected IAnnotation enterAnnotation(org.eclipse.jdt.internal.compiler.ast.Annotation annotation, AnnotatableInfo parentInfo, JavaElement parentHandle) {
251
protected IAnnotation enterAnnotation(org.eclipse.jdt.internal.compiler.ast.Annotation annotation, AnnotatableInfo parentInfo, JavaElement parentHandle) {
221
	String nameString = new String(CharOperation.concatWith(annotation.type.getTypeName(), '.'));
252
	String nameString = new String(CharOperation.concatWith(annotation.type.getTypeName(), '.'));
222
	Annotation handle = new Annotation(parentHandle, nameString); //NB: occurenceCount is computed in resolveDuplicates
253
	Annotation handle = createAnnotation(parentHandle, nameString); //NB: occurenceCount is computed in resolveDuplicates
223
	resolveDuplicates(handle);
254
	resolveDuplicates(handle);
224
	
255
	
225
	AnnotationInfo info = new AnnotationInfo();
256
	AnnotationInfo info = new AnnotationInfo();
Lines 237-247 Link Here
237
	if (membersLength == 0) {
268
	if (membersLength == 0) {
238
		info.members = Annotation.NO_MEMBER_VALUE_PAIRS;
269
		info.members = Annotation.NO_MEMBER_VALUE_PAIRS;
239
	} else {
270
	} else {
240
		IMemberValuePair[] members = new IMemberValuePair[membersLength];
271
		info.members = getMemberValuePairs(memberValuePairs);
241
		for (int j = 0; j < membersLength; j++) {
242
			members[j] = getMemberValuePair(memberValuePairs[j]);
243
		}
244
		info.members = members;
245
	}
272
	}
246
	
273
	
247
	if (parentInfo != null) {
274
	if (parentInfo != null) {
Lines 278-285 Link Here
278
	JavaElement parentHandle= (JavaElement) this.handleStack.peek();
305
	JavaElement parentHandle= (JavaElement) this.handleStack.peek();
279
	SourceField handle = null;
306
	SourceField handle = null;
280
	if (parentHandle.getElementType() == IJavaElement.TYPE) {
307
	if (parentHandle.getElementType() == IJavaElement.TYPE) {
281
		String fieldName = JavaModelManager.getJavaModelManager().intern(new String(fieldInfo.name));
308
		handle = createField(parentHandle, fieldInfo);
282
		handle = new SourceField(parentHandle, fieldName);
283
	}
309
	}
284
	else {
310
	else {
285
		Assert.isTrue(false); // Should not happen
311
		Assert.isTrue(false); // Should not happen
Lines 322-328 Link Here
322
		Initializer handle = null;
348
		Initializer handle = null;
323
		
349
		
324
		if (parentHandle.getElementType() == IJavaElement.TYPE) {
350
		if (parentHandle.getElementType() == IJavaElement.TYPE) {
325
			handle = new Initializer(parentHandle, 1);
351
			handle = createInitializer(parentHandle);
326
		}
352
		}
327
		else {
353
		else {
328
			Assert.isTrue(false); // Should not happen
354
			Assert.isTrue(false); // Should not happen
Lines 359-368 Link Here
359
		methodInfo.exceptionTypes= CharOperation.NO_CHAR_CHAR;
385
		methodInfo.exceptionTypes= CharOperation.NO_CHAR_CHAR;
360
	}
386
	}
361
	
387
	
362
	String[] parameterTypeSigs = convertTypeNamesToSigs(methodInfo.parameterTypes);
363
	if (parentHandle.getElementType() == IJavaElement.TYPE) {
388
	if (parentHandle.getElementType() == IJavaElement.TYPE) {
364
		String selector = JavaModelManager.getJavaModelManager().intern(new String(methodInfo.name));
389
		handle = createMethod(parentHandle, methodInfo);
365
		handle = new SourceMethod(parentHandle, selector, parameterTypeSigs);
366
	}
390
	}
367
	else {
391
	else {
368
		Assert.isTrue(false); // Should not happen
392
		Assert.isTrue(false); // Should not happen
Lines 422-429 Link Here
422
446
423
	JavaElementInfo parentInfo = (JavaElementInfo) this.infoStack.peek();
447
	JavaElementInfo parentInfo = (JavaElementInfo) this.infoStack.peek();
424
	JavaElement parentHandle= (JavaElement) this.handleStack.peek();
448
	JavaElement parentHandle= (JavaElement) this.handleStack.peek();
425
	String nameString= new String(typeInfo.name);
449
	SourceType handle = this.createType(parentHandle, typeInfo); //NB: occurenceCount is computed in resolveDuplicates
426
	SourceType handle = new SourceType(parentHandle, nameString); //NB: occurenceCount is computed in resolveDuplicates
427
	resolveDuplicates(handle);
450
	resolveDuplicates(handle);
428
	
451
	
429
	SourceTypeElementInfo info = 
452
	SourceTypeElementInfo info = 
Lines 475-481 Link Here
475
	JavaElementInfo parentInfo = (JavaElementInfo) this.infoStack.peek();
498
	JavaElementInfo parentInfo = (JavaElementInfo) this.infoStack.peek();
476
	JavaElement parentHandle = (JavaElement) this.handleStack.peek();
499
	JavaElement parentHandle = (JavaElement) this.handleStack.peek();
477
	String nameString = new String(typeParameterInfo.name);
500
	String nameString = new String(typeParameterInfo.name);
478
	TypeParameter handle = new TypeParameter(parentHandle, nameString); //NB: occurenceCount is computed in resolveDuplicates
501
	TypeParameter handle = createTypeParameter(parentHandle, nameString); //NB: occurenceCount is computed in resolveDuplicates
479
	resolveDuplicates(handle);
502
	resolveDuplicates(handle);
480
	
503
	
481
	TypeParameterElementInfo info = new TypeParameterElementInfo();
504
	TypeParameterElementInfo info = new TypeParameterElementInfo();
Lines 601-616 Link Here
601
		handle.occurrenceCount++;
624
		handle.occurrenceCount++;
602
	}
625
	}
603
}
626
}
604
private IMemberValuePair getMemberValuePair(MemberValuePair memberValuePair) {
627
protected IMemberValuePair getMemberValuePair(MemberValuePair memberValuePair) {
605
	String memberName = new String(memberValuePair.name);
628
	String memberName = new String(memberValuePair.name);
606
	org.eclipse.jdt.internal.core.MemberValuePair result = new org.eclipse.jdt.internal.core.MemberValuePair(memberName);
629
	org.eclipse.jdt.internal.core.MemberValuePair result = new org.eclipse.jdt.internal.core.MemberValuePair(memberName);
607
	result.value = getMemberValue(result, memberValuePair.value);
630
	result.value = getMemberValue(result, memberValuePair.value);
608
	return result;
631
	return result;
609
}
632
}
633
protected IMemberValuePair[] getMemberValuePairs(MemberValuePair[] memberValuePairs) {
634
	int membersLength = memberValuePairs.length;
635
	IMemberValuePair[] members = new IMemberValuePair[membersLength];
636
	for (int j = 0; j < membersLength; j++) {
637
		members[j] = getMemberValuePair(memberValuePairs[j]);
638
	}
639
	return members;
640
}
610
/*
641
/*
611
 * Creates the value from the given expression, and sets the valueKind on the given memberValuePair
642
 * Creates the value from the given expression, and sets the valueKind on the given memberValuePair
612
 */
643
 */
613
private Object getMemberValue(org.eclipse.jdt.internal.core.MemberValuePair memberValuePair, Expression expression) {
644
protected Object getMemberValue(org.eclipse.jdt.internal.core.MemberValuePair memberValuePair, Expression expression) {
614
	if (expression instanceof NullLiteral) {
645
	if (expression instanceof NullLiteral) {
615
		return null;
646
		return null;
616
	} else if (expression instanceof Literal) {
647
	} else if (expression instanceof Literal) {
(-)model/org/eclipse/jdt/internal/core/CompilationUnit.java (-1 / +7 lines)
Lines 338-344 Link Here
338
 * @see org.eclipse.jdt.core.ICodeAssist#codeComplete(int, org.eclipse.jdt.core.CompletionRequestor, org.eclipse.jdt.core.WorkingCopyOwner)
338
 * @see org.eclipse.jdt.core.ICodeAssist#codeComplete(int, org.eclipse.jdt.core.CompletionRequestor, org.eclipse.jdt.core.WorkingCopyOwner)
339
 */
339
 */
340
public void codeComplete(int offset, CompletionRequestor requestor, WorkingCopyOwner workingCopyOwner) throws JavaModelException {
340
public void codeComplete(int offset, CompletionRequestor requestor, WorkingCopyOwner workingCopyOwner) throws JavaModelException {
341
	codeComplete(this, isWorkingCopy() ? (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) getOriginalElement() : this, offset, requestor, workingCopyOwner);
341
	codeComplete(
342
			this,
343
			isWorkingCopy() ? (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) getOriginalElement() : this,
344
			offset,
345
			requestor,
346
			workingCopyOwner,
347
			this);
342
}
348
}
343
349
344
/**
350
/**
(-)model/org/eclipse/jdt/internal/core/ResolvedSourceType.java (-1 / +1 lines)
Lines 53-59 Link Here
53
		super.toStringInfo(tab, buffer, info, showResolvedInfo);
53
		super.toStringInfo(tab, buffer, info, showResolvedInfo);
54
		if (showResolvedInfo) {
54
		if (showResolvedInfo) {
55
			buffer.append(" {key="); //$NON-NLS-1$
55
			buffer.append(" {key="); //$NON-NLS-1$
56
			buffer.append(this.uniqueKey);
56
			buffer.append(this.getKey());
57
			buffer.append("}"); //$NON-NLS-1$
57
			buffer.append("}"); //$NON-NLS-1$
58
		}
58
		}
59
	}
59
	}
(-)model/org/eclipse/jdt/internal/core/Initializer.java (-1 / +1 lines)
Lines 24-30 Link Here
24
 * @see IInitializer
24
 * @see IInitializer
25
 */
25
 */
26
26
27
/* package */ class Initializer extends Member implements IInitializer {
27
public class Initializer extends Member implements IInitializer {
28
28
29
protected Initializer(JavaElement parent, int count) {
29
protected Initializer(JavaElement parent, int count) {
30
	super(parent);
30
	super(parent);
(-)model/org/eclipse/jdt/internal/core/ResolvedSourceMethod.java (-1 / +1 lines)
Lines 46-52 Link Here
46
		super.toStringInfo(tab, buffer, info, showResolvedInfo);
46
		super.toStringInfo(tab, buffer, info, showResolvedInfo);
47
		if (showResolvedInfo) {
47
		if (showResolvedInfo) {
48
			buffer.append(" {key="); //$NON-NLS-1$
48
			buffer.append(" {key="); //$NON-NLS-1$
49
			buffer.append(this.uniqueKey);
49
			buffer.append(this.getKey());
50
			buffer.append("}"); //$NON-NLS-1$
50
			buffer.append("}"); //$NON-NLS-1$
51
		}
51
		}
52
	}
52
	}
(-)model/org/eclipse/jdt/internal/core/ImportContainer.java (+3 lines)
Lines 69-74 Link Here
69
	if (isOnDemand)
69
	if (isOnDemand)
70
		// make sure to copy the string (so that it doesn't hold on the underlying char[] that might be much bigger than necessary)
70
		// make sure to copy the string (so that it doesn't hold on the underlying char[] that might be much bigger than necessary)
71
		importName = new String(importName.substring(0, index));
71
		importName = new String(importName.substring(0, index));
72
	return getImport(importName, isOnDemand);
73
}
74
protected IImportDeclaration getImport(String importName, boolean isOnDemand) {
72
	return new ImportDeclaration(this, importName, isOnDemand);
75
	return new ImportDeclaration(this, importName, isOnDemand);
73
}
76
}
74
/*
77
/*
(-)model/org/eclipse/jdt/internal/core/JavaElementInfo.java (-1 / +1 lines)
Lines 16-22 Link Here
16
 * Holds cached structure and properties for a Java element.
16
 * Holds cached structure and properties for a Java element.
17
 * Subclassed to carry properties for specific kinds of elements.
17
 * Subclassed to carry properties for specific kinds of elements.
18
 */
18
 */
19
/* package */ class JavaElementInfo {
19
public class JavaElementInfo {
20
20
21
	/**
21
	/**
22
	 * Collection of handles of immediate children of this
22
	 * Collection of handles of immediate children of this
(-)model/org/eclipse/jdt/internal/core/util/Util.java (-2 / +253 lines)
Lines 39-54 Link Here
39
import org.eclipse.jdt.core.util.IFieldInfo;
39
import org.eclipse.jdt.core.util.IFieldInfo;
40
import org.eclipse.jdt.core.util.IMethodInfo;
40
import org.eclipse.jdt.core.util.IMethodInfo;
41
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
41
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
42
import org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration;
42
import org.eclipse.jdt.internal.compiler.ast.Argument;
43
import org.eclipse.jdt.internal.compiler.ast.Argument;
44
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
43
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
45
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
44
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
46
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
45
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
47
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
48
import org.eclipse.jdt.internal.compiler.env.IDependent;
46
import org.eclipse.jdt.internal.compiler.impl.Constant;
49
import org.eclipse.jdt.internal.compiler.impl.Constant;
50
import org.eclipse.jdt.internal.compiler.lookup.Binding;
51
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
52
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
53
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
54
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
47
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
55
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
48
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
56
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
49
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
57
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
58
import org.eclipse.jdt.internal.core.ClassFile;
50
import org.eclipse.jdt.internal.core.JavaElement;
59
import org.eclipse.jdt.internal.core.JavaElement;
51
import org.eclipse.jdt.internal.core.JavaModelManager;
60
import org.eclipse.jdt.internal.core.JavaModelManager;
61
import org.eclipse.jdt.internal.core.Member;
52
import org.eclipse.jdt.internal.core.MemberValuePair;
62
import org.eclipse.jdt.internal.core.MemberValuePair;
53
import org.eclipse.jdt.internal.core.PackageFragment;
63
import org.eclipse.jdt.internal.core.PackageFragment;
54
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
64
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
Lines 76-81 Link Here
76
		 */
86
		 */
77
		int compare(Object a, Object b);
87
		int compare(Object a, Object b);
78
	}
88
	}
89
	
90
	public static interface BindingsToNodesMap {
91
		public org.eclipse.jdt.internal.compiler.ast.ASTNode get(Binding binding);
92
	}
93
	
79
	private static final String ARGUMENTS_DELIMITER = "#"; //$NON-NLS-1$
94
	private static final String ARGUMENTS_DELIMITER = "#"; //$NON-NLS-1$
80
95
81
	private static final String EMPTY_ARGUMENT = "   "; //$NON-NLS-1$
96
	private static final String EMPTY_ARGUMENT = "   "; //$NON-NLS-1$
Lines 747-752 Link Here
747
		return null;
762
		return null;
748
	}
763
	}
749
	
764
	
765
	private static IClassFile getClassFile(char[] fileName) {
766
		int jarSeparator = CharOperation.indexOf(IDependent.JAR_FILE_ENTRY_SEPARATOR, fileName);
767
		int pkgEnd = CharOperation.lastIndexOf('/', fileName); // pkgEnd is exclusive
768
		if (pkgEnd == -1)
769
			pkgEnd = CharOperation.lastIndexOf(File.separatorChar, fileName);
770
		if (jarSeparator != -1 && pkgEnd < jarSeparator) // if in a jar and no slash, it is a default package -> pkgEnd should be equal to jarSeparator
771
			pkgEnd = jarSeparator;
772
		if (pkgEnd == -1)
773
			return null;
774
		IPackageFragment pkg = getPackageFragment(fileName, pkgEnd, jarSeparator);
775
		if (pkg == null) return null;
776
		int start;
777
		return pkg.getClassFile(new String(fileName, start = pkgEnd + 1, fileName.length - start));
778
	}
779
	
780
	private static ICompilationUnit getCompilationUnit(char[] fileName, WorkingCopyOwner workingCopyOwner) {
781
		char[] slashSeparatedFileName = CharOperation.replaceOnCopy(fileName, File.separatorChar, '/');
782
		int pkgEnd = CharOperation.lastIndexOf('/', slashSeparatedFileName); // pkgEnd is exclusive
783
		if (pkgEnd == -1)
784
			return null;
785
		IPackageFragment pkg = getPackageFragment(slashSeparatedFileName, pkgEnd, -1/*no jar separator for .java files*/);
786
		if (pkg == null) return null;
787
		int start;
788
		ICompilationUnit cu = pkg.getCompilationUnit(new String(slashSeparatedFileName, start =  pkgEnd+1, slashSeparatedFileName.length - start));
789
		if (workingCopyOwner != null) {
790
			ICompilationUnit workingCopy = cu.findWorkingCopy(workingCopyOwner);
791
			if (workingCopy != null)
792
				return workingCopy;
793
		}
794
		return cu;
795
	}
796
	
750
	/**
797
	/**
751
	 * Returns the registered Java like extensions.
798
	 * Returns the registered Java like extensions.
752
	 */
799
	 */
Lines 910-916 Link Here
910
		}
957
		}
911
		return lineSeparator;
958
		return lineSeparator;
912
	}
959
	}
913
		
960
	
961
	private static IPackageFragment getPackageFragment(char[] fileName, int pkgEnd, int jarSeparator) {
962
		if (jarSeparator != -1) {
963
			String jarMemento = new String(fileName, 0, jarSeparator);
964
			IPackageFragmentRoot root = (IPackageFragmentRoot) JavaCore.create(jarMemento);
965
			if (pkgEnd == jarSeparator)
966
				return root.getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
967
			char[] pkgName = CharOperation.subarray(fileName, jarSeparator+1, pkgEnd);
968
			CharOperation.replace(pkgName, '/', '.');
969
			return root.getPackageFragment(new String(pkgName));
970
		} else {
971
			Path path = new Path(new String(fileName, 0, pkgEnd));
972
			IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
973
			IContainer folder = path.segmentCount() == 1 ? workspaceRoot.getProject(path.lastSegment()) : (IContainer) workspaceRoot.getFolder(path);
974
			IJavaElement element = JavaCore.create(folder);
975
			if (element == null) return null;
976
			switch (element.getElementType()) {
977
				case IJavaElement.PACKAGE_FRAGMENT:
978
					return (IPackageFragment) element;
979
				case IJavaElement.PACKAGE_FRAGMENT_ROOT:
980
					return ((IPackageFragmentRoot) element).getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
981
				case IJavaElement.JAVA_PROJECT:
982
					IPackageFragmentRoot root = ((IJavaProject) element).getPackageFragmentRoot(folder);
983
					if (root == null) return null;
984
					return root.getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
985
			}
986
			return null;
987
		}
988
	}
989
	
914
	/**
990
	/**
915
	 * Returns the number of parameter types in a method signature.
991
	 * Returns the number of parameter types in a method signature.
916
	 */
992
	 */
Lines 1204-1210 Link Here
1204
		return result;
1280
		return result;
1205
	}
1281
	}
1206
	
1282
	
1207
		/*
1283
	/**
1284
	 * Return the java element corresponding to the given compiler binding.
1285
	 */
1286
	public static JavaElement getUnresolvedJavaElement(FieldBinding binding, WorkingCopyOwner workingCopyOwner, BindingsToNodesMap bindingsToNodes) {
1287
		if (binding.declaringClass == null) return null; // arraylength
1288
		IType declaringType = (IType) getUnresolvedJavaElement(binding.declaringClass, workingCopyOwner, bindingsToNodes);
1289
		if (declaringType == null) return null;
1290
		return (JavaElement) declaringType.getField(String.valueOf(binding.name));
1291
	}
1292
	
1293
	/**
1294
	 * Return the java element corresponding to the given compiler binding.
1295
	 */
1296
	public static JavaElement getUnresolvedJavaElement(MethodBinding methodBinding, WorkingCopyOwner workingCopyOwner, BindingsToNodesMap bindingsToNodes) {
1297
		IType declaringType = (IType) getUnresolvedJavaElement(methodBinding.declaringClass, workingCopyOwner, bindingsToNodes);
1298
		
1299
		if (declaringType == null) return null;
1300
		
1301
		org.eclipse.jdt.internal.compiler.ast.ASTNode node = bindingsToNodes == null ? null : bindingsToNodes.get(methodBinding);
1302
		if (node != null && !declaringType.isBinary()) {
1303
			if (node instanceof AnnotationMethodDeclaration) {
1304
				// node is an AnnotationMethodDeclaration
1305
				AnnotationMethodDeclaration typeMemberDeclaration = (AnnotationMethodDeclaration) node;
1306
				return (JavaElement) declaringType.getMethod(String.valueOf(typeMemberDeclaration.selector), CharOperation.NO_STRINGS); // annotation type members don't have parameters
1307
			} else {
1308
				// node is an MethodDeclaration
1309
				MethodDeclaration methodDeclaration = (MethodDeclaration) node;
1310
				
1311
				Argument[] arguments = methodDeclaration.arguments;
1312
				String[] parameterSignatures;
1313
				if (arguments != null) {
1314
					parameterSignatures = new String[arguments.length];
1315
					for (int i = 0; i < arguments.length; i++) {
1316
						Argument argument = arguments[i];
1317
						TypeReference typeReference = argument.type;
1318
						int arrayDim = typeReference.dimensions();
1319
						
1320
						String typeSig = 
1321
							Signature.createTypeSignature(
1322
									CharOperation.concatWith(
1323
											typeReference.getTypeName(), '.'), false);
1324
						if (arrayDim > 0) {
1325
							typeSig = Signature.createArraySignature(typeSig, arrayDim);
1326
						}
1327
						parameterSignatures[i] = typeSig;
1328
						
1329
					}
1330
				} else {
1331
					parameterSignatures = new String[0];
1332
				}
1333
				return (JavaElement) declaringType.getMethod(String.valueOf(methodDeclaration.selector), parameterSignatures);
1334
			}
1335
		} else {
1336
			// case of method not in the created AST, or a binary method
1337
			org.eclipse.jdt.internal.compiler.lookup.MethodBinding original = methodBinding.original();
1338
			String selector = original.isConstructor() ? declaringType.getElementName() : new String(original.selector);
1339
			boolean isBinary = declaringType.isBinary();
1340
			ReferenceBinding enclosingType = original.declaringClass.enclosingType();
1341
			boolean isInnerBinaryTypeConstructor = isBinary && original.isConstructor() && enclosingType != null;
1342
			TypeBinding[] parameters = original.parameters;
1343
			int length = parameters == null ? 0 : parameters.length;
1344
			int declaringIndex = isInnerBinaryTypeConstructor ? 1 : 0;
1345
			String[] parameterSignatures = new String[declaringIndex + length];
1346
			if (isInnerBinaryTypeConstructor)
1347
				parameterSignatures[0] = new String(enclosingType.genericTypeSignature()).replace('/', '.');
1348
			for (int i = 0;  i < length; i++) {
1349
				parameterSignatures[declaringIndex + i] = new String(parameters[i].genericTypeSignature()).replace('/', '.');
1350
			}
1351
			IMethod result = declaringType.getMethod(selector, parameterSignatures);
1352
			if (isBinary)
1353
				return (JavaElement) result;
1354
			IMethod[] methods = null;
1355
			try {
1356
				methods = declaringType.getMethods();
1357
			} catch (JavaModelException e) {
1358
				// declaring type doesn't exist
1359
				return null;
1360
			}
1361
			IMethod[] candidates = Member.findMethods(result, methods);
1362
			if (candidates == null || candidates.length == 0)
1363
				return null;
1364
			return (JavaElement) candidates[0];
1365
		}
1366
	}
1367
	
1368
	/**
1369
	 * Return the java element corresponding to the given compiler binding.
1370
	 */
1371
	public static JavaElement getUnresolvedJavaElement(TypeBinding typeBinding, WorkingCopyOwner workingCopyOwner, BindingsToNodesMap bindingsToNodes) {
1372
		if (typeBinding == null)
1373
			return null;
1374
		switch (typeBinding.kind()) {
1375
			case Binding.ARRAY_TYPE :
1376
				typeBinding = ((org.eclipse.jdt.internal.compiler.lookup.ArrayBinding) typeBinding).leafComponentType();
1377
				return getUnresolvedJavaElement(typeBinding, workingCopyOwner, bindingsToNodes);
1378
			case Binding.BASE_TYPE :
1379
			case Binding.WILDCARD_TYPE :
1380
			case Binding.INTERSECTION_TYPE:
1381
				return null;
1382
			default :
1383
				if (typeBinding.isCapture())
1384
					return null;
1385
		}
1386
		ReferenceBinding referenceBinding;
1387
		if (typeBinding.isParameterizedType() || typeBinding.isRawType())
1388
			referenceBinding = (ReferenceBinding) typeBinding.erasure();
1389
		else
1390
			referenceBinding = (ReferenceBinding) typeBinding;
1391
		char[] fileName = referenceBinding.getFileName();
1392
		if (referenceBinding.isLocalType() || referenceBinding.isAnonymousType()) {
1393
			// local or anonymous type
1394
			if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(fileName)) {
1395
				int jarSeparator = CharOperation.indexOf(IDependent.JAR_FILE_ENTRY_SEPARATOR, fileName);
1396
				int pkgEnd = CharOperation.lastIndexOf('/', fileName); // pkgEnd is exclusive
1397
				if (pkgEnd == -1)
1398
					pkgEnd = CharOperation.lastIndexOf(File.separatorChar, fileName);
1399
				if (jarSeparator != -1 && pkgEnd < jarSeparator) // if in a jar and no slash, it is a default package -> pkgEnd should be equal to jarSeparator
1400
					pkgEnd = jarSeparator;
1401
				if (pkgEnd == -1)
1402
					return null;
1403
				IPackageFragment pkg = getPackageFragment(fileName, pkgEnd, jarSeparator);
1404
				char[] constantPoolName = referenceBinding.constantPoolName();
1405
				if (constantPoolName == null) {
1406
					ClassFile classFile = (ClassFile) getClassFile(fileName);
1407
					return classFile == null ? null : (JavaElement) classFile.getType();
1408
				}
1409
				pkgEnd = CharOperation.lastIndexOf('/', constantPoolName);
1410
				char[] classFileName = CharOperation.subarray(constantPoolName, pkgEnd+1, constantPoolName.length);
1411
				ClassFile classFile = (ClassFile) pkg.getClassFile(new String(classFileName) + SuffixConstants.SUFFIX_STRING_class);
1412
				return (JavaElement) classFile.getType();
1413
			}
1414
			ICompilationUnit cu = getCompilationUnit(fileName, workingCopyOwner);
1415
			if (cu == null) return null;
1416
			// must use getElementAt(...) as there is no back pointer to the defining method (scope is null after resolution has ended)
1417
			try {
1418
				int sourceStart = ((org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding) referenceBinding).sourceStart;
1419
				return (JavaElement) cu.getElementAt(sourceStart);
1420
			} catch (JavaModelException e) {
1421
				// does not exist
1422
				return null;
1423
			}
1424
		} else if (referenceBinding.isTypeVariable()) {
1425
			// type parameter
1426
			final String typeVariableName = new String(referenceBinding.sourceName());
1427
			org.eclipse.jdt.internal.compiler.lookup.Binding declaringElement = ((org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding) referenceBinding).declaringElement;
1428
			if (declaringElement instanceof MethodBinding) {
1429
				IMethod declaringMethod = (IMethod) getUnresolvedJavaElement((MethodBinding) declaringElement, workingCopyOwner, bindingsToNodes);
1430
				return (JavaElement) declaringMethod.getTypeParameter(typeVariableName);
1431
			} else {
1432
				IType declaringType = (IType) getUnresolvedJavaElement((TypeBinding) declaringElement, workingCopyOwner, bindingsToNodes);
1433
				return (JavaElement) declaringType.getTypeParameter(typeVariableName);
1434
			}
1435
		} else {
1436
			if (fileName == null) return null; // case of a WilCardBinding that doesn't have a corresponding Java element
1437
			// member or top level type
1438
			TypeBinding declaringTypeBinding = typeBinding.enclosingType();
1439
			if (declaringTypeBinding == null) {
1440
				// top level type
1441
				if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(fileName)) {
1442
					ClassFile classFile = (ClassFile) getClassFile(fileName);
1443
					if (classFile == null) return null;
1444
					return (JavaElement) classFile.getType();
1445
				}
1446
				ICompilationUnit cu = getCompilationUnit(fileName, workingCopyOwner);
1447
				if (cu == null) return null;
1448
				return (JavaElement) cu.getType(new String(referenceBinding.sourceName()));
1449
			} else {
1450
				// member type
1451
				IType declaringType = (IType) getUnresolvedJavaElement(declaringTypeBinding, workingCopyOwner, bindingsToNodes);
1452
				if (declaringType == null) return null;
1453
				return (JavaElement) declaringType.getType(new String(referenceBinding.sourceName()));
1454
			}
1455
		}
1456
	}
1457
	
1458
	/*
1208
	 * Returns the index of the most specific argument paths which is strictly enclosing the path to check
1459
	 * Returns the index of the most specific argument paths which is strictly enclosing the path to check
1209
	 */
1460
	 */
1210
	public static int indexOfEnclosingPath(IPath checkedPath, IPath[] paths, int pathCount) {
1461
	public static int indexOfEnclosingPath(IPath checkedPath, IPath[] paths, int pathCount) {
(-)codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java (-9 / +36 lines)
Lines 23-30 Link Here
23
import org.eclipse.jdt.core.IJavaProject;
23
import org.eclipse.jdt.core.IJavaProject;
24
import org.eclipse.jdt.core.IMethod;
24
import org.eclipse.jdt.core.IMethod;
25
import org.eclipse.jdt.core.IType;
25
import org.eclipse.jdt.core.IType;
26
import org.eclipse.jdt.core.ITypeRoot;
26
import org.eclipse.jdt.core.JavaModelException;
27
import org.eclipse.jdt.core.JavaModelException;
27
import org.eclipse.jdt.core.Signature;
28
import org.eclipse.jdt.core.Signature;
29
import org.eclipse.jdt.core.WorkingCopyOwner;
28
import org.eclipse.jdt.core.compiler.CategorizedProblem;
30
import org.eclipse.jdt.core.compiler.CategorizedProblem;
29
import org.eclipse.jdt.core.compiler.CharOperation;
31
import org.eclipse.jdt.core.compiler.CharOperation;
30
import org.eclipse.jdt.core.compiler.IProblem;
32
import org.eclipse.jdt.core.compiler.IProblem;
Lines 288-294 Link Here
288
	
290
	
289
	long targetedElement;
291
	long targetedElement;
290
	
292
	
293
	WorkingCopyOwner owner;
291
	IJavaProject javaProject;
294
	IJavaProject javaProject;
295
	ITypeRoot typeRoot; 
292
	CompletionParser parser;
296
	CompletionParser parser;
293
	CompletionRequestor requestor;
297
	CompletionRequestor requestor;
294
	CompletionProblemFactory problemFactory;
298
	CompletionProblemFactory problemFactory;
Lines 398-404 Link Here
398
			SearchableEnvironment nameEnvironment,
402
			SearchableEnvironment nameEnvironment,
399
			CompletionRequestor requestor,
403
			CompletionRequestor requestor,
400
			Map settings,
404
			Map settings,
401
			IJavaProject javaProject) {
405
			IJavaProject javaProject,
406
			WorkingCopyOwner owner) {
402
		super(settings);
407
		super(settings);
403
		this.javaProject = javaProject;
408
		this.javaProject = javaProject;
404
		this.requestor = requestor;
409
		this.requestor = requestor;
Lines 413-419 Link Here
413
		this.lookupEnvironment =
418
		this.lookupEnvironment =
414
			new LookupEnvironment(this, this.compilerOptions, this.problemReporter, nameEnvironment);
419
			new LookupEnvironment(this, this.compilerOptions, this.problemReporter, nameEnvironment);
415
		this.parser =
420
		this.parser =
416
			new CompletionParser(this.problemReporter);
421
			new CompletionParser(this.problemReporter, this.requestor.isExtendedContextRequired());
417
		this.nameScanner =
422
		this.nameScanner =
418
			new Scanner(
423
			new Scanner(
419
				false /*comment*/, 
424
				false /*comment*/, 
Lines 423-428 Link Here
423
				null /*taskTags*/, 
428
				null /*taskTags*/, 
424
				null/*taskPriorities*/,
429
				null/*taskPriorities*/,
425
				true/*taskCaseSensitive*/);
430
				true/*taskCaseSensitive*/);
431
		this.owner = owner;
426
	}
432
	}
427
433
428
	/**
434
	/**
Lines 859-867 Link Here
859
	private void buildContext(
865
	private void buildContext(
860
			ASTNode astNode,
866
			ASTNode astNode,
861
			ASTNode astNodeParent,
867
			ASTNode astNodeParent,
868
			CompilationUnitDeclaration compilationUnitDeclaration,
862
			Binding qualifiedBinding,
869
			Binding qualifiedBinding,
863
			Scope scope) {
870
			Scope scope) {
864
		CompletionContext context = new CompletionContext();
871
		CompletionContext context = new CompletionContext();
872
		if (this.requestor.isExtendedContextRequired()) {
873
			context.setExtendedData(
874
					this.typeRoot,
875
					compilationUnitDeclaration,
876
					this.lookupEnvironment,
877
					scope,
878
					astNode,
879
					this.owner,
880
					this.parser);
881
		}
865
		
882
		
866
		// build expected types context
883
		// build expected types context
867
		if (this.expectedTypesPtr > -1) {
884
		if (this.expectedTypesPtr > -1) {
Lines 974-980 Link Here
974
		}
991
		}
975
	}
992
	}
976
993
977
	private boolean complete(ASTNode astNode, ASTNode astNodeParent, ASTNode enclosingNode, Binding qualifiedBinding, Scope scope, boolean insideTypeAnnotation) {
994
	private boolean complete(
995
			ASTNode astNode,
996
			ASTNode astNodeParent,
997
			ASTNode enclosingNode,
998
			CompilationUnitDeclaration compilationUnitDeclaration,
999
			Binding qualifiedBinding,
1000
			Scope scope,
1001
			boolean insideTypeAnnotation) {
978
1002
979
		setSourceAndTokenRange(astNode.sourceStart, astNode.sourceEnd);
1003
		setSourceAndTokenRange(astNode.sourceStart, astNode.sourceEnd);
980
1004
Lines 985-991 Link Here
985
			computeExpectedTypes(astNodeParent, astNode, scope);
1009
			computeExpectedTypes(astNodeParent, astNode, scope);
986
		}
1010
		}
987
		
1011
		
988
		buildContext(astNode, astNodeParent, qualifiedBinding, scope);
1012
		buildContext(astNode, astNodeParent, compilationUnitDeclaration, qualifiedBinding, scope);
989
		
1013
		
990
		if (astNode instanceof CompletionOnFieldType) {
1014
		if (astNode instanceof CompletionOnFieldType) {
991
1015
Lines 2191-2196 Link Here
2191
									e.astNode,
2215
									e.astNode,
2192
									this.parser.assistNodeParent,
2216
									this.parser.assistNodeParent,
2193
									this.parser.enclosingNode,
2217
									this.parser.enclosingNode,
2218
									compilationUnit,
2194
									e.qualifiedBinding,
2219
									e.qualifiedBinding,
2195
									e.scope,
2220
									e.scope,
2196
									e.insideTypeAnnotation);
2221
									e.insideTypeAnnotation);
Lines 2290-2296 Link Here
2290
	 *      a position in the source where the completion is taking place. 
2315
	 *      a position in the source where the completion is taking place. 
2291
	 *      This position is relative to the source provided.
2316
	 *      This position is relative to the source provided.
2292
	 */
2317
	 */
2293
	public void complete(ICompilationUnit sourceUnit, int completionPosition, int pos) {
2318
	public void complete(ICompilationUnit sourceUnit, int completionPosition, int pos, ITypeRoot root) {
2294
2319
2295
		if(DEBUG) {
2320
		if(DEBUG) {
2296
			System.out.print("COMPLETION IN "); //$NON-NLS-1$
2321
			System.out.print("COMPLETION IN "); //$NON-NLS-1$
Lines 2306-2311 Link Here
2306
			this.fileName = sourceUnit.getFileName();
2331
			this.fileName = sourceUnit.getFileName();
2307
			this.actualCompletionPosition = completionPosition - 1;
2332
			this.actualCompletionPosition = completionPosition - 1;
2308
			this.offset = pos;
2333
			this.offset = pos;
2334
			this.typeRoot = root;
2309
			// for now until we can change the UI.
2335
			// for now until we can change the UI.
2310
			CompilationResult result = new CompilationResult(sourceUnit, 1, 1, this.compilerOptions.maxProblemsPerUnit);
2336
			CompilationResult result = new CompilationResult(sourceUnit, 1, 1, this.compilerOptions.maxProblemsPerUnit);
2311
			CompilationUnitDeclaration parsedUnit = this.parser.dietParse(sourceUnit, result, this.actualCompletionPosition);
2337
			CompilationUnitDeclaration parsedUnit = this.parser.dietParse(sourceUnit, result, this.actualCompletionPosition);
Lines 2320-2326 Link Here
2320
				// scan the package & import statements first
2346
				// scan the package & import statements first
2321
				if (parsedUnit.currentPackage instanceof CompletionOnPackageReference) {
2347
				if (parsedUnit.currentPackage instanceof CompletionOnPackageReference) {
2322
					contextAccepted = true;
2348
					contextAccepted = true;
2323
					this.buildContext(parsedUnit.currentPackage, null, null, null);
2349
					this.buildContext(parsedUnit.currentPackage, null, parsedUnit, null, null);
2324
					if(!this.requestor.isIgnored(CompletionProposal.PACKAGE_REF)) {
2350
					if(!this.requestor.isIgnored(CompletionProposal.PACKAGE_REF)) {
2325
						findPackages((CompletionOnPackageReference) parsedUnit.currentPackage);
2351
						findPackages((CompletionOnPackageReference) parsedUnit.currentPackage);
2326
					}
2352
					}
Lines 2341-2347 Link Here
2341
							this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/);
2367
							this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/);
2342
							if ((this.unitScope = parsedUnit.scope) != null) {
2368
							if ((this.unitScope = parsedUnit.scope) != null) {
2343
								contextAccepted = true;
2369
								contextAccepted = true;
2344
								this.buildContext(importReference, null, null, null);
2370
								this.buildContext(importReference, null, parsedUnit, null, null);
2345
								
2371
								
2346
								long positions = importReference.sourcePositions[importReference.sourcePositions.length - 1];
2372
								long positions = importReference.sourcePositions[importReference.sourcePositions.length - 1];
2347
								setSourceAndTokenRange((int) (positions >>> 32), (int) positions);
2373
								setSourceAndTokenRange((int) (positions >>> 32), (int) positions);
Lines 2389-2395 Link Here
2389
							return;
2415
							return;
2390
						} else if(importReference instanceof CompletionOnKeyword) {
2416
						} else if(importReference instanceof CompletionOnKeyword) {
2391
							contextAccepted = true;
2417
							contextAccepted = true;
2392
							this.buildContext(importReference, null, null, null);
2418
							this.buildContext(importReference, null, parsedUnit, null, null);
2393
							if(!this.requestor.isIgnored(CompletionProposal.KEYWORD)) {
2419
							if(!this.requestor.isIgnored(CompletionProposal.KEYWORD)) {
2394
								setSourceAndTokenRange(importReference.sourceStart, importReference.sourceEnd);
2420
								setSourceAndTokenRange(importReference.sourceStart, importReference.sourceEnd);
2395
								CompletionOnKeyword keyword = (CompletionOnKeyword)importReference;
2421
								CompletionOnKeyword keyword = (CompletionOnKeyword)importReference;
Lines 2438-2443 Link Here
2438
									e.astNode,
2464
									e.astNode,
2439
									this.parser.assistNodeParent,
2465
									this.parser.assistNodeParent,
2440
									this.parser.enclosingNode,
2466
									this.parser.enclosingNode,
2467
									parsedUnit,
2441
									e.qualifiedBinding,
2468
									e.qualifiedBinding,
2442
									e.scope,
2469
									e.scope,
2443
									e.insideTypeAnnotation);
2470
									e.insideTypeAnnotation);
Lines 8710-8716 Link Here
8710
8737
8711
	protected void reset() {
8738
	protected void reset() {
8712
8739
8713
		super.reset();
8740
		super.reset(false);
8714
		this.knownPkgs = new HashtableOfObject(10);
8741
		this.knownPkgs = new HashtableOfObject(10);
8715
		this.knownTypes = new HashtableOfObject(10);
8742
		this.knownTypes = new HashtableOfObject(10);
8716
	}
8743
	}
(-)codeassist/org/eclipse/jdt/internal/codeassist/InternalCompletionContext.java (-14 / +45 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.codeassist;
11
package org.eclipse.jdt.internal.codeassist;
12
12
13
import org.eclipse.jdt.core.ITypeRoot;
14
import org.eclipse.jdt.core.WorkingCopyOwner;
15
import org.eclipse.jdt.internal.codeassist.complete.CompletionParser;
16
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
17
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
18
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
19
import org.eclipse.jdt.internal.compiler.lookup.Scope;
20
13
21
14
/**
22
/**
15
 * Internal completion context
23
 * Internal completion context
Lines 27-38 Link Here
27
	protected int tokenKind;
35
	protected int tokenKind;
28
	protected int tokenLocation;
36
	protected int tokenLocation;
29
	
37
	
38
	protected InternalExtendedCompletionContext extendedContext;
39
	
40
	protected void setExpectedTypesKeys(char[][] expectedTypesKeys) {
41
		this.expectedTypesKeys = expectedTypesKeys;
42
	}
43
	
30
	protected void setExpectedTypesSignatures(char[][] expectedTypesSignatures) {
44
	protected void setExpectedTypesSignatures(char[][] expectedTypesSignatures) {
31
		this.expectedTypesSignatures = expectedTypesSignatures;
45
		this.expectedTypesSignatures = expectedTypesSignatures;
32
	}
46
	}
33
	
47
	
34
	protected void setExpectedTypesKeys(char[][] expectedTypesKeys) {
48
	protected void setExtendedData(
35
		this.expectedTypesKeys = expectedTypesKeys;
49
			ITypeRoot typeRoot,
50
			CompilationUnitDeclaration compilationUnitDeclaration,
51
			LookupEnvironment lookupEnvironment,
52
			Scope scope,
53
			ASTNode astNode,
54
			WorkingCopyOwner owner,
55
			CompletionParser parser) {
56
		this.extendedContext =
57
			new InternalExtendedCompletionContext(
58
					this,
59
					typeRoot,
60
					compilationUnitDeclaration,
61
					lookupEnvironment,
62
					scope,
63
					astNode,
64
					owner,
65
					parser);
36
	}
66
	}
37
67
38
	protected void setJavadoc(int javadoc) {
68
	protected void setJavadoc(int javadoc) {
Lines 42-51 Link Here
42
	protected void setOffset(int offset) {
72
	protected void setOffset(int offset) {
43
		this.offset = offset;
73
		this.offset = offset;
44
	}
74
	}
75
76
	protected void setToken(char[] token) {
77
		this.token = token;
78
	}
79
80
	protected void setTokenKind(int tokenKind) {
81
		this.tokenKind = tokenKind;
82
	}
45
	
83
	
84
	protected void setTokenLocation(int tokenLocation) {
85
		this.tokenLocation = tokenLocation;
86
	}
87
46
	protected void setTokenRange(int start, int end) {
88
	protected void setTokenRange(int start, int end) {
47
		this.setTokenRange(start, end, -1);
89
		this.setTokenRange(start, end, -1);
48
	}
90
	}
91
49
	protected void setTokenRange(int start, int end, int endOfEmptyToken) {
92
	protected void setTokenRange(int start, int end, int endOfEmptyToken) {
50
		this.tokenStart = start;
93
		this.tokenStart = start;
51
		this.tokenEnd = endOfEmptyToken > end ? endOfEmptyToken : end;
94
		this.tokenEnd = endOfEmptyToken > end ? endOfEmptyToken : end;
Lines 57-72 Link Here
57
			this.tokenEnd = 0;
100
			this.tokenEnd = 0;
58
		}
101
		}
59
	}
102
	}
60
	
61
	protected void setToken(char[] token) {
62
		this.token = token;
63
	}
64
	
65
	protected void setTokenKind(int tokenKind) {
66
		this.tokenKind = tokenKind;
67
	}
68
	
69
	protected void setTokenLocation(int tokenLocation) {
70
		this.tokenLocation = tokenLocation;
71
	}
72
}
103
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java (-2 / +2 lines)
Lines 737-743 Link Here
737
				e.printStackTrace(System.out);
737
				e.printStackTrace(System.out);
738
			}
738
			}
739
		} finally {
739
		} finally {
740
			reset();
740
			reset(true);
741
		}
741
		}
742
	}
742
	}
743
743
Lines 1193-1199 Link Here
1193
			}
1193
			}
1194
		} catch (AbortCompilation e) { // ignore this exception for now since it typically means we cannot find java.lang.Object
1194
		} catch (AbortCompilation e) { // ignore this exception for now since it typically means we cannot find java.lang.Object
1195
		} finally {
1195
		} finally {
1196
			reset();
1196
			reset(true);
1197
		}
1197
		}
1198
	}
1198
	}
1199
1199
(-)model/org/eclipse/jdt/internal/core/eval/EvaluationContextWrapper.java (-1 / +2 lines)
Lines 110-116 Link Here
110
		environment,
110
		environment,
111
		requestor,
111
		requestor,
112
		this.project.getOptions(true),
112
		this.project.getOptions(true),
113
		this.project
113
		this.project,
114
		owner
114
	);
115
	);
115
}
116
}
116
/**
117
/**
(-)search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexer.java (-1 / +1 lines)
Lines 50-56 Link Here
50
			IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0));
50
			IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0));
51
			parser = JavaModelManager.getJavaModelManager().indexManager.getSourceElementParser(JavaCore.create(project), requestor);
51
			parser = JavaModelManager.getJavaModelManager().indexManager.getSourceElementParser(JavaCore.create(project), requestor);
52
		} else {
52
		} else {
53
			parser.requestor = requestor;
53
			parser.setRequestor(requestor);
54
		}
54
		}
55
		
55
		
56
		// Launch the parser
56
		// Launch the parser
(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/Engine.java (-2 / +2 lines)
Lines 309-316 Link Here
309
		return null;
309
		return null;
310
	}
310
	}
311
311
312
	protected void reset() {
312
	protected void reset(boolean resetLookupEnvironment) {
313
		lookupEnvironment.reset();
313
		if (resetLookupEnvironment) lookupEnvironment.reset();
314
	}
314
	}
315
315
316
	public static char[] getTypeSignature(TypeBinding typeBinding) {
316
	public static char[] getTypeSignature(TypeBinding typeBinding) {
(-)model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java (+6 lines)
Lines 11-19 Link Here
11
package org.eclipse.jdt.internal.compiler;
11
package org.eclipse.jdt.internal.compiler;
12
12
13
import org.eclipse.jdt.core.compiler.CategorizedProblem;
13
import org.eclipse.jdt.core.compiler.CategorizedProblem;
14
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
14
import org.eclipse.jdt.internal.compiler.ast.Annotation;
15
import org.eclipse.jdt.internal.compiler.ast.Annotation;
15
import org.eclipse.jdt.internal.compiler.ast.Expression;
16
import org.eclipse.jdt.internal.compiler.ast.Expression;
17
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
16
import org.eclipse.jdt.internal.compiler.ast.ImportReference;
18
import org.eclipse.jdt.internal.compiler.ast.ImportReference;
19
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
17
20
18
/*
21
/*
19
 * Part of the source element parser responsible for building the output. It
22
 * Part of the source element parser responsible for building the output. It
Lines 54-59 Link Here
54
		public boolean secondary;
57
		public boolean secondary;
55
		public boolean anonymousMember;
58
		public boolean anonymousMember;
56
		public Annotation[] annotations;
59
		public Annotation[] annotations;
60
		public TypeDeclaration node;
57
	}
61
	}
58
	
62
	
59
	public static class TypeParameterInfo {
63
	public static class TypeParameterInfo {
Lines 80-85 Link Here
80
		public TypeParameterInfo[] typeParameters;
84
		public TypeParameterInfo[] typeParameters;
81
		public char[][] categories;
85
		public char[][] categories;
82
		public Annotation[] annotations;
86
		public Annotation[] annotations;
87
		public AbstractMethodDeclaration node;
83
	}
88
	}
84
	
89
	
85
	public static class FieldInfo {
90
	public static class FieldInfo {
Lines 91-96 Link Here
91
		public int nameSourceEnd;
96
		public int nameSourceEnd;
92
		public char[][] categories;
97
		public char[][] categories;
93
		public Annotation[] annotations;
98
		public Annotation[] annotations;
99
		public FieldDeclaration node;
94
	}
100
	}
95
101
96
	void acceptAnnotationTypeReference(char[][] annotation, int sourceStart, int sourceEnd);
102
	void acceptAnnotationTypeReference(char[][] annotation, int sourceStart, int sourceEnd);
(-)model/org/eclipse/jdt/internal/compiler/SourceElementParser.java (-685 / +19 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler;
11
package org.eclipse.jdt.internal.compiler;
12
12
13
import java.util.ArrayList;
14
import java.util.HashMap;
13
import java.util.HashMap;
15
14
16
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.IProgressMonitor;
Lines 46-91 Link Here
46
 */
45
 */
47
public class SourceElementParser extends CommentRecorderParser {
46
public class SourceElementParser extends CommentRecorderParser {
48
	
47
	
49
	public ISourceElementRequestor requestor;
48
	ISourceElementRequestor requestor;
50
	ISourceType sourceType;
51
	boolean reportReferenceInfo;
49
	boolean reportReferenceInfo;
52
	char[][] typeNames;
50
	boolean reportLocalDeclarations;
53
	char[][] superTypeNames;
54
	int nestedTypeIndex;
55
	LocalDeclarationVisitor localDeclarationVisitor = null;
56
	HashtableOfObjectToInt sourceEnds = new HashtableOfObjectToInt();
51
	HashtableOfObjectToInt sourceEnds = new HashtableOfObjectToInt();
57
	HashMap nodesToCategories = new HashMap(); // a map from ASTNode to char[][]
52
	HashMap nodesToCategories = new HashMap(); // a map from ASTNode to char[][]
58
	boolean useSourceJavadocParser = true;
53
	boolean useSourceJavadocParser = true;
59
	
54
	
60
/**
55
	SourceElementNotifier notifier;
61
 * An ast visitor that visits local type declarations.
62
 */
63
public class LocalDeclarationVisitor extends ASTVisitor {
64
	ArrayList declaringTypes;
65
	public void pushDeclaringType(TypeDeclaration declaringType) {
66
		if (this.declaringTypes == null) {
67
			this.declaringTypes = new ArrayList();
68
		}
69
		this.declaringTypes.add(declaringType);
70
	}
71
	public void popDeclaringType() {
72
		this.declaringTypes.remove(this.declaringTypes.size()-1);
73
	}
74
	public TypeDeclaration peekDeclaringType() {
75
		if (this.declaringTypes == null) return null;
76
		int size = this.declaringTypes.size();
77
		if (size == 0) return null;
78
		return (TypeDeclaration) this.declaringTypes.get(size-1);
79
	}
80
	public boolean visit(TypeDeclaration typeDeclaration, BlockScope scope) {
81
		notifySourceElementRequestor(typeDeclaration, sourceType == null, peekDeclaringType());
82
		return false; // don't visit members as this was done during notifySourceElementRequestor(...)
83
	}
84
	public boolean visit(TypeDeclaration typeDeclaration, ClassScope scope) {
85
		notifySourceElementRequestor(typeDeclaration, sourceType == null, peekDeclaringType());
86
		return false; // don't visit members as this was done during notifySourceElementRequestor(...)
87
	}	
88
}
89
56
90
public SourceElementParser(
57
public SourceElementParser(
91
		final ISourceElementRequestor requestor, 
58
		final ISourceElementRequestor requestor, 
Lines 111-116 Link Here
111
			problemFactory),
78
			problemFactory),
112
		optimizeStringLiterals);
79
		optimizeStringLiterals);
113
	
80
	
81
	this.reportLocalDeclarations = reportLocalDeclarations;
82
	
114
	// we want to notify all syntax error with the acceptProblem API
83
	// we want to notify all syntax error with the acceptProblem API
115
	// To do so, we define the record method of the ProblemReporter
84
	// To do so, we define the record method of the ProblemReporter
116
	this.problemReporter = new ProblemReporter(
85
	this.problemReporter = new ProblemReporter(
Lines 123-135 Link Here
123
		}
92
		}
124
	};
93
	};
125
	this.requestor = requestor;
94
	this.requestor = requestor;
126
	typeNames = new char[4][];
127
	superTypeNames = new char[4][];
128
	nestedTypeIndex = 0;
129
	this.options = options;
95
	this.options = options;
130
	if (reportLocalDeclarations) {
96
	
131
		this.localDeclarationVisitor = new LocalDeclarationVisitor();
97
	this.notifier = new SourceElementNotifier(this.requestor, reportLocalDeclarations);
132
	}
98
	
133
	// set specific javadoc parser
99
	// set specific javadoc parser
134
	this.useSourceJavadocParser = useSourceJavadocParser;
100
	this.useSourceJavadocParser = useSourceJavadocParser;
135
	if (useSourceJavadocParser) {
101
	if (useSourceJavadocParser) {
Lines 735-756 Link Here
735
	return methodDeclaration;
701
	return methodDeclaration;
736
}
702
}
737
protected CompilationUnitDeclaration endParse(int act) {
703
protected CompilationUnitDeclaration endParse(int act) {
738
	if (sourceType != null) {
739
		switch (TypeDeclaration.kind(sourceType.getModifiers())) {
740
			case TypeDeclaration.CLASS_DECL :
741
				consumeClassDeclaration();
742
				break;
743
			case TypeDeclaration.INTERFACE_DECL :
744
				consumeInterfaceDeclaration();
745
				break;
746
			case TypeDeclaration.ENUM_DECL :
747
				consumeEnumDeclaration();
748
				break;
749
			case TypeDeclaration.ANNOTATION_TYPE_DECL :
750
				consumeAnnotationTypeDeclaration();
751
				break;
752
		}
753
	}
754
	if (compilationUnit != null) {
704
	if (compilationUnit != null) {
755
		CompilationUnitDeclaration result = super.endParse(act);
705
		CompilationUnitDeclaration result = super.endParse(act);
756
		return result;
706
		return result;
Lines 758-799 Link Here
758
		return null;
708
		return null;
759
	}		
709
	}		
760
}
710
}
761
private ISourceElementRequestor.TypeParameterInfo[] getTypeParameterInfos(TypeParameter[] typeParameters) {
762
	if (typeParameters == null) return null;
763
	int typeParametersLength = typeParameters.length;
764
	ISourceElementRequestor.TypeParameterInfo[] result = new ISourceElementRequestor.TypeParameterInfo[typeParametersLength];
765
	for (int i = 0; i < typeParametersLength; i++) {
766
		TypeParameter typeParameter = typeParameters[i];
767
		TypeReference firstBound = typeParameter.type;
768
		TypeReference[] otherBounds = typeParameter.bounds;
769
		char[][] typeParameterBounds = null;
770
		if (firstBound != null) {
771
			if (otherBounds != null) {
772
				int otherBoundsLength = otherBounds.length;
773
				char[][] boundNames = new char[otherBoundsLength+1][];
774
				boundNames[0] = CharOperation.concatWith(firstBound.getParameterizedTypeName(), '.');
775
				for (int j = 0; j < otherBoundsLength; j++) {
776
					boundNames[j+1] = 
777
						CharOperation.concatWith(otherBounds[j].getParameterizedTypeName(), '.'); 
778
				}
779
				typeParameterBounds = boundNames;
780
			} else {
781
				typeParameterBounds = new char[][] { CharOperation.concatWith(firstBound.getParameterizedTypeName(), '.')};
782
			}
783
		} else {
784
			typeParameterBounds = CharOperation.NO_CHAR_CHAR;
785
		}
786
		ISourceElementRequestor.TypeParameterInfo typeParameterInfo = new ISourceElementRequestor.TypeParameterInfo();
787
		typeParameterInfo.declarationStart = typeParameter.declarationSourceStart;
788
		typeParameterInfo.declarationEnd = typeParameter.declarationSourceEnd;
789
		typeParameterInfo.name = typeParameter.name;
790
		typeParameterInfo.nameSourceStart = typeParameter.sourceStart;
791
		typeParameterInfo.nameSourceEnd = typeParameter.sourceEnd;
792
		typeParameterInfo.bounds = typeParameterBounds;
793
		result[i] = typeParameterInfo;
794
	}
795
	return result;
796
}
797
public TypeReference getTypeReference(int dim) {
711
public TypeReference getTypeReference(int dim) {
798
	/* build a Reference on a variable that may be qualified or not
712
	/* build a Reference on a variable that may be qualified or not
799
	 * This variable is a type reference and dim will be its dimensions
713
	 * This variable is a type reference and dim will be its dimensions
Lines 962-984 Link Here
962
	}
876
	}
963
	return ref;
877
	return ref;
964
}
878
}
965
966
/*
967
 * Checks whether one of the annotations is the @Deprecated annotation
968
 * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89807)
969
 */
970
private boolean hasDeprecatedAnnotation(Annotation[] annotations) {
971
	if (annotations != null) {
972
		for (int i = 0, length = annotations.length; i < length; i++) {
973
			Annotation annotation = annotations[i];
974
			if (CharOperation.equals(annotation.type.getLastToken(), TypeConstants.JAVA_LANG_DEPRECATED[2])) {
975
				return true;
976
			}
977
		}
978
	}
979
	return false;
980
}
981
982
protected ImportReference newImportReference(char[][] tokens, long[] positions, boolean onDemand, int mod) {
879
protected ImportReference newImportReference(char[][] tokens, long[] positions, boolean onDemand, int mod) {
983
	return new ImportReference(tokens, positions, onDemand, mod);
880
	return new ImportReference(tokens, positions, onDemand, mod);
984
}
881
}
Lines 988-1485 Link Here
988
protected SingleNameReference newSingleNameReference(char[] source, long positions) {
885
protected SingleNameReference newSingleNameReference(char[] source, long positions) {
989
	return new SingleNameReference(source, positions);
886
	return new SingleNameReference(source, positions);
990
}
887
}
991
/*
992
 * Update the bodyStart of the corresponding parse node
993
 */
994
public void notifySourceElementRequestor(CompilationUnitDeclaration parsedUnit) {
995
	if (parsedUnit == null) {
996
		// when we parse a single type member declaration the compilation unit is null, but we still
997
		// want to be able to notify the requestor on the created ast node
998
		if (astStack[0] instanceof AbstractMethodDeclaration) {
999
			notifySourceElementRequestor((AbstractMethodDeclaration) astStack[0]);
1000
			return;
1001
		}
1002
		return;
1003
	}
1004
	// range check
1005
	boolean isInRange = 
1006
				scanner.initialPosition <= parsedUnit.sourceStart
1007
				&& scanner.eofPosition >= parsedUnit.sourceEnd;
1008
	
1009
	// collect the top level ast nodes
1010
	int length = 0;
1011
	ASTNode[] nodes = null;
1012
	if (sourceType == null){
1013
		if (isInRange) {
1014
			requestor.enterCompilationUnit();
1015
		}
1016
		ImportReference currentPackage = parsedUnit.currentPackage;
1017
		ImportReference[] imports = parsedUnit.imports;
1018
		TypeDeclaration[] types = parsedUnit.types;
1019
		length = 
1020
			(currentPackage == null ? 0 : 1) 
1021
			+ (imports == null ? 0 : imports.length)
1022
			+ (types == null ? 0 : types.length);
1023
		nodes = new ASTNode[length];
1024
		int index = 0;
1025
		if (currentPackage != null) {
1026
			nodes[index++] = currentPackage;
1027
		}
1028
		if (imports != null) {
1029
			for (int i = 0, max = imports.length; i < max; i++) {
1030
				nodes[index++] = imports[i];
1031
			}
1032
		}
1033
		if (types != null) {
1034
			for (int i = 0, max = types.length; i < max; i++) {
1035
				nodes[index++] = types[i];
1036
			}
1037
		}
1038
	} else {
1039
		TypeDeclaration[] types = parsedUnit.types;
1040
		if (types != null) {
1041
			length = types.length;
1042
			nodes = new ASTNode[length];
1043
			for (int i = 0, max = types.length; i < max; i++) {
1044
				nodes[i] = types[i];
1045
			}
1046
		}
1047
	}
1048
	
1049
	// notify the nodes in the syntactical order
1050
	if (nodes != null && length > 0) {
1051
		quickSort(nodes, 0, length-1);
1052
		for (int i=0;i<length;i++) {
1053
			ASTNode node = nodes[i];
1054
			if (node instanceof ImportReference) {
1055
				ImportReference importRef = (ImportReference)node;
1056
				if (node == parsedUnit.currentPackage) {
1057
					notifySourceElementRequestor(importRef, true);
1058
				} else {
1059
					notifySourceElementRequestor(importRef, false);
1060
				}
1061
			} else { // instanceof TypeDeclaration
1062
				notifySourceElementRequestor((TypeDeclaration)node, sourceType == null, null);
1063
			}
1064
		}
1065
	}
1066
	
1067
	if (sourceType == null){
1068
		if (isInRange) {
1069
			requestor.exitCompilationUnit(parsedUnit.sourceEnd);
1070
		}
1071
	}
1072
}
1073
1074
/*
1075
 * Update the bodyStart of the corresponding parse node
1076
 */
1077
public void notifySourceElementRequestor(AbstractMethodDeclaration methodDeclaration) {
1078
1079
	// range check
1080
	boolean isInRange = 
1081
				scanner.initialPosition <= methodDeclaration.declarationSourceStart
1082
				&& scanner.eofPosition >= methodDeclaration.declarationSourceEnd;
1083
1084
	if (methodDeclaration.isClinit()) {
1085
		this.visitIfNeeded(methodDeclaration);
1086
		return;
1087
	}
1088
1089
	if (methodDeclaration.isDefaultConstructor()) {
1090
		if (reportReferenceInfo) {
1091
			ConstructorDeclaration constructorDeclaration = (ConstructorDeclaration) methodDeclaration;
1092
			ExplicitConstructorCall constructorCall = constructorDeclaration.constructorCall;
1093
			if (constructorCall != null) {
1094
				switch(constructorCall.accessMode) {
1095
					case ExplicitConstructorCall.This :
1096
						requestor.acceptConstructorReference(
1097
							typeNames[nestedTypeIndex-1],
1098
							constructorCall.arguments == null ? 0 : constructorCall.arguments.length, 
1099
							constructorCall.sourceStart);
1100
						break;
1101
					case ExplicitConstructorCall.Super :
1102
					case ExplicitConstructorCall.ImplicitSuper :					
1103
						requestor.acceptConstructorReference(
1104
							superTypeNames[nestedTypeIndex-1],
1105
							constructorCall.arguments == null ? 0 : constructorCall.arguments.length, 
1106
							constructorCall.sourceStart);
1107
						break;
1108
				}
1109
			}
1110
		}	
1111
		return;	
1112
	}	
1113
	char[][] argumentTypes = null;
1114
	char[][] argumentNames = null;
1115
	boolean isVarArgs = false;
1116
	Argument[] arguments = methodDeclaration.arguments;
1117
	if (arguments != null) {
1118
		int argumentLength = arguments.length;
1119
		argumentTypes = new char[argumentLength][];
1120
		argumentNames = new char[argumentLength][];
1121
		for (int i = 0; i < argumentLength; i++) {
1122
			argumentTypes[i] = CharOperation.concatWith(arguments[i].type.getParameterizedTypeName(), '.');
1123
			argumentNames[i] = arguments[i].name;
1124
		}
1125
		isVarArgs = arguments[argumentLength-1].isVarArgs();
1126
	}
1127
	char[][] thrownExceptionTypes = null;
1128
	TypeReference[] thrownExceptions = methodDeclaration.thrownExceptions;
1129
	if (thrownExceptions != null) {
1130
		int thrownExceptionLength = thrownExceptions.length;
1131
		thrownExceptionTypes = new char[thrownExceptionLength][];
1132
		for (int i = 0; i < thrownExceptionLength; i++) {
1133
			thrownExceptionTypes[i] = 
1134
				CharOperation.concatWith(thrownExceptions[i].getParameterizedTypeName(), '.'); 
1135
		}
1136
	}
1137
	// by default no selector end position
1138
	int selectorSourceEnd = -1;
1139
	if (methodDeclaration.isConstructor()) {
1140
		selectorSourceEnd = this.sourceEnds.get(methodDeclaration);
1141
		if (isInRange){
1142
			int currentModifiers = methodDeclaration.modifiers;
1143
			if (isVarArgs)
1144
				currentModifiers |= ClassFileConstants.AccVarargs;
1145
			
1146
			// remember deprecation so as to not lose it below
1147
			boolean deprecated = (currentModifiers & ClassFileConstants.AccDeprecated) != 0 || hasDeprecatedAnnotation(methodDeclaration.annotations);
1148
			
1149
			ISourceElementRequestor.MethodInfo methodInfo = new ISourceElementRequestor.MethodInfo();
1150
			methodInfo.isConstructor = true;
1151
			methodInfo.declarationStart = methodDeclaration.declarationSourceStart;
1152
			methodInfo.modifiers = deprecated ? (currentModifiers & ExtraCompilerModifiers.AccJustFlag) | ClassFileConstants.AccDeprecated : currentModifiers & ExtraCompilerModifiers.AccJustFlag;
1153
			methodInfo.name = methodDeclaration.selector;
1154
			methodInfo.nameSourceStart = methodDeclaration.sourceStart;
1155
			methodInfo.nameSourceEnd = selectorSourceEnd;
1156
			methodInfo.parameterTypes = argumentTypes;
1157
			methodInfo.parameterNames = argumentNames;
1158
			methodInfo.exceptionTypes = thrownExceptionTypes;
1159
			methodInfo.typeParameters = getTypeParameterInfos(methodDeclaration.typeParameters());
1160
			methodInfo.categories = (char[][]) this.nodesToCategories.get(methodDeclaration);
1161
			methodInfo.annotations = methodDeclaration.annotations;
1162
			requestor.enterConstructor(methodInfo);
1163
		}
1164
		if (reportReferenceInfo) {
1165
			ConstructorDeclaration constructorDeclaration = (ConstructorDeclaration) methodDeclaration;
1166
			ExplicitConstructorCall constructorCall = constructorDeclaration.constructorCall;
1167
			if (constructorCall != null) {
1168
				switch(constructorCall.accessMode) {
1169
					case ExplicitConstructorCall.This :
1170
						requestor.acceptConstructorReference(
1171
							typeNames[nestedTypeIndex-1],
1172
							constructorCall.arguments == null ? 0 : constructorCall.arguments.length, 
1173
							constructorCall.sourceStart);
1174
						break;
1175
					case ExplicitConstructorCall.Super :
1176
					case ExplicitConstructorCall.ImplicitSuper :
1177
						requestor.acceptConstructorReference(
1178
							superTypeNames[nestedTypeIndex-1],
1179
							constructorCall.arguments == null ? 0 : constructorCall.arguments.length, 
1180
							constructorCall.sourceStart);
1181
						break;
1182
				}
1183
			}
1184
		}
1185
		this.visitIfNeeded(methodDeclaration);
1186
		if (isInRange){
1187
			requestor.exitConstructor(methodDeclaration.declarationSourceEnd);
1188
		}
1189
		return;
1190
	}
1191
	selectorSourceEnd = this.sourceEnds.get(methodDeclaration);
1192
	if (isInRange) {
1193
		int currentModifiers = methodDeclaration.modifiers;
1194
		if (isVarArgs)
1195
			currentModifiers |= ClassFileConstants.AccVarargs;
1196
		
1197
		// remember deprecation so as to not lose it below
1198
		boolean deprecated = (currentModifiers & ClassFileConstants.AccDeprecated) != 0 || hasDeprecatedAnnotation(methodDeclaration.annotations);	
1199
			
1200
		TypeReference returnType = methodDeclaration instanceof MethodDeclaration
1201
			? ((MethodDeclaration) methodDeclaration).returnType
1202
			: null;
1203
		ISourceElementRequestor.MethodInfo methodInfo = new ISourceElementRequestor.MethodInfo();
1204
		methodInfo.isAnnotation = methodDeclaration instanceof AnnotationMethodDeclaration;
1205
		methodInfo.declarationStart = methodDeclaration.declarationSourceStart;
1206
		methodInfo.modifiers = deprecated ? (currentModifiers & ExtraCompilerModifiers.AccJustFlag) | ClassFileConstants.AccDeprecated : currentModifiers & ExtraCompilerModifiers.AccJustFlag;
1207
		methodInfo.returnType = returnType == null ? null : CharOperation.concatWith(returnType.getParameterizedTypeName(), '.');
1208
		methodInfo.name = methodDeclaration.selector;
1209
		methodInfo.nameSourceStart = methodDeclaration.sourceStart;
1210
		methodInfo.nameSourceEnd = selectorSourceEnd;
1211
		methodInfo.parameterTypes = argumentTypes;
1212
		methodInfo.parameterNames = argumentNames;
1213
		methodInfo.exceptionTypes = thrownExceptionTypes;
1214
		methodInfo.typeParameters = getTypeParameterInfos(methodDeclaration.typeParameters());
1215
		methodInfo.categories = (char[][]) this.nodesToCategories.get(methodDeclaration);
1216
		methodInfo.annotations = methodDeclaration.annotations;
1217
		requestor.enterMethod(methodInfo);
1218
	}		
1219
		
1220
	this.visitIfNeeded(methodDeclaration);
1221
1222
	if (isInRange) {
1223
		if (methodDeclaration instanceof AnnotationMethodDeclaration) {
1224
			AnnotationMethodDeclaration annotationMethodDeclaration = (AnnotationMethodDeclaration) methodDeclaration;
1225
			Expression expression = annotationMethodDeclaration.defaultValue;
1226
			if (expression != null) {
1227
				requestor.exitMethod(methodDeclaration.declarationSourceEnd, expression);
1228
				return;
1229
			}
1230
		} 
1231
		requestor.exitMethod(methodDeclaration.declarationSourceEnd, null);
1232
	}
1233
}
1234
1235
/*
1236
* Update the bodyStart of the corresponding parse node
1237
*/
1238
public void notifySourceElementRequestor(FieldDeclaration fieldDeclaration, TypeDeclaration declaringType) {
1239
	
1240
	// range check
1241
	boolean isInRange = 
1242
				scanner.initialPosition <= fieldDeclaration.declarationSourceStart
1243
				&& scanner.eofPosition >= fieldDeclaration.declarationSourceEnd;
1244
1245
	switch(fieldDeclaration.getKind()) {
1246
		case AbstractVariableDeclaration.ENUM_CONSTANT:
1247
			// accept constructor reference for enum constant
1248
			if (fieldDeclaration.initialization instanceof AllocationExpression) {
1249
				AllocationExpression alloc = (AllocationExpression) fieldDeclaration.initialization;
1250
				requestor.acceptConstructorReference(
1251
					declaringType.name,
1252
					alloc.arguments == null ? 0 : alloc.arguments.length, 
1253
					alloc.sourceStart);
1254
			}
1255
			// fall through next case
1256
		case AbstractVariableDeclaration.FIELD:
1257
			int fieldEndPosition = this.sourceEnds.get(fieldDeclaration);
1258
			if (fieldEndPosition == -1) {
1259
				// use the declaration source end by default
1260
				fieldEndPosition = fieldDeclaration.declarationSourceEnd;
1261
			}
1262
			if (isInRange) {
1263
				int currentModifiers = fieldDeclaration.modifiers;
1264
				
1265
				// remember deprecation so as to not lose it below
1266
				boolean deprecated = (currentModifiers & ClassFileConstants.AccDeprecated) != 0 || hasDeprecatedAnnotation(fieldDeclaration.annotations);	
1267
			
1268
				char[] typeName = null;
1269
				if (fieldDeclaration.type == null) {
1270
					// enum constant
1271
					typeName = declaringType.name;
1272
					currentModifiers |= ClassFileConstants.AccEnum;
1273
				} else {
1274
					// regular field
1275
					typeName = CharOperation.concatWith(fieldDeclaration.type.getParameterizedTypeName(), '.');
1276
				}
1277
				ISourceElementRequestor.FieldInfo fieldInfo = new ISourceElementRequestor.FieldInfo();
1278
				fieldInfo.declarationStart = fieldDeclaration.declarationSourceStart;
1279
				fieldInfo.name = fieldDeclaration.name;
1280
				fieldInfo.modifiers = deprecated ? (currentModifiers & ExtraCompilerModifiers.AccJustFlag) | ClassFileConstants.AccDeprecated : currentModifiers & ExtraCompilerModifiers.AccJustFlag;
1281
				fieldInfo.type = typeName;
1282
				fieldInfo.nameSourceStart = fieldDeclaration.sourceStart;
1283
				fieldInfo.nameSourceEnd = fieldDeclaration.sourceEnd;
1284
				fieldInfo.categories = (char[][]) this.nodesToCategories.get(fieldDeclaration);
1285
				fieldInfo.annotations = fieldDeclaration.annotations;
1286
				requestor.enterField(fieldInfo);
1287
			}
1288
			this.visitIfNeeded(fieldDeclaration, declaringType);
1289
			if (isInRange){
1290
				requestor.exitField(
1291
					// filter out initializations that are not a constant (simple check)
1292
					(fieldDeclaration.initialization == null 
1293
							|| fieldDeclaration.initialization instanceof ArrayInitializer
1294
							|| fieldDeclaration.initialization instanceof AllocationExpression
1295
							|| fieldDeclaration.initialization instanceof ArrayAllocationExpression
1296
							|| fieldDeclaration.initialization instanceof Assignment
1297
							|| fieldDeclaration.initialization instanceof ClassLiteralAccess
1298
							|| fieldDeclaration.initialization instanceof MessageSend
1299
							|| fieldDeclaration.initialization instanceof ArrayReference
1300
							|| fieldDeclaration.initialization instanceof ThisReference) ? 
1301
						-1 :  
1302
						fieldDeclaration.initialization.sourceStart, 
1303
					fieldEndPosition,
1304
					fieldDeclaration.declarationSourceEnd);
1305
			}
1306
			break;
1307
		case AbstractVariableDeclaration.INITIALIZER:
1308
			if (isInRange){
1309
				requestor.enterInitializer(
1310
					fieldDeclaration.declarationSourceStart,
1311
					fieldDeclaration.modifiers); 
1312
			}
1313
			this.visitIfNeeded((Initializer)fieldDeclaration);
1314
			if (isInRange){
1315
				requestor.exitInitializer(fieldDeclaration.declarationSourceEnd);
1316
			}
1317
			break;
1318
	}
1319
}
1320
public void notifySourceElementRequestor(
1321
	ImportReference importReference, 
1322
	boolean isPackage) {
1323
	if (isPackage) {
1324
		requestor.acceptPackage(importReference); 
1325
	} else {
1326
		requestor.acceptImport(
1327
			importReference.declarationSourceStart, 
1328
			importReference.declarationSourceEnd, 
1329
			importReference.tokens, 
1330
			(importReference.bits & ASTNode.OnDemand) != 0,
1331
			importReference.modifiers); 
1332
	}
1333
}
1334
public void notifySourceElementRequestor(TypeDeclaration typeDeclaration, boolean notifyTypePresence, TypeDeclaration declaringType) {
1335
	
1336
	if (CharOperation.equals(TypeConstants.PACKAGE_INFO_NAME, typeDeclaration.name)) return;
1337
1338
	// range check
1339
	boolean isInRange = 
1340
		scanner.initialPosition <= typeDeclaration.declarationSourceStart
1341
		&& scanner.eofPosition >= typeDeclaration.declarationSourceEnd;
1342
	
1343
	FieldDeclaration[] fields = typeDeclaration.fields;
1344
	AbstractMethodDeclaration[] methods = typeDeclaration.methods;
1345
	TypeDeclaration[] memberTypes = typeDeclaration.memberTypes;
1346
	int fieldCounter = fields == null ? 0 : fields.length;
1347
	int methodCounter = methods == null ? 0 : methods.length;
1348
	int memberTypeCounter = memberTypes == null ? 0 : memberTypes.length;
1349
	int fieldIndex = 0;
1350
	int methodIndex = 0;
1351
	int memberTypeIndex = 0;
1352
	
1353
	if (notifyTypePresence){
1354
		char[][] interfaceNames = null;
1355
		int superInterfacesLength = 0;
1356
		TypeReference[] superInterfaces = typeDeclaration.superInterfaces;
1357
		if (superInterfaces != null) {
1358
			superInterfacesLength = superInterfaces.length;
1359
			interfaceNames = new char[superInterfacesLength][];
1360
		} else {
1361
			if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) {
1362
				// see PR 3442
1363
				QualifiedAllocationExpression alloc = typeDeclaration.allocation;
1364
				if (alloc != null && alloc.type != null) {
1365
					superInterfaces = new TypeReference[] { alloc.type};
1366
					superInterfacesLength = 1;
1367
					interfaceNames = new char[1][];
1368
				}
1369
			}
1370
		}
1371
		if (superInterfaces != null) {
1372
			for (int i = 0; i < superInterfacesLength; i++) {
1373
				interfaceNames[i] = 
1374
					CharOperation.concatWith(superInterfaces[i].getParameterizedTypeName(), '.'); 
1375
			}
1376
		}
1377
		int kind = TypeDeclaration.kind(typeDeclaration.modifiers);
1378
		char[] implicitSuperclassName = TypeConstants.CharArray_JAVA_LANG_OBJECT;
1379
		if (isInRange) {
1380
			int currentModifiers = typeDeclaration.modifiers;
1381
			
1382
			// remember deprecation so as to not lose it below
1383
			boolean deprecated = (currentModifiers & ClassFileConstants.AccDeprecated) != 0 || hasDeprecatedAnnotation(typeDeclaration.annotations);	
1384
			
1385
			boolean isEnumInit = typeDeclaration.allocation != null && typeDeclaration.allocation.enumConstant != null;
1386
			char[] superclassName;
1387
			if (isEnumInit) {
1388
				currentModifiers |= ClassFileConstants.AccEnum;
1389
				superclassName = declaringType.name;
1390
			} else {
1391
				TypeReference superclass = typeDeclaration.superclass;
1392
				superclassName = superclass != null ? CharOperation.concatWith(superclass.getParameterizedTypeName(), '.') : null;
1393
			}
1394
			ISourceElementRequestor.TypeInfo typeInfo = new ISourceElementRequestor.TypeInfo();
1395
			typeInfo.declarationStart = typeDeclaration.allocation == null ? typeDeclaration.declarationSourceStart : typeDeclaration.allocation.sourceStart;
1396
			typeInfo.modifiers = deprecated ? (currentModifiers & ExtraCompilerModifiers.AccJustFlag) | ClassFileConstants.AccDeprecated : currentModifiers & ExtraCompilerModifiers.AccJustFlag;
1397
			typeInfo.name = typeDeclaration.name;
1398
			typeInfo.nameSourceStart = typeDeclaration.sourceStart;
1399
			typeInfo.nameSourceEnd = sourceEnd(typeDeclaration);
1400
			typeInfo.superclass = superclassName;
1401
			typeInfo.superinterfaces = interfaceNames;
1402
			typeInfo.typeParameters = getTypeParameterInfos(typeDeclaration.typeParameters);
1403
			typeInfo.categories = (char[][]) this.nodesToCategories.get(typeDeclaration);
1404
			typeInfo.secondary = typeDeclaration.isSecondary();
1405
			typeInfo.anonymousMember = typeDeclaration.allocation != null && typeDeclaration.allocation.enclosingInstance != null;
1406
			typeInfo.annotations = typeDeclaration.annotations;
1407
			requestor.enterType(typeInfo);
1408
			switch (kind) {
1409
				case TypeDeclaration.CLASS_DECL :
1410
					if (superclassName != null)
1411
						implicitSuperclassName = superclassName;
1412
					break;
1413
				case TypeDeclaration.INTERFACE_DECL :
1414
					implicitSuperclassName = TypeConstants.CharArray_JAVA_LANG_OBJECT;
1415
					break;
1416
				case TypeDeclaration.ENUM_DECL :
1417
					implicitSuperclassName = TypeConstants.CharArray_JAVA_LANG_ENUM;
1418
					break;
1419
				case TypeDeclaration.ANNOTATION_TYPE_DECL :
1420
					implicitSuperclassName = TypeConstants.CharArray_JAVA_LANG_ANNOTATION_ANNOTATION;
1421
					break;
1422
			}
1423
		}
1424
		if (this.nestedTypeIndex == this.typeNames.length) {
1425
			// need a resize
1426
			System.arraycopy(this.typeNames, 0, (this.typeNames = new char[this.nestedTypeIndex * 2][]), 0, this.nestedTypeIndex);
1427
			System.arraycopy(this.superTypeNames, 0, (this.superTypeNames = new char[this.nestedTypeIndex * 2][]), 0, this.nestedTypeIndex);
1428
		}
1429
		this.typeNames[this.nestedTypeIndex] = typeDeclaration.name;
1430
		this.superTypeNames[this.nestedTypeIndex++] = implicitSuperclassName;
1431
	}
1432
	while ((fieldIndex < fieldCounter)
1433
			|| (memberTypeIndex < memberTypeCounter)
1434
			|| (methodIndex < methodCounter)) {
1435
		FieldDeclaration nextFieldDeclaration = null;
1436
		AbstractMethodDeclaration nextMethodDeclaration = null;
1437
		TypeDeclaration nextMemberDeclaration = null;
1438
		
1439
		int position = Integer.MAX_VALUE;
1440
		int nextDeclarationType = -1;
1441
		if (fieldIndex < fieldCounter) {
1442
			nextFieldDeclaration = fields[fieldIndex];
1443
			if (nextFieldDeclaration.declarationSourceStart < position) {
1444
				position = nextFieldDeclaration.declarationSourceStart;
1445
				nextDeclarationType = 0; // FIELD
1446
			}
1447
		}
1448
		if (methodIndex < methodCounter) {
1449
			nextMethodDeclaration = methods[methodIndex];
1450
			if (nextMethodDeclaration.declarationSourceStart < position) {
1451
				position = nextMethodDeclaration.declarationSourceStart;
1452
				nextDeclarationType = 1; // METHOD
1453
			}
1454
		}
1455
		if (memberTypeIndex < memberTypeCounter) {
1456
			nextMemberDeclaration = memberTypes[memberTypeIndex];
1457
			if (nextMemberDeclaration.declarationSourceStart < position) {
1458
				position = nextMemberDeclaration.declarationSourceStart;
1459
				nextDeclarationType = 2; // MEMBER
1460
			}
1461
		}
1462
		switch (nextDeclarationType) {
1463
			case 0 :
1464
				fieldIndex++;
1465
				notifySourceElementRequestor(nextFieldDeclaration, typeDeclaration);
1466
				break;
1467
			case 1 :
1468
				methodIndex++;
1469
				notifySourceElementRequestor(nextMethodDeclaration);
1470
				break;
1471
			case 2 :
1472
				memberTypeIndex++;
1473
				notifySourceElementRequestor(nextMemberDeclaration, true, null);
1474
		}
1475
	}
1476
	if (notifyTypePresence){
1477
		if (isInRange){
1478
			requestor.exitType(typeDeclaration.declarationSourceEnd);
1479
		}
1480
		nestedTypeIndex--;
1481
	}
1482
}
1483
public CompilationUnitDeclaration parseCompilationUnit(
888
public CompilationUnitDeclaration parseCompilationUnit(
1484
	ICompilationUnit unit, 
889
	ICompilationUnit unit, 
1485
	boolean fullParse,
890
	boolean fullParse,
Lines 1499-1510 Link Here
1499
		}
904
		}
1500
		int initialStart = this.scanner.initialPosition;
905
		int initialStart = this.scanner.initialPosition;
1501
		int initialEnd = this.scanner.eofPosition;
906
		int initialEnd = this.scanner.eofPosition;
1502
		if (this.localDeclarationVisitor != null || fullParse){
907
		if (this.reportLocalDeclarations || fullParse){
1503
			diet = false;
908
			diet = false;
1504
			this.getMethodBodies(parsedUnit);
909
			this.getMethodBodies(parsedUnit);
1505
		}
910
		}
1506
		this.scanner.resetTo(initialStart, initialEnd);
911
		this.scanner.resetTo(initialStart, initialEnd);
1507
		notifySourceElementRequestor(parsedUnit);
912
		this.notifier.notifySourceElementRequestor(
913
				parsedUnit,
914
				this.scanner.initialPosition,
915
				this.scanner.eofPosition,
916
				this.reportReferenceInfo,
917
				this.sourceEnds,
918
				this.nodesToCategories);
1508
		return parsedUnit;
919
		return parsedUnit;
1509
	} catch (AbortCompilation e) {
920
	} catch (AbortCompilation e) {
1510
		// ignore this exception
921
		// ignore this exception
Lines 1514-1548 Link Here
1514
	}
925
	}
1515
	return parsedUnit;
926
	return parsedUnit;
1516
}
927
}
1517
/*
1518
 * Sort the given ast nodes by their positions.
1519
 */
1520
private static void quickSort(ASTNode[] sortedCollection, int left, int right) {
1521
	int original_left = left;
1522
	int original_right = right;
1523
	ASTNode mid = sortedCollection[left +  (right - left) / 2];
1524
	do {
1525
		while (sortedCollection[left].sourceStart < mid.sourceStart) {
1526
			left++;
1527
		}
1528
		while (mid.sourceStart < sortedCollection[right].sourceStart) {
1529
			right--;
1530
		}
1531
		if (left <= right) {
1532
			ASTNode tmp = sortedCollection[left];
1533
			sortedCollection[left] = sortedCollection[right];
1534
			sortedCollection[right] = tmp;
1535
			left++;
1536
			right--;
1537
		}
1538
	} while (left <= right);
1539
	if (original_left < right) {
1540
		quickSort(sortedCollection, original_left, right);
1541
	}
1542
	if (left < original_right) {
1543
		quickSort(sortedCollection, left, original_right);
1544
	}
1545
}
1546
private void rememberCategories() {
928
private void rememberCategories() {
1547
	if (this.useSourceJavadocParser) {
929
	if (this.useSourceJavadocParser) {
1548
		SourceJavadocParser sourceJavadocParser = (SourceJavadocParser) this.javadocParser;
930
		SourceJavadocParser sourceJavadocParser = (SourceJavadocParser) this.javadocParser;
Lines 1556-1612 Link Here
1556
private void reset() {
938
private void reset() {
1557
	this.sourceEnds = new HashtableOfObjectToInt();
939
	this.sourceEnds = new HashtableOfObjectToInt();
1558
	this.nodesToCategories = new HashMap();
940
	this.nodesToCategories = new HashMap();
1559
	typeNames = new char[4][];
1560
	superTypeNames = new char[4][];
1561
	nestedTypeIndex = 0;
1562
}
1563
private int sourceEnd(TypeDeclaration typeDeclaration) {
1564
	if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) {
1565
		QualifiedAllocationExpression allocation = typeDeclaration.allocation;
1566
		if (allocation.type == null) // case of enum constant body
1567
			return typeDeclaration.sourceEnd;
1568
		return allocation.type.sourceEnd;
1569
	} else {
1570
		return typeDeclaration.sourceEnd;
1571
	}
1572
}
1573
private void visitIfNeeded(AbstractMethodDeclaration method) {
1574
	if (this.localDeclarationVisitor != null 
1575
		&& (method.bits & ASTNode.HasLocalType) != 0) {
1576
			if (method instanceof ConstructorDeclaration) {
1577
				ConstructorDeclaration constructorDeclaration = (ConstructorDeclaration) method;
1578
				if (constructorDeclaration.constructorCall != null) {
1579
					constructorDeclaration.constructorCall.traverse(this.localDeclarationVisitor, method.scope);
1580
				}
1581
			}
1582
			if (method.statements != null) {
1583
				int statementsLength = method.statements.length;
1584
				for (int i = 0; i < statementsLength; i++)
1585
					method.statements[i].traverse(this.localDeclarationVisitor, method.scope);
1586
			}
1587
	}
1588
}
941
}
1589
942
public void setRequestor(ISourceElementRequestor requestor) {
1590
private void visitIfNeeded(FieldDeclaration field, TypeDeclaration declaringType) {
943
	this.requestor = requestor;
1591
	if (this.localDeclarationVisitor != null 
944
	this.notifier.requestor = requestor;
1592
		&& (field.bits & ASTNode.HasLocalType) != 0) {
1593
			if (field.initialization != null) {
1594
				try {
1595
					this.localDeclarationVisitor.pushDeclaringType(declaringType);
1596
					field.initialization.traverse(this.localDeclarationVisitor, (MethodScope) null);
1597
				} finally {
1598
					this.localDeclarationVisitor.popDeclaringType();
1599
				}
1600
			}
1601
	}
1602
}
1603
1604
private void visitIfNeeded(Initializer initializer) {
1605
	if (this.localDeclarationVisitor != null 
1606
		&& (initializer.bits & ASTNode.HasLocalType) != 0) {
1607
			if (initializer.block != null) {
1608
				initializer.block.traverse(this.localDeclarationVisitor, null);
1609
			}
1610
	}
1611
}
945
}
1612
}
946
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java (-7 / +10 lines)
Lines 1220-1226 Link Here
1220
	return createArrayType(binding, dimension);
1220
	return createArrayType(binding, dimension);
1221
}
1221
}
1222
1222
1223
TypeBinding getTypeFromTypeSignature(SignatureWrapper wrapper, TypeVariableBinding[] staticVariables, ReferenceBinding enclosingType, char[][][] missingTypeNames) {
1223
public TypeBinding getTypeFromTypeSignature(SignatureWrapper wrapper, TypeVariableBinding[] staticVariables, ReferenceBinding enclosingType, char[][][] missingTypeNames) {
1224
	// TypeVariableSignature = 'T' Identifier ';'
1224
	// TypeVariableSignature = 'T' Identifier ';'
1225
	// ArrayTypeSignature = '[' TypeSignature
1225
	// ArrayTypeSignature = '[' TypeSignature
1226
	// ClassTypeSignature = 'L' Identifier TypeArgs(optional) ';'
1226
	// ClassTypeSignature = 'L' Identifier TypeArgs(optional) ';'
Lines 1239-1250 Link Here
1239
				return dimension == 0 ? (TypeBinding) staticVariables[i] : createArrayType(staticVariables[i], dimension);
1239
				return dimension == 0 ? (TypeBinding) staticVariables[i] : createArrayType(staticVariables[i], dimension);
1240
	    ReferenceBinding initialType = enclosingType;
1240
	    ReferenceBinding initialType = enclosingType;
1241
		do {
1241
		do {
1242
		    if (enclosingType instanceof BinaryTypeBinding) { // per construction can only be binary type binding
1242
			TypeVariableBinding[] enclosingTypeVariables;
1243
				TypeVariableBinding[] enclosingVariables = ((BinaryTypeBinding)enclosingType).typeVariables; // do not trigger resolution of variables
1243
			if (enclosingType instanceof BinaryTypeBinding) { // compiler normal case, no eager resolution of binary variables
1244
				for (int i = enclosingVariables.length; --i >= 0;)
1244
				enclosingTypeVariables = ((BinaryTypeBinding)enclosingType).typeVariables; // do not trigger resolution of variables
1245
					if (CharOperation.equals(enclosingVariables[i].sourceName, wrapper.signature, varStart, varEnd))
1245
			} else { // codepath only use by codeassist for decoding signatures
1246
						return dimension == 0 ? (TypeBinding) enclosingVariables[i] : createArrayType(enclosingVariables[i], dimension);
1246
				enclosingTypeVariables = enclosingType.typeVariables();
1247
		    }
1247
			}
1248
			for (int i = enclosingTypeVariables.length; --i >= 0;)
1249
				if (CharOperation.equals(enclosingTypeVariables[i].sourceName, wrapper.signature, varStart, varEnd))
1250
					return dimension == 0 ? (TypeBinding) enclosingTypeVariables[i] : createArrayType(enclosingTypeVariables[i], dimension);
1248
		} while ((enclosingType = enclosingType.enclosingType()) != null);
1251
		} while ((enclosingType = enclosingType.enclosingType()) != null);
1249
		problemReporter.undefinedTypeVariableSignature(CharOperation.subarray(wrapper.signature, varStart, varEnd), initialType);
1252
		problemReporter.undefinedTypeVariableSignature(CharOperation.subarray(wrapper.signature, varStart, varEnd), initialType);
1250
		return null; // cannot reach this, since previous problem will abort compilation
1253
		return null; // cannot reach this, since previous problem will abort compilation
(-)model/org/eclipse/jdt/core/CompletionContext.java (-24 / +110 lines)
Lines 27-32 Link Here
27
public final class CompletionContext extends InternalCompletionContext {
27
public final class CompletionContext extends InternalCompletionContext {
28
28
29
	/**
29
	/**
30
	 * The completed token is the first token of a member declaration.<br>
31
	 * e.g.
32
	 * <pre>
33
	 * public class X {
34
	 *   Foo| // completion occurs at |
35
	 * }
36
	 * </pre>
37
	 * 
38
	 * @see #getTokenLocation()
39
	 * 
40
	 * @since 3.4
41
	 */
42
	public static final int TL_MEMBER_START = 1;
43
	
44
	/**
45
	 * The completed token is the first token of a statement.<br>
46
	 * e.g.
47
	 * <pre>
48
	 * public class X {
49
	 *   public void bar() {
50
	 *     Foo| // completion occurs at |
51
	 *   }
52
	 * }
53
	 * </pre>
54
	 * 
55
	 * @see #getTokenLocation()
56
	 * 
57
	 * @since 3.4
58
	 */
59
	public static final int TL_STATEMENT_START = 2;
60
	
61
	/**
30
	 * The completion token is unknown.
62
	 * The completion token is unknown.
31
	 * @since 3.2
63
	 * @since 3.2
32
	 */
64
	 */
Lines 83-88 Link Here
83
	public boolean isInJavadocFormalReference() {
115
	public boolean isInJavadocFormalReference() {
84
		return (this.javadoc & CompletionOnJavadoc.FORMAL_REFERENCE) != 0;
116
		return (this.javadoc & CompletionOnJavadoc.FORMAL_REFERENCE) != 0;
85
	}
117
	}
118
	
119
	/**
120
	 * Returns whether this completion context is an extended context.
121
	 * Some methods of this context can be used only if this context is an extended context but an extended context consumes more memory.
122
	 * 
123
	 * @return <code>true</code> if this completion context is an extended context.
124
	 * 
125
	 * @since 3.4
126
	 */
127
	public boolean isExtended() {
128
		return this.extendedContext != null;
129
	}
86
130
87
	/**
131
	/**
88
	 * Return signatures of expected types of a potential completion proposal at the completion position.
132
	 * Return signatures of expected types of a potential completion proposal at the completion position.
Lines 210-247 Link Here
210
		return this.offset;
254
		return this.offset;
211
	}
255
	}
212
	
256
	
213
	
214
	/**
257
	/**
215
	 * The completed token is the first token of a member declaration.<br>
258
	 * Returns the innermost enclosing Java element which contains the completion location or <code>null</code> if this element cannot be computed.
216
	 * e.g.
259
	 * The returned Java element and all Java elements in the same compilation unit which can be navigated to from the returned Java element are special Java elements:
217
	 * <pre>
260
	 * <ul>
218
	 * public class X {
261
	 * <li>they are based on the current content of the compilation unit's buffer, they are not the result of a reconcile operation</li>
219
	 *   Foo| // completion occurs at |
262
	 * <li>they are not updated if the buffer changes.</li>
220
	 * }
263
	 * <li>they do not contain local types which are not visible from the completion location.</li>
221
	 * </pre>
264
	 * <li>they do not give information about categories. {@link IMember#getCategories()} will return an empty array</li>
265
	 * </ul>
222
	 * 
266
	 * 
223
	 * @see #getTokenLocation()
267
	 * Reasons for returning <code>null</code> include:
268
	 * <ul>
269
	 * <li>the compilation unit no longer exists</li>
270
	 * <li>the completion occurred in a binary type. However this restriction might be relaxed in the future.</li>
271
	 * </ul>
272
	 * 
273
	 * @return the innermost enclosing Java element which contains the completion location or <code>null</code> if this element cannot be computed.
274
	 * 
275
	 * @exception UnsupportedOperationException if the context is not an extended context
224
	 * 
276
	 * 
225
	 * @since 3.4
277
	 * @since 3.4
226
	 */
278
	 */
227
	public static final int TL_MEMBER_START = 1;
279
	public IJavaElement getEnclosingElement() {
280
		if (!this.isExtended()) throw new UnsupportedOperationException("Operation only supported in extended context"); //$NON-NLS-1$
281
		
282
		if (this.extendedContext == null) return null;
283
		
284
		return this.extendedContext.getEnclosingElement();
285
	}
228
	
286
	
229
	/**
287
	/**
230
	 * The completed token is the first token of a statement.<br>
288
	 * Return the elements which are visible from the completion location and which can be assigned to the given type.
231
	 * e.g.
289
	 * An element is assignable if its type can be assigned to a variable
232
	 * <pre>
290
	 * of the given type, as specified in section 5.2 of <em>The Java Language
233
	 * public class X {
291
	 * Specification, Third Edition</em> (JLS3).
234
	 *   public void bar() {
292
	 * A visible element is either:
235
	 *     Foo| // completion occurs at |
293
	 * <ul>
236
	 *   }
294
	 * <li>a {@link ILocalVariable} - the element type is {@link ILocalVariable#getTypeSignature()}</li>
237
	 * }
295
	 * <li>a {@link IField} - the element type is {@link IField#getTypeSignature()}</li>
238
	 * </pre>
296
	 * <li>a {@link IMethod} - the element type is {@link IMethod#getReturnType()}</li>
297
	 * </ul>
239
	 * 
298
	 * 
240
	 * @see #getTokenLocation()
299
	 * Returned elements defined in the completed compilation unit are special Java elements:
300
	 * <ul>
301
	 * <li>they are based on the current content of the compilation unit's buffer, they are not the result of a reconcile operation</li>
302
	 * <li>they are not updated if the buffer changes.</li>
303
	 * <li>they do not contain local types which are not visible from the completion location.</li>
304
	 * <li>they do not give information about categories. {@link IMember#getCategories()} will return an empty array</li>
305
	 * </ul>
306
	 * 
307
	 * Note the array can be empty if:
308
	 * <ul>
309
	 * <li>the compilation unit no longer exists</li>
310
	 * <li>the completion occurred in a binary type. However this restriction might be relaxed in the future.</li>
311
	 * </ul>
312
	 * 
313
	 * @param typeSignature elements which can be assigned to this type are returned.
314
	 * 		If <code>null</code> there is no constraint on the type of the returned elements.
315
	 * 
316
	 * @return elements which are visible from the completion location and which can be assigned to the given type.
317
	 * 
318
	 * @exception UnsupportedOperationException if the context is not an extended context
319
	 * 
320
	 * @see #isExtended()
241
	 * 
321
	 * 
242
	 * @since 3.4
322
	 * @since 3.4
243
	 */
323
	 */
244
	public static final int TL_STATEMENT_START = 2;
324
	public IJavaElement[] getVisibleElements(String typeSignature) {
325
		if (!this.isExtended()) throw new UnsupportedOperationException("Operation only supported in extended context"); //$NON-NLS-1$
326
		
327
		if (this.extendedContext == null) return new IJavaElement[0];
328
		
329
		return this.extendedContext.getVisibleElements(typeSignature);
330
	}
245
	
331
	
246
	public String toString() {
332
	public String toString() {
247
		StringBuffer buffer = new StringBuffer();
333
		StringBuffer buffer = new StringBuffer();
Lines 296-304 Link Here
296
		buffer.append('\n');
382
		buffer.append('\n');
297
		
383
		
298
		if (tokenLocation == 0) {
384
		if (tokenLocation == 0) {
299
			buffer.append("locationType=UNKNOWN"); //$NON-NLS-1$
385
			buffer.append("tokenLocation=UNKNOWN"); //$NON-NLS-1$
300
		} else {
386
		} else {
301
			buffer.append("locationType={"); //$NON-NLS-1$
387
			buffer.append("tokenLocation={"); //$NON-NLS-1$
302
			boolean first = true;
388
			boolean first = true;
303
			if ((tokenLocation & CompletionContext.TL_MEMBER_START) != 0) {
389
			if ((tokenLocation & CompletionContext.TL_MEMBER_START) != 0) {
304
				if (!first) buffer.append(',');
390
				if (!first) buffer.append(',');
Lines 313-319 Link Here
313
			buffer.append('}');
399
			buffer.append('}');
314
		}
400
		}
315
		buffer.append('\n');
401
		buffer.append('\n');
316
			
402
		
317
		return buffer.toString();
403
		return buffer.toString();
318
	}
404
	}
319
}
405
}
(-)model/org/eclipse/jdt/core/CompletionRequestor.java (+31 lines)
Lines 68-73 Link Here
68
	 * 1 << completionProposalKind
68
	 * 1 << completionProposalKind
69
	 */
69
	 */
70
	private int requiredProposalAllowSet[] = null;
70
	private int requiredProposalAllowSet[] = null;
71
			
72
	private boolean requireExtendedContext = false;
71
73
72
	/**
74
	/**
73
	 * Creates a new completion requestor.
75
	 * Creates a new completion requestor.
Lines 324-327 Link Here
324
	public void acceptContext(CompletionContext context) {
326
	public void acceptContext(CompletionContext context) {
325
		// do nothing
327
		// do nothing
326
	}
328
	}
329
	
330
	/**
331
	 * Returns whether this requestor requires an extended context.
332
	 * 
333
	 * By default this method return <code>false</code>.
334
	 * 
335
	 * @return <code>true</code> if this requestor requires an extended context.
336
	 * 
337
	 * @see CompletionContext#isExtended()
338
	 * 
339
	 * @since 3.4
340
	 */
341
	public boolean isExtendedContextRequired() {
342
		return this.requireExtendedContext;
343
	}
344
	
345
	
346
	/**
347
	 * Sets whether this requestor requires an extended context.
348
	 * 
349
	 * @param require <code>true</code> if this requestor requires an extended context.
350
	 * 
351
	 * @see CompletionContext#isExtended()
352
	 * 
353
	 * @since 3.4
354
	 */
355
	public void setRequireExtendedContext(boolean require) {
356
		this.requireExtendedContext = require;
357
	}
327
}
358
}
(-)search/org/eclipse/jdt/internal/core/search/matching/SuperTypeNamesCollector.java (+1 lines)
Lines 19-24 Link Here
19
import org.eclipse.jdt.internal.compiler.ASTVisitor;
19
import org.eclipse.jdt.internal.compiler.ASTVisitor;
20
import org.eclipse.jdt.internal.compiler.CompilationResult;
20
import org.eclipse.jdt.internal.compiler.CompilationResult;
21
import org.eclipse.jdt.internal.compiler.ast.*;
21
import org.eclipse.jdt.internal.compiler.ast.*;
22
import org.eclipse.jdt.internal.compiler.ast.Initializer;
22
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
23
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
23
import org.eclipse.jdt.internal.compiler.lookup.*;
24
import org.eclipse.jdt.internal.compiler.lookup.*;
24
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
25
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
(-)batch/org/eclipse/jdt/internal/compiler/batch/messages.properties (-1 / +1 lines)
Lines 14-20 Link Here
14
#Format: compiler.name = word1 word2 word3
14
#Format: compiler.name = word1 word2 word3
15
compiler.name = Eclipse Java Compiler
15
compiler.name = Eclipse Java Compiler
16
#Format: compiler.version = 0.XXX[, other words (don't forget the comma if adding other words)]
16
#Format: compiler.version = 0.XXX[, other words (don't forget the comma if adding other words)]
17
compiler.version = 0.843, pre-3.4.0 milestone-6
17
compiler.version = 0.844, pre-3.4.0 milestone-6
18
compiler.copyright = Copyright IBM Corp 2000, 2008. All rights reserved.
18
compiler.copyright = Copyright IBM Corp 2000, 2008. All rights reserved.
19
19
20
### progress
20
### progress
(-)eval/org/eclipse/jdt/internal/eval/EvaluationContext.java (-3 / +7 lines)
Lines 15-20 Link Here
15
15
16
import org.eclipse.jdt.core.CompletionRequestor;
16
import org.eclipse.jdt.core.CompletionRequestor;
17
import org.eclipse.jdt.core.IJavaProject;
17
import org.eclipse.jdt.core.IJavaProject;
18
import org.eclipse.jdt.core.WorkingCopyOwner;
18
import org.eclipse.jdt.core.compiler.*;
19
import org.eclipse.jdt.core.compiler.*;
19
import org.eclipse.jdt.internal.codeassist.CompletionEngine;
20
import org.eclipse.jdt.internal.codeassist.CompletionEngine;
20
import org.eclipse.jdt.internal.codeassist.ISelectionRequestor;
21
import org.eclipse.jdt.internal.codeassist.ISelectionRequestor;
Lines 100-107 Link Here
100
 *
101
 *
101
 *  @param options
102
 *  @param options
102
 *		set of options used to configure the code assist engine.
103
 *		set of options used to configure the code assist engine.
104
 *
105
 *  @param owner
106
 *  	the owner of working copies that take precedence over their original compilation units
103
 */
107
 */
104
public void complete(char[] codeSnippet, int completionPosition, SearchableEnvironment environment, CompletionRequestor requestor, Map options, IJavaProject project) {
108
public void complete(char[] codeSnippet, int completionPosition, SearchableEnvironment environment, CompletionRequestor requestor, Map options, final IJavaProject project, WorkingCopyOwner owner) {
105
	try {
109
	try {
106
		IRequestor variableRequestor = new IRequestor() {
110
		IRequestor variableRequestor = new IRequestor() {
107
			public boolean acceptClassFiles(ClassFile[] classFiles, char[] codeSnippetClassName) {
111
			public boolean acceptClassFiles(ClassFile[] classFiles, char[] codeSnippetClassName) {
Lines 144-150 Link Here
144
		}
148
		}
145
	};
149
	};
146
	
150
	
147
	CompletionEngine engine = new CompletionEngine(environment, mapper.getCompletionRequestor(requestor), options, project);
151
	CompletionEngine engine = new CompletionEngine(environment, mapper.getCompletionRequestor(requestor), options, project, owner);
148
	
152
	
149
	if (this.installedVars != null) {
153
	if (this.installedVars != null) {
150
		IBinaryType binaryType = this.getRootCodeSnippetBinary();
154
		IBinaryType binaryType = this.getRootCodeSnippetBinary();
Lines 165-171 Link Here
165
		}
169
		}
166
	}
170
	}
167
	
171
	
168
	engine.complete(sourceUnit, mapper.startPosOffset + completionPosition, mapper.startPosOffset);
172
	engine.complete(sourceUnit, mapper.startPosOffset + completionPosition, mapper.startPosOffset, null);
169
}
173
}
170
/**
174
/**
171
 * Deletes the given variable from this evaluation context. This will take effect in the target VM only
175
 * Deletes the given variable from this evaluation context. This will take effect in the target VM only
(-)model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java (+1 lines)
Lines 36-41 Link Here
36
import org.eclipse.jdt.internal.compiler.CompilationResult;
36
import org.eclipse.jdt.internal.compiler.CompilationResult;
37
import org.eclipse.jdt.internal.compiler.ast.*;
37
import org.eclipse.jdt.internal.compiler.ast.*;
38
import org.eclipse.jdt.internal.compiler.ast.Annotation;
38
import org.eclipse.jdt.internal.compiler.ast.Annotation;
39
import org.eclipse.jdt.internal.compiler.ast.Initializer;
39
import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
40
import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
40
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
41
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
41
import org.eclipse.jdt.internal.compiler.env.*;
42
import org.eclipse.jdt.internal.compiler.env.*;
(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistAnnotation.java (+30 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.codeassist.impl;
12
13
import java.util.Map;
14
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.jdt.core.JavaModelException;
17
import org.eclipse.jdt.internal.core.Annotation;
18
import org.eclipse.jdt.internal.core.JavaElement;
19
20
public class AssistAnnotation extends Annotation {
21
	private Map infoCache;
22
	public AssistAnnotation(JavaElement parent, String name, Map infoCache) {
23
		super(parent, name);
24
		this.infoCache = infoCache;
25
	}
26
	
27
	public Object getElementInfo(IProgressMonitor monitor) throws JavaModelException {
28
		return infoCache.get(this);
29
	}
30
}
(-)model/org/eclipse/jdt/internal/compiler/SourceElementNotifier.java (+758 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler;
12
13
import java.util.ArrayList;
14
import java.util.Map;
15
16
import org.eclipse.jdt.core.compiler.CharOperation;
17
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
18
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
19
import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
20
import org.eclipse.jdt.internal.compiler.ast.AllocationExpression;
21
import org.eclipse.jdt.internal.compiler.ast.Annotation;
22
import org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration;
23
import org.eclipse.jdt.internal.compiler.ast.Argument;
24
import org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression;
25
import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
26
import org.eclipse.jdt.internal.compiler.ast.ArrayReference;
27
import org.eclipse.jdt.internal.compiler.ast.Assignment;
28
import org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess;
29
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
30
import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
31
import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall;
32
import org.eclipse.jdt.internal.compiler.ast.Expression;
33
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
34
import org.eclipse.jdt.internal.compiler.ast.ImportReference;
35
import org.eclipse.jdt.internal.compiler.ast.Initializer;
36
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
37
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
38
import org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression;
39
import org.eclipse.jdt.internal.compiler.ast.ThisReference;
40
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
41
import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
42
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
43
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
44
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
45
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
46
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
47
import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
48
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
49
import org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToInt;
50
51
public class SourceElementNotifier {
52
	/**
53
	 * An ast visitor that visits local type declarations.
54
	 */
55
	public class LocalDeclarationVisitor extends ASTVisitor {
56
		ArrayList declaringTypes;
57
		public void pushDeclaringType(TypeDeclaration declaringType) {
58
			if (this.declaringTypes == null) {
59
				this.declaringTypes = new ArrayList();
60
			}
61
			this.declaringTypes.add(declaringType);
62
		}
63
		public void popDeclaringType() {
64
			this.declaringTypes.remove(this.declaringTypes.size()-1);
65
		}
66
		public TypeDeclaration peekDeclaringType() {
67
			if (this.declaringTypes == null) return null;
68
			int size = this.declaringTypes.size();
69
			if (size == 0) return null;
70
			return (TypeDeclaration) this.declaringTypes.get(size-1);
71
		}
72
		public boolean visit(TypeDeclaration typeDeclaration, BlockScope scope) {
73
			notifySourceElementRequestor(typeDeclaration, true, peekDeclaringType());
74
			return false; // don't visit members as this was done during notifySourceElementRequestor(...)
75
		}
76
		public boolean visit(TypeDeclaration typeDeclaration, ClassScope scope) {
77
			notifySourceElementRequestor(typeDeclaration, true, peekDeclaringType());
78
			return false; // don't visit members as this was done during notifySourceElementRequestor(...)
79
		}	
80
	}
81
	
82
	ISourceElementRequestor requestor;
83
	boolean reportReferenceInfo;
84
	char[][] typeNames;
85
	char[][] superTypeNames;
86
	int nestedTypeIndex;
87
	LocalDeclarationVisitor localDeclarationVisitor = null;
88
	
89
	HashtableOfObjectToInt sourceEnds;
90
	Map nodesToCategories;
91
	
92
	int initialPosition;
93
	int eofPosition;
94
	
95
public SourceElementNotifier(ISourceElementRequestor requestor, boolean reportLocalDeclarations) {
96
	this.requestor = requestor;
97
	if (reportLocalDeclarations) {
98
		this.localDeclarationVisitor = new LocalDeclarationVisitor();
99
	}
100
	typeNames = new char[4][];
101
	superTypeNames = new char[4][];
102
	nestedTypeIndex = 0;
103
}
104
protected char[][][] getArguments(Argument[] arguments) {
105
	int argumentLength = arguments.length;
106
	char[][] argumentTypes = new char[argumentLength][];
107
	char[][] argumentNames = new char[argumentLength][];
108
	for (int i = 0; i < argumentLength; i++) {
109
		argumentTypes[i] = CharOperation.concatWith(arguments[i].type.getParameterizedTypeName(), '.');
110
		argumentNames[i] = arguments[i].name;
111
	}
112
	
113
	return new char[][][] {argumentTypes, argumentNames};
114
}
115
protected char[][] getInterfaceNames(TypeDeclaration typeDeclaration) {
116
	char[][] interfaceNames = null;
117
	int superInterfacesLength = 0;
118
	TypeReference[] superInterfaces = typeDeclaration.superInterfaces;
119
	if (superInterfaces != null) {
120
		superInterfacesLength = superInterfaces.length;
121
		interfaceNames = new char[superInterfacesLength][];
122
	} else {
123
		if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) {
124
			// see PR 3442
125
			QualifiedAllocationExpression alloc = typeDeclaration.allocation;
126
			if (alloc != null && alloc.type != null) {
127
				superInterfaces = new TypeReference[] { alloc.type};
128
				superInterfacesLength = 1;
129
				interfaceNames = new char[1][];
130
			}
131
		}
132
	}
133
	if (superInterfaces != null) {
134
		for (int i = 0; i < superInterfacesLength; i++) {
135
			interfaceNames[i] = 
136
				CharOperation.concatWith(superInterfaces[i].getParameterizedTypeName(), '.'); 
137
		}
138
	}
139
	return interfaceNames;
140
}
141
protected char[] getSuperclassName(TypeDeclaration typeDeclaration) {
142
	TypeReference superclass = typeDeclaration.superclass;
143
	return superclass != null ? CharOperation.concatWith(superclass.getParameterizedTypeName(), '.') : null;
144
}
145
protected char[][] getThrownExceptions(AbstractMethodDeclaration methodDeclaration) {
146
	char[][] thrownExceptionTypes = null;
147
	TypeReference[] thrownExceptions = methodDeclaration.thrownExceptions;
148
	if (thrownExceptions != null) {
149
		int thrownExceptionLength = thrownExceptions.length;
150
		thrownExceptionTypes = new char[thrownExceptionLength][];
151
		for (int i = 0; i < thrownExceptionLength; i++) {
152
			thrownExceptionTypes[i] = 
153
				CharOperation.concatWith(thrownExceptions[i].getParameterizedTypeName(), '.'); 
154
		}
155
	}
156
	return thrownExceptionTypes;
157
}
158
protected char[][] getTypeParameterBounds(TypeParameter typeParameter) {
159
	TypeReference firstBound = typeParameter.type;
160
	TypeReference[] otherBounds = typeParameter.bounds;
161
	char[][] typeParameterBounds = null;
162
	if (firstBound != null) {
163
		if (otherBounds != null) {
164
			int otherBoundsLength = otherBounds.length;
165
			char[][] boundNames = new char[otherBoundsLength+1][];
166
			boundNames[0] = CharOperation.concatWith(firstBound.getParameterizedTypeName(), '.');
167
			for (int j = 0; j < otherBoundsLength; j++) {
168
				boundNames[j+1] = 
169
					CharOperation.concatWith(otherBounds[j].getParameterizedTypeName(), '.'); 
170
			}
171
			typeParameterBounds = boundNames;
172
		} else {
173
			typeParameterBounds = new char[][] { CharOperation.concatWith(firstBound.getParameterizedTypeName(), '.')};
174
		}
175
	} else {
176
		typeParameterBounds = CharOperation.NO_CHAR_CHAR;
177
	}
178
	
179
	return typeParameterBounds;
180
}
181
private ISourceElementRequestor.TypeParameterInfo[] getTypeParameterInfos(TypeParameter[] typeParameters) {
182
	if (typeParameters == null) return null;
183
	int typeParametersLength = typeParameters.length;
184
	ISourceElementRequestor.TypeParameterInfo[] result = new ISourceElementRequestor.TypeParameterInfo[typeParametersLength];
185
	for (int i = 0; i < typeParametersLength; i++) {
186
		TypeParameter typeParameter = typeParameters[i];
187
		char[][] typeParameterBounds = this.getTypeParameterBounds(typeParameter);
188
		ISourceElementRequestor.TypeParameterInfo typeParameterInfo = new ISourceElementRequestor.TypeParameterInfo();
189
		typeParameterInfo.declarationStart = typeParameter.declarationSourceStart;
190
		typeParameterInfo.declarationEnd = typeParameter.declarationSourceEnd;
191
		typeParameterInfo.name = typeParameter.name;
192
		typeParameterInfo.nameSourceStart = typeParameter.sourceStart;
193
		typeParameterInfo.nameSourceEnd = typeParameter.sourceEnd;
194
		typeParameterInfo.bounds = typeParameterBounds;
195
		result[i] = typeParameterInfo;
196
	}
197
	return result;
198
}
199
/*
200
 * Checks whether one of the annotations is the @Deprecated annotation
201
 * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89807)
202
 */
203
private boolean hasDeprecatedAnnotation(Annotation[] annotations) {
204
	if (annotations != null) {
205
		for (int i = 0, length = annotations.length; i < length; i++) {
206
			Annotation annotation = annotations[i];
207
			if (CharOperation.equals(annotation.type.getLastToken(), TypeConstants.JAVA_LANG_DEPRECATED[2])) {
208
				return true;
209
			}
210
		}
211
	}
212
	return false;
213
}
214
/*
215
 * Update the bodyStart of the corresponding parse node
216
 */
217
protected void notifySourceElementRequestor(AbstractMethodDeclaration methodDeclaration) {
218
219
	// range check
220
	boolean isInRange = 
221
				initialPosition <= methodDeclaration.declarationSourceStart
222
				&& eofPosition >= methodDeclaration.declarationSourceEnd;
223
224
	if (methodDeclaration.isClinit()) {
225
		this.visitIfNeeded(methodDeclaration);
226
		return;
227
	}
228
229
	if (methodDeclaration.isDefaultConstructor()) {
230
		if (reportReferenceInfo) {
231
			ConstructorDeclaration constructorDeclaration = (ConstructorDeclaration) methodDeclaration;
232
			ExplicitConstructorCall constructorCall = constructorDeclaration.constructorCall;
233
			if (constructorCall != null) {
234
				switch(constructorCall.accessMode) {
235
					case ExplicitConstructorCall.This :
236
						requestor.acceptConstructorReference(
237
							typeNames[nestedTypeIndex-1],
238
							constructorCall.arguments == null ? 0 : constructorCall.arguments.length, 
239
							constructorCall.sourceStart);
240
						break;
241
					case ExplicitConstructorCall.Super :
242
					case ExplicitConstructorCall.ImplicitSuper :					
243
						requestor.acceptConstructorReference(
244
							superTypeNames[nestedTypeIndex-1],
245
							constructorCall.arguments == null ? 0 : constructorCall.arguments.length, 
246
							constructorCall.sourceStart);
247
						break;
248
				}
249
			}
250
		}	
251
		return;	
252
	}	
253
	char[][] argumentTypes = null;
254
	char[][] argumentNames = null;
255
	boolean isVarArgs = false;
256
	Argument[] arguments = methodDeclaration.arguments;
257
	if (arguments != null) {
258
		char[][][] argumentTypesAndNames = this.getArguments(arguments);
259
		argumentTypes = argumentTypesAndNames[0];
260
		argumentNames = argumentTypesAndNames[1];
261
		
262
		isVarArgs = arguments[arguments.length-1].isVarArgs();
263
	}
264
	char[][] thrownExceptionTypes = getThrownExceptions(methodDeclaration);
265
	// by default no selector end position
266
	int selectorSourceEnd = -1;
267
	if (methodDeclaration.isConstructor()) {
268
		selectorSourceEnd = this.sourceEnds.get(methodDeclaration);
269
		if (isInRange){
270
			int currentModifiers = methodDeclaration.modifiers;
271
			if (isVarArgs)
272
				currentModifiers |= ClassFileConstants.AccVarargs;
273
			
274
			// remember deprecation so as to not lose it below
275
			boolean deprecated = (currentModifiers & ClassFileConstants.AccDeprecated) != 0 || hasDeprecatedAnnotation(methodDeclaration.annotations);
276
			
277
			ISourceElementRequestor.MethodInfo methodInfo = new ISourceElementRequestor.MethodInfo();
278
			methodInfo.isConstructor = true;
279
			methodInfo.declarationStart = methodDeclaration.declarationSourceStart;
280
			methodInfo.modifiers = deprecated ? (currentModifiers & ExtraCompilerModifiers.AccJustFlag) | ClassFileConstants.AccDeprecated : currentModifiers & ExtraCompilerModifiers.AccJustFlag;
281
			methodInfo.name = methodDeclaration.selector;
282
			methodInfo.nameSourceStart = methodDeclaration.sourceStart;
283
			methodInfo.nameSourceEnd = selectorSourceEnd;
284
			methodInfo.parameterTypes = argumentTypes;
285
			methodInfo.parameterNames = argumentNames;
286
			methodInfo.exceptionTypes = thrownExceptionTypes;
287
			methodInfo.typeParameters = getTypeParameterInfos(methodDeclaration.typeParameters());
288
			methodInfo.categories = (char[][]) this.nodesToCategories.get(methodDeclaration);
289
			methodInfo.annotations = methodDeclaration.annotations;
290
			methodInfo.node = methodDeclaration;
291
			requestor.enterConstructor(methodInfo);
292
		}
293
		if (reportReferenceInfo) {
294
			ConstructorDeclaration constructorDeclaration = (ConstructorDeclaration) methodDeclaration;
295
			ExplicitConstructorCall constructorCall = constructorDeclaration.constructorCall;
296
			if (constructorCall != null) {
297
				switch(constructorCall.accessMode) {
298
					case ExplicitConstructorCall.This :
299
						requestor.acceptConstructorReference(
300
							typeNames[nestedTypeIndex-1],
301
							constructorCall.arguments == null ? 0 : constructorCall.arguments.length, 
302
							constructorCall.sourceStart);
303
						break;
304
					case ExplicitConstructorCall.Super :
305
					case ExplicitConstructorCall.ImplicitSuper :
306
						requestor.acceptConstructorReference(
307
							superTypeNames[nestedTypeIndex-1],
308
							constructorCall.arguments == null ? 0 : constructorCall.arguments.length, 
309
							constructorCall.sourceStart);
310
						break;
311
				}
312
			}
313
		}
314
		this.visitIfNeeded(methodDeclaration);
315
		if (isInRange){
316
			requestor.exitConstructor(methodDeclaration.declarationSourceEnd);
317
		}
318
		return;
319
	}
320
	selectorSourceEnd = this.sourceEnds.get(methodDeclaration);
321
	if (isInRange) {
322
		int currentModifiers = methodDeclaration.modifiers;
323
		if (isVarArgs)
324
			currentModifiers |= ClassFileConstants.AccVarargs;
325
		
326
		// remember deprecation so as to not lose it below
327
		boolean deprecated = (currentModifiers & ClassFileConstants.AccDeprecated) != 0 || hasDeprecatedAnnotation(methodDeclaration.annotations);	
328
			
329
		TypeReference returnType = methodDeclaration instanceof MethodDeclaration
330
			? ((MethodDeclaration) methodDeclaration).returnType
331
			: null;
332
		ISourceElementRequestor.MethodInfo methodInfo = new ISourceElementRequestor.MethodInfo();
333
		methodInfo.isAnnotation = methodDeclaration instanceof AnnotationMethodDeclaration;
334
		methodInfo.declarationStart = methodDeclaration.declarationSourceStart;
335
		methodInfo.modifiers = deprecated ? (currentModifiers & ExtraCompilerModifiers.AccJustFlag) | ClassFileConstants.AccDeprecated : currentModifiers & ExtraCompilerModifiers.AccJustFlag;
336
		methodInfo.returnType = returnType == null ? null : CharOperation.concatWith(returnType.getParameterizedTypeName(), '.');
337
		methodInfo.name = methodDeclaration.selector;
338
		methodInfo.nameSourceStart = methodDeclaration.sourceStart;
339
		methodInfo.nameSourceEnd = selectorSourceEnd;
340
		methodInfo.parameterTypes = argumentTypes;
341
		methodInfo.parameterNames = argumentNames;
342
		methodInfo.exceptionTypes = thrownExceptionTypes;
343
		methodInfo.typeParameters = getTypeParameterInfos(methodDeclaration.typeParameters());
344
		methodInfo.categories = (char[][]) this.nodesToCategories.get(methodDeclaration);
345
		methodInfo.annotations = methodDeclaration.annotations;
346
		methodInfo.node = methodDeclaration;
347
		requestor.enterMethod(methodInfo);
348
	}		
349
		
350
	this.visitIfNeeded(methodDeclaration);
351
352
	if (isInRange) {
353
		if (methodDeclaration instanceof AnnotationMethodDeclaration) {
354
			AnnotationMethodDeclaration annotationMethodDeclaration = (AnnotationMethodDeclaration) methodDeclaration;
355
			Expression expression = annotationMethodDeclaration.defaultValue;
356
			if (expression != null) {
357
				requestor.exitMethod(methodDeclaration.declarationSourceEnd, expression);
358
				return;
359
			}
360
		} 
361
		requestor.exitMethod(methodDeclaration.declarationSourceEnd, null);
362
	}
363
}
364
365
/*
366
 * Update the bodyStart of the corresponding parse node
367
 */
368
public void notifySourceElementRequestor(
369
		CompilationUnitDeclaration parsedUnit,
370
		int sourceStart,
371
		int sourceEnd,
372
		boolean reportReference,
373
		HashtableOfObjectToInt sourceEndsMap,
374
		Map nodesToCategoriesMap) {
375
	
376
	this.initialPosition = sourceStart;
377
	this.eofPosition = sourceEnd;
378
	
379
	this.reportReferenceInfo = reportReference;
380
	this.sourceEnds = sourceEndsMap;
381
	this.nodesToCategories = nodesToCategoriesMap;
382
	
383
	try {
384
		// range check
385
		boolean isInRange = 
386
					initialPosition <= parsedUnit.sourceStart
387
					&& eofPosition >= parsedUnit.sourceEnd;
388
		
389
		// collect the top level ast nodes
390
		int length = 0;
391
		ASTNode[] nodes = null;
392
		if (isInRange) {
393
			requestor.enterCompilationUnit();
394
		}
395
		ImportReference currentPackage = parsedUnit.currentPackage;
396
		ImportReference[] imports = parsedUnit.imports;
397
		TypeDeclaration[] types = parsedUnit.types;
398
		length = 
399
			(currentPackage == null ? 0 : 1) 
400
			+ (imports == null ? 0 : imports.length)
401
			+ (types == null ? 0 : types.length);
402
		nodes = new ASTNode[length];
403
		int index = 0;
404
		if (currentPackage != null) {
405
			nodes[index++] = currentPackage;
406
		}
407
		if (imports != null) {
408
			for (int i = 0, max = imports.length; i < max; i++) {
409
				nodes[index++] = imports[i];
410
			}
411
		}
412
		if (types != null) {
413
			for (int i = 0, max = types.length; i < max; i++) {
414
				nodes[index++] = types[i];
415
			}
416
		}
417
		
418
		// notify the nodes in the syntactical order
419
		if (length > 0) {
420
			quickSort(nodes, 0, length-1);
421
			for (int i=0;i<length;i++) {
422
				ASTNode node = nodes[i];
423
				if (node instanceof ImportReference) {
424
					ImportReference importRef = (ImportReference)node;
425
					if (node == parsedUnit.currentPackage) {
426
						notifySourceElementRequestor(importRef, true);
427
					} else {
428
						notifySourceElementRequestor(importRef, false);
429
					}
430
				} else { // instanceof TypeDeclaration
431
					notifySourceElementRequestor((TypeDeclaration)node, true, null);
432
				}
433
			}
434
		}
435
		
436
		if (isInRange) {
437
			requestor.exitCompilationUnit(parsedUnit.sourceEnd);
438
		}
439
	} finally {
440
		this.reset();
441
	}
442
}
443
444
/*
445
* Update the bodyStart of the corresponding parse node
446
*/
447
protected void notifySourceElementRequestor(FieldDeclaration fieldDeclaration, TypeDeclaration declaringType) {
448
	
449
	// range check
450
	boolean isInRange = 
451
				initialPosition <= fieldDeclaration.declarationSourceStart
452
				&& eofPosition >= fieldDeclaration.declarationSourceEnd;
453
454
	switch(fieldDeclaration.getKind()) {
455
		case AbstractVariableDeclaration.ENUM_CONSTANT:
456
			if (this.reportReferenceInfo) {
457
				// accept constructor reference for enum constant
458
				if (fieldDeclaration.initialization instanceof AllocationExpression) {
459
					AllocationExpression alloc = (AllocationExpression) fieldDeclaration.initialization;
460
					requestor.acceptConstructorReference(
461
						declaringType.name,
462
						alloc.arguments == null ? 0 : alloc.arguments.length, 
463
						alloc.sourceStart);
464
				}
465
			}
466
			// fall through next case
467
		case AbstractVariableDeclaration.FIELD:
468
			int fieldEndPosition = this.sourceEnds.get(fieldDeclaration);
469
			if (fieldEndPosition == -1) {
470
				// use the declaration source end by default
471
				fieldEndPosition = fieldDeclaration.declarationSourceEnd;
472
			}
473
			if (isInRange) {
474
				int currentModifiers = fieldDeclaration.modifiers;
475
				
476
				// remember deprecation so as to not lose it below
477
				boolean deprecated = (currentModifiers & ClassFileConstants.AccDeprecated) != 0 || hasDeprecatedAnnotation(fieldDeclaration.annotations);	
478
			
479
				char[] typeName = null;
480
				if (fieldDeclaration.type == null) {
481
					// enum constant
482
					typeName = declaringType.name;
483
					currentModifiers |= ClassFileConstants.AccEnum;
484
				} else {
485
					// regular field
486
					typeName = CharOperation.concatWith(fieldDeclaration.type.getParameterizedTypeName(), '.');
487
				}
488
				ISourceElementRequestor.FieldInfo fieldInfo = new ISourceElementRequestor.FieldInfo();
489
				fieldInfo.declarationStart = fieldDeclaration.declarationSourceStart;
490
				fieldInfo.name = fieldDeclaration.name;
491
				fieldInfo.modifiers = deprecated ? (currentModifiers & ExtraCompilerModifiers.AccJustFlag) | ClassFileConstants.AccDeprecated : currentModifiers & ExtraCompilerModifiers.AccJustFlag;
492
				fieldInfo.type = typeName;
493
				fieldInfo.nameSourceStart = fieldDeclaration.sourceStart;
494
				fieldInfo.nameSourceEnd = fieldDeclaration.sourceEnd;
495
				fieldInfo.categories = (char[][]) this.nodesToCategories.get(fieldDeclaration);
496
				fieldInfo.annotations = fieldDeclaration.annotations;
497
				fieldInfo.node = fieldDeclaration;
498
				requestor.enterField(fieldInfo);
499
			}
500
			this.visitIfNeeded(fieldDeclaration, declaringType);
501
			if (isInRange){
502
				requestor.exitField(
503
					// filter out initializations that are not a constant (simple check)
504
					(fieldDeclaration.initialization == null 
505
							|| fieldDeclaration.initialization instanceof ArrayInitializer
506
							|| fieldDeclaration.initialization instanceof AllocationExpression
507
							|| fieldDeclaration.initialization instanceof ArrayAllocationExpression
508
							|| fieldDeclaration.initialization instanceof Assignment
509
							|| fieldDeclaration.initialization instanceof ClassLiteralAccess
510
							|| fieldDeclaration.initialization instanceof MessageSend
511
							|| fieldDeclaration.initialization instanceof ArrayReference
512
							|| fieldDeclaration.initialization instanceof ThisReference) ? 
513
						-1 :  
514
						fieldDeclaration.initialization.sourceStart, 
515
					fieldEndPosition,
516
					fieldDeclaration.declarationSourceEnd);
517
			}
518
			break;
519
		case AbstractVariableDeclaration.INITIALIZER:
520
			if (isInRange){
521
				requestor.enterInitializer(
522
					fieldDeclaration.declarationSourceStart,
523
					fieldDeclaration.modifiers); 
524
			}
525
			this.visitIfNeeded((Initializer)fieldDeclaration);
526
			if (isInRange){
527
				requestor.exitInitializer(fieldDeclaration.declarationSourceEnd);
528
			}
529
			break;
530
	}
531
}
532
protected void notifySourceElementRequestor(
533
	ImportReference importReference, 
534
	boolean isPackage) {
535
	if (isPackage) {
536
		requestor.acceptPackage(importReference); 
537
	} else {
538
		requestor.acceptImport(
539
			importReference.declarationSourceStart, 
540
			importReference.declarationSourceEnd, 
541
			importReference.tokens, 
542
			(importReference.bits & ASTNode.OnDemand) != 0,
543
			importReference.modifiers); 
544
	}
545
}
546
protected void notifySourceElementRequestor(TypeDeclaration typeDeclaration, boolean notifyTypePresence, TypeDeclaration declaringType) {
547
	
548
	if (CharOperation.equals(TypeConstants.PACKAGE_INFO_NAME, typeDeclaration.name)) return;
549
550
	// range check
551
	boolean isInRange = 
552
		initialPosition <= typeDeclaration.declarationSourceStart
553
		&& eofPosition >= typeDeclaration.declarationSourceEnd;
554
	
555
	FieldDeclaration[] fields = typeDeclaration.fields;
556
	AbstractMethodDeclaration[] methods = typeDeclaration.methods;
557
	TypeDeclaration[] memberTypes = typeDeclaration.memberTypes;
558
	int fieldCounter = fields == null ? 0 : fields.length;
559
	int methodCounter = methods == null ? 0 : methods.length;
560
	int memberTypeCounter = memberTypes == null ? 0 : memberTypes.length;
561
	int fieldIndex = 0;
562
	int methodIndex = 0;
563
	int memberTypeIndex = 0;
564
	
565
	if (notifyTypePresence){
566
		char[][] interfaceNames = getInterfaceNames(typeDeclaration);
567
		int kind = TypeDeclaration.kind(typeDeclaration.modifiers);
568
		char[] implicitSuperclassName = TypeConstants.CharArray_JAVA_LANG_OBJECT;
569
		if (isInRange) {
570
			int currentModifiers = typeDeclaration.modifiers;
571
			
572
			// remember deprecation so as to not lose it below
573
			boolean deprecated = (currentModifiers & ClassFileConstants.AccDeprecated) != 0 || hasDeprecatedAnnotation(typeDeclaration.annotations);	
574
			
575
			boolean isEnumInit = typeDeclaration.allocation != null && typeDeclaration.allocation.enumConstant != null;
576
			char[] superclassName;
577
			if (isEnumInit) {
578
				currentModifiers |= ClassFileConstants.AccEnum;
579
				superclassName = declaringType.name;
580
			} else {
581
				superclassName = getSuperclassName(typeDeclaration);
582
			}
583
			ISourceElementRequestor.TypeInfo typeInfo = new ISourceElementRequestor.TypeInfo();
584
			typeInfo.declarationStart = typeDeclaration.allocation == null ? typeDeclaration.declarationSourceStart : typeDeclaration.allocation.sourceStart;
585
			typeInfo.modifiers = deprecated ? (currentModifiers & ExtraCompilerModifiers.AccJustFlag) | ClassFileConstants.AccDeprecated : currentModifiers & ExtraCompilerModifiers.AccJustFlag;
586
			typeInfo.name = typeDeclaration.name;
587
			typeInfo.nameSourceStart = typeDeclaration.sourceStart;
588
			typeInfo.nameSourceEnd = sourceEnd(typeDeclaration);
589
			typeInfo.superclass = superclassName;
590
			typeInfo.superinterfaces = interfaceNames;
591
			typeInfo.typeParameters = getTypeParameterInfos(typeDeclaration.typeParameters);
592
			typeInfo.categories = (char[][]) this.nodesToCategories.get(typeDeclaration);
593
			typeInfo.secondary = typeDeclaration.isSecondary();
594
			typeInfo.anonymousMember = typeDeclaration.allocation != null && typeDeclaration.allocation.enclosingInstance != null;
595
			typeInfo.annotations = typeDeclaration.annotations;
596
			typeInfo.node = typeDeclaration;
597
			requestor.enterType(typeInfo);
598
			switch (kind) {
599
				case TypeDeclaration.CLASS_DECL :
600
					if (superclassName != null)
601
						implicitSuperclassName = superclassName;
602
					break;
603
				case TypeDeclaration.INTERFACE_DECL :
604
					implicitSuperclassName = TypeConstants.CharArray_JAVA_LANG_OBJECT;
605
					break;
606
				case TypeDeclaration.ENUM_DECL :
607
					implicitSuperclassName = TypeConstants.CharArray_JAVA_LANG_ENUM;
608
					break;
609
				case TypeDeclaration.ANNOTATION_TYPE_DECL :
610
					implicitSuperclassName = TypeConstants.CharArray_JAVA_LANG_ANNOTATION_ANNOTATION;
611
					break;
612
			}
613
		}
614
		if (this.nestedTypeIndex == this.typeNames.length) {
615
			// need a resize
616
			System.arraycopy(this.typeNames, 0, (this.typeNames = new char[this.nestedTypeIndex * 2][]), 0, this.nestedTypeIndex);
617
			System.arraycopy(this.superTypeNames, 0, (this.superTypeNames = new char[this.nestedTypeIndex * 2][]), 0, this.nestedTypeIndex);
618
		}
619
		this.typeNames[this.nestedTypeIndex] = typeDeclaration.name;
620
		this.superTypeNames[this.nestedTypeIndex++] = implicitSuperclassName;
621
	}
622
	while ((fieldIndex < fieldCounter)
623
			|| (memberTypeIndex < memberTypeCounter)
624
			|| (methodIndex < methodCounter)) {
625
		FieldDeclaration nextFieldDeclaration = null;
626
		AbstractMethodDeclaration nextMethodDeclaration = null;
627
		TypeDeclaration nextMemberDeclaration = null;
628
		
629
		int position = Integer.MAX_VALUE;
630
		int nextDeclarationType = -1;
631
		if (fieldIndex < fieldCounter) {
632
			nextFieldDeclaration = fields[fieldIndex];
633
			if (nextFieldDeclaration.declarationSourceStart < position) {
634
				position = nextFieldDeclaration.declarationSourceStart;
635
				nextDeclarationType = 0; // FIELD
636
			}
637
		}
638
		if (methodIndex < methodCounter) {
639
			nextMethodDeclaration = methods[methodIndex];
640
			if (nextMethodDeclaration.declarationSourceStart < position) {
641
				position = nextMethodDeclaration.declarationSourceStart;
642
				nextDeclarationType = 1; // METHOD
643
			}
644
		}
645
		if (memberTypeIndex < memberTypeCounter) {
646
			nextMemberDeclaration = memberTypes[memberTypeIndex];
647
			if (nextMemberDeclaration.declarationSourceStart < position) {
648
				position = nextMemberDeclaration.declarationSourceStart;
649
				nextDeclarationType = 2; // MEMBER
650
			}
651
		}
652
		switch (nextDeclarationType) {
653
			case 0 :
654
				fieldIndex++;
655
				notifySourceElementRequestor(nextFieldDeclaration, typeDeclaration);
656
				break;
657
			case 1 :
658
				methodIndex++;
659
				notifySourceElementRequestor(nextMethodDeclaration);
660
				break;
661
			case 2 :
662
				memberTypeIndex++;
663
				notifySourceElementRequestor(nextMemberDeclaration, true, null);
664
		}
665
	}
666
	if (notifyTypePresence){
667
		if (isInRange){
668
			requestor.exitType(typeDeclaration.declarationSourceEnd);
669
		}
670
		nestedTypeIndex--;
671
	}
672
}
673
/*
674
 * Sort the given ast nodes by their positions.
675
 */
676
private static void quickSort(ASTNode[] sortedCollection, int left, int right) {
677
	int original_left = left;
678
	int original_right = right;
679
	ASTNode mid = sortedCollection[left +  (right - left) / 2];
680
	do {
681
		while (sortedCollection[left].sourceStart < mid.sourceStart) {
682
			left++;
683
		}
684
		while (mid.sourceStart < sortedCollection[right].sourceStart) {
685
			right--;
686
		}
687
		if (left <= right) {
688
			ASTNode tmp = sortedCollection[left];
689
			sortedCollection[left] = sortedCollection[right];
690
			sortedCollection[right] = tmp;
691
			left++;
692
			right--;
693
		}
694
	} while (left <= right);
695
	if (original_left < right) {
696
		quickSort(sortedCollection, original_left, right);
697
	}
698
	if (left < original_right) {
699
		quickSort(sortedCollection, left, original_right);
700
	}
701
}
702
private void reset() {
703
	typeNames = new char[4][];
704
	superTypeNames = new char[4][];
705
	nestedTypeIndex = 0;
706
	
707
	this.sourceEnds = null;
708
}
709
private int sourceEnd(TypeDeclaration typeDeclaration) {
710
	if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) {
711
		QualifiedAllocationExpression allocation = typeDeclaration.allocation;
712
		if (allocation.type == null) // case of enum constant body
713
			return typeDeclaration.sourceEnd;
714
		return allocation.type.sourceEnd;
715
	} else {
716
		return typeDeclaration.sourceEnd;
717
	}
718
}
719
private void visitIfNeeded(AbstractMethodDeclaration method) {
720
	if (this.localDeclarationVisitor != null 
721
		&& (method.bits & ASTNode.HasLocalType) != 0) {
722
			if (method instanceof ConstructorDeclaration) {
723
				ConstructorDeclaration constructorDeclaration = (ConstructorDeclaration) method;
724
				if (constructorDeclaration.constructorCall != null) {
725
					constructorDeclaration.constructorCall.traverse(this.localDeclarationVisitor, method.scope);
726
				}
727
			}
728
			if (method.statements != null) {
729
				int statementsLength = method.statements.length;
730
				for (int i = 0; i < statementsLength; i++)
731
					method.statements[i].traverse(this.localDeclarationVisitor, method.scope);
732
			}
733
	}
734
}
735
736
private void visitIfNeeded(FieldDeclaration field, TypeDeclaration declaringType) {
737
	if (this.localDeclarationVisitor != null 
738
		&& (field.bits & ASTNode.HasLocalType) != 0) {
739
			if (field.initialization != null) {
740
				try {
741
					this.localDeclarationVisitor.pushDeclaringType(declaringType);
742
					field.initialization.traverse(this.localDeclarationVisitor, (MethodScope) null);
743
				} finally {
744
					this.localDeclarationVisitor.popDeclaringType();
745
				}
746
			}
747
	}
748
}
749
750
private void visitIfNeeded(Initializer initializer) {
751
	if (this.localDeclarationVisitor != null 
752
		&& (initializer.bits & ASTNode.HasLocalType) != 0) {
753
			if (initializer.block != null) {
754
				initializer.block.traverse(this.localDeclarationVisitor, null);
755
			}
756
	}
757
}
758
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/CompletionUnitStructureRequestor.java (+208 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.codeassist;
12
13
import java.util.Map;
14
15
import org.eclipse.jdt.core.IAnnotation;
16
import org.eclipse.jdt.core.ICompilationUnit;
17
import org.eclipse.jdt.core.IMemberValuePair;
18
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnMarkerAnnotationName;
19
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnMemberValueName;
20
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnParameterizedQualifiedTypeReference;
21
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnQualifiedNameReference;
22
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnQualifiedTypeReference;
23
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnSingleNameReference;
24
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnSingleTypeReference;
25
import org.eclipse.jdt.internal.codeassist.impl.AssistAnnotation;
26
import org.eclipse.jdt.internal.codeassist.impl.AssistImportContainer;
27
import org.eclipse.jdt.internal.codeassist.impl.AssistImportDeclaration;
28
import org.eclipse.jdt.internal.codeassist.impl.AssistInitializer;
29
import org.eclipse.jdt.internal.codeassist.impl.AssistPackageDeclaration;
30
import org.eclipse.jdt.internal.codeassist.impl.AssistSourceField;
31
import org.eclipse.jdt.internal.codeassist.impl.AssistSourceMethod;
32
import org.eclipse.jdt.internal.codeassist.impl.AssistSourceType;
33
import org.eclipse.jdt.internal.codeassist.impl.AssistTypeParameter;
34
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
35
import org.eclipse.jdt.internal.compiler.ast.Expression;
36
import org.eclipse.jdt.internal.compiler.ast.MemberValuePair;
37
import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference;
38
import org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference;
39
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
40
import org.eclipse.jdt.internal.compiler.parser.Parser;
41
import org.eclipse.jdt.internal.core.AnnotatableInfo;
42
import org.eclipse.jdt.internal.core.Annotation;
43
import org.eclipse.jdt.internal.core.CompilationUnit;
44
import org.eclipse.jdt.internal.core.CompilationUnitElementInfo;
45
import org.eclipse.jdt.internal.core.CompilationUnitStructureRequestor;
46
import org.eclipse.jdt.internal.core.ImportContainer;
47
import org.eclipse.jdt.internal.core.ImportDeclaration;
48
import org.eclipse.jdt.internal.core.Initializer;
49
import org.eclipse.jdt.internal.core.JavaElement;
50
import org.eclipse.jdt.internal.core.JavaModelManager;
51
import org.eclipse.jdt.internal.core.PackageDeclaration;
52
import org.eclipse.jdt.internal.core.SourceField;
53
import org.eclipse.jdt.internal.core.SourceMethod;
54
import org.eclipse.jdt.internal.core.SourceType;
55
import org.eclipse.jdt.internal.core.TypeParameter;
56
57
public class CompletionUnitStructureRequestor extends CompilationUnitStructureRequestor {
58
	private ASTNode assistNode;
59
	
60
	private Map bindingCache;
61
	private Map elementCache;
62
	
63
	public CompletionUnitStructureRequestor(
64
			ICompilationUnit unit,
65
			CompilationUnitElementInfo unitInfo,
66
			Parser parser,
67
			ASTNode assistNode,
68
			Map bindingCache,
69
			Map elementCache,
70
			Map newElements) {
71
		super(unit, unitInfo, newElements);
72
		this.parser = parser;
73
		this.assistNode = assistNode;
74
		this.bindingCache = bindingCache;
75
		this.elementCache = elementCache;
76
	}
77
	
78
	protected Annotation createAnnotation(JavaElement parent, String name) {
79
		return new AssistAnnotation(parent, name, this.newElements);
80
	}
81
82
	protected SourceField createField(JavaElement parent, FieldInfo fieldInfo) {
83
		String fieldName = JavaModelManager.getJavaModelManager().intern(new String(fieldInfo.name));
84
		AssistSourceField field = new AssistSourceField(parent, fieldName, this.bindingCache, this.newElements);
85
		if (fieldInfo.node.binding != null) {
86
			this.bindingCache.put(field, fieldInfo.node.binding);
87
			this.elementCache.put(fieldInfo.node.binding, field);
88
		}
89
		return field;
90
	}
91
92
	protected ImportContainer createImportContainer(ICompilationUnit parent) {
93
		return new AssistImportContainer((CompilationUnit)parent, this.newElements);
94
	}
95
96
	protected ImportDeclaration createImportDeclaration(ImportContainer parent, String name, boolean onDemand) {
97
		return new AssistImportDeclaration(parent, name, onDemand, this.newElements);
98
	}
99
100
	protected Initializer createInitializer(JavaElement parent) {
101
		return new AssistInitializer(parent, 1, this.bindingCache, this.newElements);
102
	}
103
104
	protected SourceMethod createMethod(JavaElement parent, MethodInfo methodInfo) {
105
		String selector = JavaModelManager.getJavaModelManager().intern(new String(methodInfo.name));
106
		String[] parameterTypeSigs = convertTypeNamesToSigs(methodInfo.parameterTypes);
107
		AssistSourceMethod method = new AssistSourceMethod(parent, selector, parameterTypeSigs, this.bindingCache, this.newElements);
108
		if (methodInfo.node.binding != null) {
109
			this.bindingCache.put(method, methodInfo.node.binding);
110
			this.elementCache.put(methodInfo.node.binding, method);
111
		}
112
		return method;
113
	}
114
115
	protected PackageDeclaration createPackageDeclaration(JavaElement parent, String name) {
116
		return new AssistPackageDeclaration((CompilationUnit) parent, name, this.newElements);
117
	}
118
	
119
	protected SourceType createType(JavaElement parent, TypeInfo typeInfo) {
120
		String nameString= new String(typeInfo.name);
121
		AssistSourceType type = new AssistSourceType(parent, nameString, this.bindingCache, this.newElements);
122
		if (typeInfo.node.binding != null) {
123
			this.bindingCache.put(type, typeInfo.node.binding);
124
			this.elementCache.put(typeInfo.node.binding, type);
125
		}
126
		return type;
127
	}
128
	
129
	protected TypeParameter createTypeParameter(JavaElement parent, String name) {
130
		return new AssistTypeParameter(parent, name, this.newElements);
131
	}
132
	
133
	protected IAnnotation enterAnnotation(
134
			org.eclipse.jdt.internal.compiler.ast.Annotation annotation,
135
			AnnotatableInfo parentInfo,
136
			JavaElement parentHandle) {
137
		if (annotation instanceof CompletionOnMarkerAnnotationName) {
138
			if (hasEmptyName(annotation.type, assistNode)) {
139
				super.enterAnnotation(annotation, null, parentHandle);
140
				return null;
141
			}
142
		}
143
		return super.enterAnnotation(annotation, parentInfo, parentHandle);
144
	}
145
	
146
	protected Object getMemberValue(
147
			org.eclipse.jdt.internal.core.MemberValuePair memberValuePair,
148
			Expression expression) {
149
		if (expression instanceof CompletionOnSingleNameReference) {
150
			CompletionOnSingleNameReference reference = (CompletionOnSingleNameReference) expression;
151
			if (reference.token.length == 0) return null;
152
		} else if (expression instanceof CompletionOnQualifiedNameReference) {
153
			CompletionOnQualifiedNameReference reference = (CompletionOnQualifiedNameReference) expression;
154
			if (reference.tokens[reference.tokens.length - 1].length == 0) return null;
155
		}
156
		return super.getMemberValue(memberValuePair, expression);
157
	}
158
	protected IMemberValuePair[] getMemberValuePairs(MemberValuePair[] memberValuePairs) {
159
		int membersLength = memberValuePairs.length;
160
		int membersCount = 0;
161
		IMemberValuePair[] members = new IMemberValuePair[membersLength];
162
		next : for (int j = 0; j < membersLength; j++) {
163
			if (memberValuePairs[j] instanceof CompletionOnMemberValueName) continue next;
164
			
165
			members[membersCount++] = getMemberValuePair(memberValuePairs[j]);
166
		}
167
		
168
		if (membersCount > membersLength) {
169
			System.arraycopy(members, 0, members, 0, membersCount);
170
		}
171
		return members;
172
	}
173
174
	protected static boolean hasEmptyName(TypeReference reference, ASTNode assistNode) {
175
		if (reference == null) return false;
176
		
177
		if (reference.sourceStart <= assistNode.sourceStart && assistNode.sourceEnd <= reference.sourceEnd) return false;
178
		
179
		if (reference instanceof CompletionOnSingleTypeReference ||
180
				reference instanceof CompletionOnQualifiedTypeReference ||
181
				reference instanceof CompletionOnParameterizedQualifiedTypeReference) {
182
			char[][] typeName = reference.getTypeName();
183
			if (typeName[typeName.length - 1].length == 0) return true;
184
		}
185
		if (reference instanceof ParameterizedSingleTypeReference) {
186
			ParameterizedSingleTypeReference parameterizedReference = (ParameterizedSingleTypeReference) reference;
187
			TypeReference[] typeArguments = parameterizedReference.typeArguments;
188
			if (typeArguments != null) {
189
				for (int i = 0; i < typeArguments.length; i++) {
190
					if (hasEmptyName(typeArguments[i], assistNode)) return true;
191
				}
192
			}
193
		} else if (reference instanceof ParameterizedQualifiedTypeReference) {
194
			ParameterizedQualifiedTypeReference parameterizedReference = (ParameterizedQualifiedTypeReference) reference;
195
			TypeReference[][] typeArguments = parameterizedReference.typeArguments;
196
			if (typeArguments != null) {
197
				for (int i = 0; i < typeArguments.length; i++) {
198
					if (typeArguments[i] != null) {
199
						for (int j = 0; j < typeArguments[i].length; j++) {
200
							if (hasEmptyName(typeArguments[i][j], assistNode)) return true;
201
						}
202
					}
203
				}
204
			}
205
		}
206
		return false;
207
	}
208
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistTypeParameter.java (+30 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.codeassist.impl;
12
13
import java.util.Map;
14
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.jdt.core.JavaModelException;
17
import org.eclipse.jdt.internal.core.JavaElement;
18
import org.eclipse.jdt.internal.core.TypeParameter;
19
20
public class AssistTypeParameter extends TypeParameter {
21
	private Map infoCache;
22
	public AssistTypeParameter(JavaElement parent, String name, Map infoCache) {
23
		super(parent, name);
24
		this.infoCache = infoCache;
25
	}
26
	
27
	public Object getElementInfo(IProgressMonitor monitor) throws JavaModelException {
28
		return infoCache.get(this);
29
	}
30
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistCompilationUnit.java (+55 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.codeassist.impl;
12
13
import java.util.Map;
14
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.jdt.core.ICompilationUnit;
17
import org.eclipse.jdt.core.IImportContainer;
18
import org.eclipse.jdt.core.IPackageDeclaration;
19
import org.eclipse.jdt.core.IType;
20
import org.eclipse.jdt.core.JavaModelException;
21
import org.eclipse.jdt.core.WorkingCopyOwner;
22
import org.eclipse.jdt.internal.core.CompilationUnit;
23
import org.eclipse.jdt.internal.core.JavaElementInfo;
24
import org.eclipse.jdt.internal.core.PackageFragment;
25
26
public class AssistCompilationUnit extends CompilationUnit {
27
	private Map infoCache;
28
	private Map bindingCache;
29
	public AssistCompilationUnit(ICompilationUnit compilationUnit, WorkingCopyOwner owner, Map bindingCache, Map infoCache) {
30
		super((PackageFragment)compilationUnit.getParent(), compilationUnit.getElementName(), owner);
31
		this.bindingCache = bindingCache;
32
		this.infoCache = infoCache;
33
	}
34
	
35
	public Object getElementInfo(IProgressMonitor monitor) throws JavaModelException {
36
		return infoCache.get(this);
37
	}
38
	
39
	public IImportContainer getImportContainer() {
40
		return new AssistImportContainer(this, this.infoCache);
41
	}
42
	
43
	public IPackageDeclaration getPackageDeclaration(String pkg) {
44
		return new AssistPackageDeclaration(this, pkg, this.infoCache);
45
	}
46
	
47
	public IType getType(String typeName) {
48
		return new AssistSourceType(this, typeName, this.bindingCache, this.infoCache);
49
	}
50
	
51
	public boolean hasChildren() throws JavaModelException {
52
		JavaElementInfo info = (JavaElementInfo)this.infoCache.get(this);
53
		return info.getChildren().length > 0;
54
	}
55
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceField.java (+69 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.codeassist.impl;
12
13
import java.util.Map;
14
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.jdt.core.IAnnotation;
17
import org.eclipse.jdt.core.IType;
18
import org.eclipse.jdt.core.JavaModelException;
19
import org.eclipse.jdt.internal.compiler.lookup.Binding;
20
import org.eclipse.jdt.internal.core.JavaElement;
21
import org.eclipse.jdt.internal.core.ResolvedSourceField;
22
23
public class AssistSourceField extends ResolvedSourceField {
24
	private Map bindingCache;
25
	private Map infoCache;
26
	
27
	private String uniqueKey;
28
	
29
	public AssistSourceField(JavaElement parent, String name, Map bindingCache, Map infoCache) {
30
		super(parent, name, null);
31
		this.bindingCache = bindingCache;
32
		this.infoCache = infoCache;
33
	}
34
	
35
	public Object getElementInfo(IProgressMonitor monitor) throws JavaModelException {
36
		return infoCache.get(this);
37
	}
38
	
39
	/* (non-Javadoc)
40
	 * @see org.eclipse.jdt.internal.core.SourceField#getKey()
41
	 */
42
	public String getKey() {
43
		if (this.uniqueKey == null) {
44
			Binding binding = (Binding) this.bindingCache.get(this);
45
			if (binding != null) {
46
				this.uniqueKey = new String(binding.computeUniqueKey());
47
			}
48
		}
49
		return this.uniqueKey;
50
	}
51
	
52
	public boolean isResolved() {
53
		return getKey() != null;
54
	}
55
	
56
	protected void toStringInfo(int tab, StringBuffer buffer, Object info,boolean showResolvedInfo) {
57
		super.toStringInfo(tab, buffer, info, showResolvedInfo && this.isResolved());
58
	}
59
	
60
	public IAnnotation getAnnotation(String annotationName) {
61
		return new AssistAnnotation(this, annotationName, this.infoCache);
62
	}
63
	
64
	public IType getType(String typeName, int count) {
65
		AssistSourceType type = new AssistSourceType(this, typeName, this.bindingCache, this.infoCache);
66
		type.occurrenceCount = count;
67
		return type;
68
	}
69
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/CompletionElementNotifier.java (+216 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.codeassist;
12
13
import java.util.Map;
14
15
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnAnnotationOfType;
17
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnArgumentName;
18
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnFieldName;
19
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnFieldType;
20
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnImportReference;
21
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnKeyword;
22
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnKeyword2;
23
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnMethodName;
24
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnMethodReturnType;
25
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnMethodTypeParameter;
26
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnPackageReference;
27
import org.eclipse.jdt.internal.compiler.SourceElementNotifier;
28
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
29
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
30
import org.eclipse.jdt.internal.compiler.ast.Argument;
31
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
32
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
33
import org.eclipse.jdt.internal.compiler.ast.ImportReference;
34
import org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression;
35
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
36
import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
37
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
38
import org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToInt;
39
40
public class CompletionElementNotifier extends SourceElementNotifier {
41
	
42
	private ASTNode assistNode;
43
	
44
	public CompletionElementNotifier(
45
			CompletionUnitStructureRequestor requestor,
46
			boolean reportLocalDeclarations,
47
			ASTNode assistNode) {
48
		super(requestor, reportLocalDeclarations);
49
		this.assistNode = assistNode;
50
	}
51
	
52
	protected char[][][] getArguments(Argument[] arguments) {
53
		int argumentLength = arguments.length;
54
		char[][] argumentTypes = new char[argumentLength][];
55
		char[][] argumentNames = new char[argumentLength][];
56
		int argumentCount = 0;
57
		next : for (int i = 0; i < argumentLength; i++) {
58
			Argument argument = arguments[i];
59
			
60
			if (argument instanceof CompletionOnArgumentName && argument.name.length == 0) continue next;
61
			
62
			argumentTypes[argumentCount] = CharOperation.concatWith(argument.type.getParameterizedTypeName(), '.');
63
			argumentNames[argumentCount++] = argument.name;
64
		}
65
		
66
		if (argumentCount < argumentLength) {
67
			System.arraycopy(argumentTypes, 0, argumentTypes = new char[argumentCount][], 0, argumentCount);
68
			System.arraycopy(argumentNames, 0, argumentNames = new char[argumentCount][], 0, argumentCount);
69
		}
70
		
71
		return new char[][][] {argumentTypes, argumentNames};
72
	}
73
	
74
	protected char[][] getInterfaceNames(TypeDeclaration typeDeclaration) {
75
		char[][] interfaceNames = null;
76
		int superInterfacesLength = 0;
77
		TypeReference[] superInterfaces = typeDeclaration.superInterfaces;
78
		if (superInterfaces != null) {
79
			superInterfacesLength = superInterfaces.length;
80
			interfaceNames = new char[superInterfacesLength][];
81
		} else {
82
			if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) {
83
				// see PR 3442
84
				QualifiedAllocationExpression alloc = typeDeclaration.allocation;
85
				if (alloc != null && alloc.type != null) {
86
					superInterfaces = new TypeReference[] { alloc.type};
87
					superInterfacesLength = 1;
88
					interfaceNames = new char[1][];
89
				}
90
			}
91
		}
92
		if (superInterfaces != null) {
93
			int superInterfaceCount = 0;
94
			next: for (int i = 0; i < superInterfacesLength; i++) {
95
				TypeReference superInterface = superInterfaces[i];
96
				
97
				if (superInterface instanceof CompletionOnKeyword) continue next;
98
				if (CompletionUnitStructureRequestor.hasEmptyName(superInterface, this.assistNode)) continue next;
99
				
100
				interfaceNames[superInterfaceCount++] = CharOperation.concatWith(superInterface.getParameterizedTypeName(), '.'); 
101
			}
102
			
103
			if (superInterfaceCount == 0) return null;
104
			if (superInterfaceCount < superInterfacesLength) {
105
				System.arraycopy(interfaceNames, 0, interfaceNames = new char[superInterfaceCount][], 0, superInterfaceCount);
106
			}
107
		}
108
		return interfaceNames;
109
	}
110
	
111
	protected char[] getSuperclassName(TypeDeclaration typeDeclaration) {
112
		TypeReference superclass = typeDeclaration.superclass;
113
		
114
		if (superclass instanceof CompletionOnKeyword) return null;
115
		if (CompletionUnitStructureRequestor.hasEmptyName(superclass, this.assistNode)) return null;
116
				
117
		return superclass != null ? CharOperation.concatWith(superclass.getParameterizedTypeName(), '.') : null;
118
	}
119
	
120
	protected char[][] getThrownExceptions(AbstractMethodDeclaration methodDeclaration) {
121
		char[][] thrownExceptionTypes = null;
122
		TypeReference[] thrownExceptions = methodDeclaration.thrownExceptions;
123
		if (thrownExceptions != null) {
124
			int thrownExceptionLength = thrownExceptions.length;
125
			int thrownExceptionCount = 0;
126
			thrownExceptionTypes = new char[thrownExceptionLength][];
127
			next : for (int i = 0; i < thrownExceptionLength; i++) {
128
				TypeReference thrownException = thrownExceptions[i];
129
				
130
				if (thrownException instanceof CompletionOnKeyword) continue next;
131
				if (CompletionUnitStructureRequestor.hasEmptyName(thrownException, this.assistNode)) continue next;
132
				
133
				thrownExceptionTypes[thrownExceptionCount++] = 
134
					CharOperation.concatWith(thrownException.getParameterizedTypeName(), '.'); 
135
			}
136
			
137
			if (thrownExceptionCount == 0) return null;
138
			if (thrownExceptionCount < thrownExceptionLength) {
139
				System.arraycopy(thrownExceptionTypes, 0, thrownExceptionTypes = new char[thrownExceptionCount][], 0, thrownExceptionCount);
140
			}
141
		}
142
		return thrownExceptionTypes;
143
	}
144
	
145
	protected char[][] getTypeParameterBounds(TypeParameter typeParameter) {
146
		TypeReference firstBound = typeParameter.type;
147
		TypeReference[] otherBounds = typeParameter.bounds;
148
		char[][] typeParameterBounds = null;
149
		if (firstBound != null) {
150
			if (otherBounds != null) {
151
				int otherBoundsLength = otherBounds.length;
152
				char[][] boundNames = new char[otherBoundsLength+1][];
153
				int boundCount = 0;
154
				if (!CompletionUnitStructureRequestor.hasEmptyName(firstBound, this.assistNode)) {
155
					boundNames[boundCount++] = CharOperation.concatWith(firstBound.getParameterizedTypeName(), '.');
156
				}
157
				for (int j = 0; j < otherBoundsLength; j++) {
158
					TypeReference otherBound = otherBounds[j];
159
					if (!CompletionUnitStructureRequestor.hasEmptyName(otherBound, this.assistNode)) {
160
						boundNames[boundCount++] = 
161
							CharOperation.concatWith(otherBound.getParameterizedTypeName(), '.');
162
					}
163
				}
164
				
165
				if (boundCount == 0) {
166
					boundNames = CharOperation.NO_CHAR_CHAR;
167
				} else if (boundCount < otherBoundsLength + 1){
168
					System.arraycopy(boundNames, 0, boundNames = new char[boundCount][], 0, boundCount);
169
				}
170
				typeParameterBounds = boundNames;
171
			} else {
172
				if (!CompletionUnitStructureRequestor.hasEmptyName(firstBound, this.assistNode)) {
173
					typeParameterBounds = new char[][] { CharOperation.concatWith(firstBound.getParameterizedTypeName(), '.')};
174
				} else {
175
					typeParameterBounds = CharOperation.NO_CHAR_CHAR;
176
				}
177
			}
178
		} else {
179
			typeParameterBounds = CharOperation.NO_CHAR_CHAR;
180
		}
181
		
182
		return typeParameterBounds;
183
	}
184
	
185
	protected void notifySourceElementRequestor(AbstractMethodDeclaration methodDeclaration) {
186
		if (methodDeclaration instanceof CompletionOnMethodReturnType) return;
187
		if (methodDeclaration instanceof CompletionOnMethodTypeParameter) return;
188
		if (methodDeclaration instanceof CompletionOnMethodName) return;
189
		super.notifySourceElementRequestor(methodDeclaration);
190
	}
191
	
192
	public void notifySourceElementRequestor(CompilationUnitDeclaration parsedUnit, int sourceStart, int sourceEnd, boolean reportReference, HashtableOfObjectToInt sourceEndsMap, Map nodesToCategoriesMap) {
193
		super.notifySourceElementRequestor(parsedUnit, sourceStart, sourceEnd, reportReference, sourceEndsMap, nodesToCategoriesMap);
194
	}
195
	
196
	protected void notifySourceElementRequestor(FieldDeclaration fieldDeclaration, TypeDeclaration declaringType) {
197
		if (fieldDeclaration instanceof CompletionOnFieldType) return;
198
		if (fieldDeclaration instanceof CompletionOnFieldName) return;
199
		super.notifySourceElementRequestor(fieldDeclaration, declaringType);
200
	}
201
	
202
	protected void notifySourceElementRequestor(ImportReference importReference, boolean isPackage) {
203
		if (importReference instanceof CompletionOnKeyword2) return;
204
		if (importReference instanceof CompletionOnImportReference ||
205
				importReference instanceof CompletionOnPackageReference) {
206
			if (importReference.tokens[importReference.tokens.length - 1].length == 0) return;
207
		}
208
		
209
		super.notifySourceElementRequestor(importReference, isPackage);
210
	}
211
	
212
	protected void notifySourceElementRequestor(TypeDeclaration typeDeclaration, boolean notifyTypePresence, TypeDeclaration declaringType) {
213
		if (typeDeclaration instanceof CompletionOnAnnotationOfType) return;
214
		super.notifySourceElementRequestor(typeDeclaration, notifyTypePresence, declaringType);
215
	}
216
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceType.java (+100 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.codeassist.impl;
12
13
import java.util.Map;
14
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.jdt.core.IAnnotation;
17
import org.eclipse.jdt.core.IField;
18
import org.eclipse.jdt.core.IInitializer;
19
import org.eclipse.jdt.core.IMethod;
20
import org.eclipse.jdt.core.IType;
21
import org.eclipse.jdt.core.ITypeParameter;
22
import org.eclipse.jdt.core.JavaModelException;
23
import org.eclipse.jdt.internal.compiler.lookup.Binding;
24
import org.eclipse.jdt.internal.core.JavaElement;
25
import org.eclipse.jdt.internal.core.ResolvedSourceType;
26
27
public class AssistSourceType extends ResolvedSourceType {
28
	private Map bindingCache;
29
	private Map infoCache;
30
	
31
	private String uniqueKey;
32
	
33
	public AssistSourceType(JavaElement parent, String name, Map bindingCache, Map infoCache) {
34
		super(parent, name, null);
35
		this.bindingCache = bindingCache;
36
		this.infoCache = infoCache;
37
	}
38
	
39
	public Object getElementInfo(IProgressMonitor monitor) throws JavaModelException {
40
		return infoCache.get(this);
41
	}
42
	
43
	public String getFullyQualifiedParameterizedName() throws JavaModelException {
44
		if (this.isResolved()) {
45
			return getFullyQualifiedParameterizedName(getFullyQualifiedName(), this.getKey());
46
		}
47
		return getFullyQualifiedName('.', true/*show parameters*/);
48
	}
49
	
50
	/* (non-Javadoc)
51
	 * @see org.eclipse.jdt.internal.core.SourceType#getKey()
52
	 */
53
	public String getKey() {
54
		if (this.uniqueKey == null) {
55
			Binding binding = (Binding) this.bindingCache.get(this);
56
			if (binding != null) {
57
				this.uniqueKey = new String(binding.computeUniqueKey());
58
			}
59
		}
60
		return this.uniqueKey;
61
	}
62
	
63
	public boolean isResolved() {
64
		return getKey() != null;
65
	}
66
	
67
	protected void toStringInfo(int tab, StringBuffer buffer, Object info,boolean showResolvedInfo) {
68
		super.toStringInfo(tab, buffer, info, showResolvedInfo && this.isResolved());
69
	}
70
	
71
	public IAnnotation getAnnotation(String annotationName) {
72
		return new AssistAnnotation(this, annotationName, this.infoCache);
73
	}
74
	
75
	public IField getField(String fieldName) {
76
		return new AssistSourceField(this, fieldName, this.bindingCache, this.infoCache);
77
	}
78
	
79
	public IInitializer getInitializer(int count) {
80
		return new AssistInitializer(this, count, this.bindingCache, this.infoCache);
81
	}
82
	
83
	public IMethod getMethod(String selector, String[] parameterTypeSignatures) {
84
		return new AssistSourceMethod(this, selector, parameterTypeSignatures, this.bindingCache, this.infoCache);
85
	}
86
	
87
	public IType getType(String typeName) {
88
		return new AssistSourceType(this, typeName, this.bindingCache, this.infoCache);
89
	}
90
	
91
	public IType getType(String typeName, int count) {
92
		AssistSourceType type = new AssistSourceType(this, typeName, this.bindingCache, this.infoCache);
93
		type.occurrenceCount = count;
94
		return type;
95
	}
96
	
97
	public ITypeParameter getTypeParameter(String typeParameterName) {
98
		return new AssistTypeParameter(this, typeParameterName, this.infoCache);
99
	}
100
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistImportContainer.java (+35 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.codeassist.impl;
12
13
import java.util.Map;
14
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.jdt.core.IImportDeclaration;
17
import org.eclipse.jdt.core.JavaModelException;
18
import org.eclipse.jdt.internal.core.CompilationUnit;
19
import org.eclipse.jdt.internal.core.ImportContainer;
20
21
public class AssistImportContainer extends ImportContainer {
22
	private Map infoCache;
23
	public AssistImportContainer(CompilationUnit parent, Map infoCache) {
24
		super(parent);
25
		this.infoCache = infoCache;
26
	}
27
	
28
	public Object getElementInfo(IProgressMonitor monitor) throws JavaModelException {
29
		return infoCache.get(this);
30
	}
31
	
32
	protected IImportDeclaration getImport(String importName, boolean isOnDemand) {
33
		return new AssistImportDeclaration(this, importName, isOnDemand, this.infoCache);
34
	}
35
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistImportDeclaration.java (+30 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.codeassist.impl;
12
13
import java.util.Map;
14
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.jdt.core.JavaModelException;
17
import org.eclipse.jdt.internal.core.ImportContainer;
18
import org.eclipse.jdt.internal.core.ImportDeclaration;
19
20
public class AssistImportDeclaration extends ImportDeclaration {
21
	private Map infoCache;
22
	public AssistImportDeclaration(ImportContainer parent, String name, boolean isOnDemand, Map infoCache) {
23
		super(parent, name, isOnDemand);
24
		this.infoCache = infoCache;
25
	}
26
	
27
	public Object getElementInfo(IProgressMonitor monitor) throws JavaModelException {
28
		return infoCache.get(this);
29
	}
30
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceMethod.java (+74 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.codeassist.impl;
12
13
import java.util.Map;
14
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.jdt.core.IAnnotation;
17
import org.eclipse.jdt.core.IType;
18
import org.eclipse.jdt.core.ITypeParameter;
19
import org.eclipse.jdt.core.JavaModelException;
20
import org.eclipse.jdt.internal.compiler.lookup.Binding;
21
import org.eclipse.jdt.internal.core.JavaElement;
22
import org.eclipse.jdt.internal.core.ResolvedSourceMethod;
23
24
public class AssistSourceMethod extends ResolvedSourceMethod {
25
	private Map bindingCache;
26
	private Map infoCache;
27
	
28
	private String uniqueKey;
29
	
30
	public AssistSourceMethod(JavaElement parent, String name, String[] parameterTypes, Map bindingCache, Map infoCache) {
31
		super(parent, name, parameterTypes, null);
32
		this.bindingCache = bindingCache;
33
		this.infoCache = infoCache;
34
	}
35
	
36
	public Object getElementInfo(IProgressMonitor monitor) throws JavaModelException {
37
		return infoCache.get(this);
38
	}
39
	
40
	/* (non-Javadoc)
41
	 * @see org.eclipse.jdt.internal.core.SourceMethod#getKey()
42
	 */
43
	public String getKey() {
44
		if (this.uniqueKey == null) {
45
			Binding binding = (Binding) this.bindingCache.get(this);
46
			if (binding != null) {
47
				this.uniqueKey = new String(binding.computeUniqueKey());
48
			}
49
		}
50
		return this.uniqueKey;
51
	}
52
	
53
	public boolean isResolved() {
54
		return getKey() != null;
55
	}
56
	
57
	protected void toStringInfo(int tab, StringBuffer buffer, Object info,boolean showResolvedInfo) {
58
		super.toStringInfo(tab, buffer, info, showResolvedInfo && this.isResolved());
59
	}
60
	
61
	public IAnnotation getAnnotation(String annotationName) {
62
		return new AssistAnnotation(this, annotationName, this.infoCache);
63
	}
64
	
65
	public IType getType(String typeName, int count) {
66
		AssistSourceType type = new AssistSourceType(this, typeName, this.bindingCache, this.infoCache);
67
		type.occurrenceCount = count;
68
		return type;
69
	}
70
	
71
	public ITypeParameter getTypeParameter(String typeParameterName) {
72
		return new AssistTypeParameter(this, typeParameterName, this.infoCache);
73
	}
74
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistInitializer.java (+39 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.codeassist.impl;
12
13
import java.util.Map;
14
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.jdt.core.IType;
17
import org.eclipse.jdt.core.JavaModelException;
18
import org.eclipse.jdt.internal.core.Initializer;
19
import org.eclipse.jdt.internal.core.JavaElement;
20
21
public class AssistInitializer extends Initializer {
22
	private Map bindingCache;
23
	private Map infoCache;
24
	public AssistInitializer(JavaElement parent, int count, Map bindingCache, Map infoCache) {
25
		super(parent, count);
26
		this.bindingCache = bindingCache;
27
		this.infoCache = infoCache;
28
	}
29
	
30
	public Object getElementInfo(IProgressMonitor monitor) throws JavaModelException {
31
		return infoCache.get(this);
32
	}
33
	
34
	public IType getType(String typeName, int count) {
35
		AssistSourceType type = new AssistSourceType(this, typeName, this.bindingCache, this.infoCache);
36
		type.occurrenceCount = count;
37
		return type;
38
	}
39
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistPackageDeclaration.java (+35 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.codeassist.impl;
12
13
import java.util.Map;
14
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.jdt.core.IAnnotation;
17
import org.eclipse.jdt.core.JavaModelException;
18
import org.eclipse.jdt.internal.core.CompilationUnit;
19
import org.eclipse.jdt.internal.core.PackageDeclaration;
20
21
public class AssistPackageDeclaration extends PackageDeclaration {
22
	private Map infoCache;
23
	public AssistPackageDeclaration(CompilationUnit parent, String name, Map infoCache) {
24
		super(parent, name);
25
		this.infoCache = infoCache;
26
	}
27
	
28
	public Object getElementInfo(IProgressMonitor monitor) throws JavaModelException {
29
		return infoCache.get(this);
30
	}
31
	
32
	public IAnnotation getAnnotation(String name) {
33
		return new AssistAnnotation(this, name, this.infoCache);
34
	}
35
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java (+793 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.codeassist;
12
13
import java.util.HashMap;
14
import java.util.Map;
15
16
import org.eclipse.jdt.core.ICompilationUnit;
17
import org.eclipse.jdt.core.IInitializer;
18
import org.eclipse.jdt.core.IJavaElement;
19
import org.eclipse.jdt.core.ISourceRange;
20
import org.eclipse.jdt.core.IType;
21
import org.eclipse.jdt.core.ITypeRoot;
22
import org.eclipse.jdt.core.JavaModelException;
23
import org.eclipse.jdt.core.WorkingCopyOwner;
24
import org.eclipse.jdt.core.compiler.CharOperation;
25
import org.eclipse.jdt.internal.codeassist.complete.CompletionParser;
26
import org.eclipse.jdt.internal.codeassist.impl.AssistCompilationUnit;
27
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
28
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
29
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
30
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
31
import org.eclipse.jdt.internal.compiler.ast.Initializer;
32
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
33
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
34
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
35
import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding;
36
import org.eclipse.jdt.internal.compiler.lookup.Binding;
37
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
38
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
39
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
40
import org.eclipse.jdt.internal.compiler.lookup.ImportBinding;
41
import org.eclipse.jdt.internal.compiler.lookup.InvocationSite;
42
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
43
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
44
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
45
import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
46
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
47
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
48
import org.eclipse.jdt.internal.compiler.lookup.Scope;
49
import org.eclipse.jdt.internal.compiler.lookup.SignatureWrapper;
50
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
51
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
52
import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;
53
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
54
import org.eclipse.jdt.internal.compiler.util.ObjectVector;
55
import org.eclipse.jdt.internal.core.CompilationUnitElementInfo;
56
import org.eclipse.jdt.internal.core.JavaElement;
57
import org.eclipse.jdt.internal.core.LocalVariable;
58
import org.eclipse.jdt.internal.core.util.Util;
59
60
public class InternalExtendedCompletionContext {
61
	private static Util.BindingsToNodesMap EmptyNodeMap = new Util.BindingsToNodesMap() {
62
		public ASTNode get(Binding binding) {
63
			return null;
64
		}
65
	};
66
	
67
	private InternalCompletionContext completionContext;
68
	
69
	// static data
70
	private ITypeRoot typeRoot;
71
	private CompilationUnitDeclaration compilationUnitDeclaration;
72
	private LookupEnvironment lookupEnvironment;
73
	private Scope assistScope;
74
	private ASTNode assistNode;
75
	private WorkingCopyOwner owner;
76
	
77
	private CompletionParser parser;
78
	
79
	// computed data
80
	private boolean hasComputedVisibleElementBindings;
81
	private ObjectVector visibleLocalVariables;
82
	private ObjectVector visibleFields;
83
	private ObjectVector visibleMethods;
84
	
85
	private boolean hasComputedEnclosingJavaElements;
86
	Map bindingsToNodes;
87
	private Map bindingsToHandles;
88
	private ICompilationUnit compilationUnit;
89
	
90
	public InternalExtendedCompletionContext(
91
			InternalCompletionContext completionContext,
92
			ITypeRoot typeRoot,
93
			CompilationUnitDeclaration compilationUnitDeclaration,
94
			LookupEnvironment lookupEnvironment,
95
			Scope assistScope,
96
			ASTNode assistNode,
97
			WorkingCopyOwner owner,
98
			CompletionParser parser) {
99
		this.completionContext = completionContext;
100
		this.typeRoot = typeRoot;
101
		this.compilationUnitDeclaration = compilationUnitDeclaration;
102
		this.lookupEnvironment = lookupEnvironment;
103
		this.assistScope = assistScope;
104
		this.assistNode = assistNode;
105
		this.owner = owner;
106
		this.parser = parser;
107
	}
108
	
109
	private void computeEnclosingJavaElements() {
110
		this.hasComputedEnclosingJavaElements = true;
111
		
112
		if (this.typeRoot == null) return;
113
		
114
		if (this.typeRoot.getElementType() == IJavaElement.COMPILATION_UNIT) {
115
	 		ICompilationUnit original = (org.eclipse.jdt.core.ICompilationUnit)this.typeRoot;
116
			
117
			HashMap handleToBinding = new HashMap();
118
			HashMap bindingToHandle = new HashMap();
119
			HashMap handleToInfo = new HashMap();
120
			
121
			org.eclipse.jdt.core.ICompilationUnit handle = new AssistCompilationUnit(original, this.owner, handleToBinding, handleToInfo);
122
			CompilationUnitElementInfo info = new CompilationUnitElementInfo();
123
			
124
			handleToInfo.put(handle, info);
125
			
126
			CompletionUnitStructureRequestor structureRequestor = 
127
				new CompletionUnitStructureRequestor(
128
						handle,
129
						info,
130
						this.parser,
131
						this.assistNode,
132
						handleToBinding,
133
						bindingToHandle,
134
						handleToInfo);
135
			
136
			CompletionElementNotifier notifier =
137
				new CompletionElementNotifier(
138
						structureRequestor,
139
						true,
140
						this.assistNode);
141
			
142
			notifier.notifySourceElementRequestor(
143
					this.compilationUnitDeclaration,
144
					this.compilationUnitDeclaration.sourceStart,
145
					this.compilationUnitDeclaration.sourceEnd,
146
					false,
147
					this.parser.sourceEnds,
148
					new HashMap());
149
			
150
			this.bindingsToHandles = bindingToHandle;
151
			this.compilationUnit = handle;
152
		}
153
	}
154
	
155
	private void computeVisibleElementBindings() {
156
		this.hasComputedVisibleElementBindings = true;
157
		
158
		Scope scope = this.assistScope;
159
		ASTNode astNode = this.assistNode;
160
		boolean notInJavadoc = this.completionContext.javadoc == 0;
161
		
162
		this.visibleLocalVariables = new ObjectVector();
163
		this.visibleFields = new ObjectVector();
164
		this.visibleMethods = new ObjectVector();
165
		this.bindingsToNodes = new HashMap();
166
		
167
		ReferenceContext referenceContext = scope.referenceContext();
168
		if (referenceContext instanceof AbstractMethodDeclaration) {
169
			// completion is inside a method body
170
			searchVisibleVariablesAndMethods(scope, visibleLocalVariables, visibleFields, visibleMethods, notInJavadoc);
171
		} else if (referenceContext instanceof TypeDeclaration) {
172
			TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
173
			FieldDeclaration[] fields = typeDeclaration.fields;
174
			if (fields != null) {
175
				done : for (int i = 0; i < fields.length; i++) {
176
					if (fields[i] instanceof Initializer) {
177
						Initializer initializer = (Initializer) fields[i];
178
						if (initializer.block.sourceStart <= astNode.sourceStart &&
179
								astNode.sourceStart < initializer.bodyEnd) {
180
							// completion is inside an initializer
181
							searchVisibleVariablesAndMethods(scope, visibleLocalVariables, visibleFields, visibleMethods, notInJavadoc);
182
							break done;
183
						}
184
					} else {
185
						FieldDeclaration fieldDeclaration = fields[i];
186
						if (fieldDeclaration.initialization != null && 
187
								fieldDeclaration.initialization.sourceStart <= astNode.sourceStart &&
188
								astNode.sourceEnd <= fieldDeclaration.initialization.sourceEnd) {
189
							// completion is inside a field initializer
190
							searchVisibleVariablesAndMethods(scope, visibleLocalVariables, visibleFields, visibleMethods, notInJavadoc);
191
							break done;
192
						}  
193
					}
194
				}
195
			}
196
		}
197
	}
198
	
199
	public IJavaElement getEnclosingElement() {
200
		try {
201
			if (!this.hasComputedEnclosingJavaElements) {
202
				this.computeEnclosingJavaElements();
203
			}
204
			if (this.compilationUnit == null) return null;
205
			IJavaElement enclosingElement = compilationUnit.getElementAt(this.completionContext.offset);
206
			return enclosingElement == null ? this.compilationUnit : enclosingElement;
207
		} catch (JavaModelException e) {
208
			Util.log(e, "Cannot compute enclosing element"); //$NON-NLS-1$
209
			return null;
210
		}
211
	}
212
	
213
	private JavaElement getJavaElement(LocalVariableBinding binding) {
214
		LocalDeclaration local = binding.declaration;
215
		
216
		JavaElement parent = null;
217
		ReferenceContext referenceContext = binding.declaringScope.referenceContext();
218
		if (referenceContext instanceof AbstractMethodDeclaration) {
219
			AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) referenceContext;
220
			parent = this.getJavaElementOfCompilationUnit(methodDeclaration.binding);
221
		} else if (referenceContext instanceof TypeDeclaration){
222
			// Local variable is declared inside an initializer
223
			TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
224
			
225
			IType type = (IType)this.getJavaElementOfCompilationUnit(typeDeclaration.binding);
226
			if (type != null) {
227
				try {
228
					IInitializer[] initializers = type.getInitializers();
229
					if (initializers != null) {
230
						done : for (int i = 0; i < initializers.length; i++) {
231
							IInitializer initializer = initializers[i];
232
							ISourceRange sourceRange = initializer.getSourceRange();
233
							if (sourceRange != null) {
234
								int initializerStart = sourceRange.getOffset();
235
								int initializerEnd = initializerStart + sourceRange.getLength();
236
								if (initializerStart <= local.sourceStart &&
237
										local.sourceEnd <= initializerEnd) {
238
									parent = (JavaElement)initializer;
239
									break done;
240
								}
241
							}
242
						}
243
					}
244
				} catch (JavaModelException e) {
245
					return null;
246
				}
247
			}
248
		}
249
		if (parent == null) return null;
250
		
251
		return new LocalVariable(
252
				parent,
253
				new String(local.name),
254
				local.declarationSourceStart,
255
				local.declarationSourceEnd,
256
				local.sourceStart,
257
				local.sourceEnd,
258
				Util.typeSignature(local.type),
259
				binding.declaration.annotations);
260
	}
261
	
262
	private JavaElement getJavaElementOfCompilationUnit(Binding binding) {
263
		if (!this.hasComputedEnclosingJavaElements) {
264
			computeEnclosingJavaElements();
265
		}
266
		if (this.bindingsToHandles == null) return null;
267
		return (JavaElement)this.bindingsToHandles.get(binding);
268
	}
269
	
270
	private TypeBinding getTypeFromSignature(String typeSignature, Scope scope) {
271
		TypeBinding assignableTypeBinding = null;
272
		
273
		TypeVariableBinding[] typeVariables = Binding.NO_TYPE_VARIABLES;
274
		ReferenceContext referenceContext = scope.referenceContext();
275
		if (referenceContext instanceof AbstractMethodDeclaration) {
276
			AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) referenceContext;
277
			typeVariables = methodDeclaration.binding.typeVariables;
278
		}
279
		
280
		CompilationUnitDeclaration previousUnitBeingCompleted = lookupEnvironment.unitBeingCompleted;
281
		lookupEnvironment.unitBeingCompleted = this.compilationUnitDeclaration;
282
		try {
283
			
284
			SignatureWrapper wrapper = new SignatureWrapper(typeSignature.toCharArray());
285
			assignableTypeBinding = lookupEnvironment.getTypeFromTypeSignature(wrapper, typeVariables, this.assistScope.enclosingClassScope().referenceContext.binding, null);
286
			if (assignableTypeBinding instanceof ReferenceBinding) {
287
				assignableTypeBinding = BinaryTypeBinding.resolveType((ReferenceBinding)assignableTypeBinding, lookupEnvironment, true);
288
			}
289
		} catch (AbortCompilation e) {
290
			assignableTypeBinding = null;
291
		} finally {
292
			lookupEnvironment.unitBeingCompleted = previousUnitBeingCompleted;
293
		}
294
		return assignableTypeBinding;
295
	}
296
	
297
	public IJavaElement[] getVisibleElements(String typeSignature) {
298
		if (this.assistScope == null) return new IJavaElement[0];
299
		
300
		if (!this.hasComputedVisibleElementBindings) {
301
			this.computeVisibleElementBindings();
302
		}
303
		
304
		TypeBinding assignableTypeBinding = null;
305
		if (typeSignature != null) {
306
			assignableTypeBinding = this.getTypeFromSignature(typeSignature, this.assistScope);
307
			if (assignableTypeBinding == null) return new IJavaElement[0];
308
		}
309
		 
310
		int length = visibleLocalVariables.size() + visibleFields.size() + visibleMethods.size();
311
		if (length == 0) return new IJavaElement[0];
312
		
313
		IJavaElement[] result = new IJavaElement[length];
314
		
315
		int elementCount = 0;
316
		
317
		int size = visibleLocalVariables.size();
318
		if (size > 0) {
319
			next : for (int i = 0; i < size; i++) {
320
				LocalVariableBinding binding = (LocalVariableBinding) visibleLocalVariables.elementAt(i);
321
				if (assignableTypeBinding != null && !binding.type.isCompatibleWith(assignableTypeBinding)) continue next;
322
				result[elementCount++] = getJavaElement(binding);
323
			}
324
		
325
		}
326
		size = visibleFields.size();
327
		if (size > 0) {
328
			next : for (int i = 0; i < size; i++) {
329
				FieldBinding binding = (FieldBinding) visibleFields.elementAt(i);
330
				if (assignableTypeBinding != null && !binding.type.isCompatibleWith(assignableTypeBinding)) continue next;
331
				if (this.assistScope.isDefinedInSameUnit(binding.declaringClass)) {
332
					JavaElement field = getJavaElementOfCompilationUnit(binding);
333
					if (field != null) result[elementCount++] = field;
334
				} else {
335
					JavaElement field = Util.getUnresolvedJavaElement(binding, owner, EmptyNodeMap);
336
					if (field != null) result[elementCount++] = field.resolved(binding);
337
				}
338
			}
339
		
340
		}
341
		size = visibleMethods.size();
342
		if (size > 0) {
343
			next : for (int i = 0; i < size; i++) {
344
				MethodBinding binding = (MethodBinding) visibleMethods.elementAt(i);
345
				if (assignableTypeBinding != null && !binding.returnType.isCompatibleWith(assignableTypeBinding)) continue next;
346
				if (this.assistScope.isDefinedInSameUnit(binding.declaringClass)) {
347
					JavaElement method = getJavaElementOfCompilationUnit(binding);
348
					if (method != null) result[elementCount++] = method;
349
				} else {
350
					JavaElement method = Util.getUnresolvedJavaElement(binding, owner, EmptyNodeMap);
351
					if (method != null) result[elementCount++] = method.resolved(binding);
352
				}
353
				
354
			}
355
		}
356
		
357
		if (elementCount != result.length) {
358
			System.arraycopy(result, 0, result = new IJavaElement[elementCount], 0, elementCount);
359
		}
360
361
		return result;
362
	}
363
	
364
	private void searchVisibleFields(
365
			FieldBinding[] fields,
366
			ReferenceBinding receiverType,
367
			Scope scope,
368
			InvocationSite invocationSite,
369
			Scope invocationScope,
370
			boolean onlyStaticFields,
371
			ObjectVector localsFound,
372
			ObjectVector fieldsFound) {
373
		ObjectVector newFieldsFound = new ObjectVector();
374
		// Inherited fields which are hidden by subclasses are filtered out
375
		// No visibility checks can be performed without the scope & invocationSite
376
		
377
		next : for (int f = fields.length; --f >= 0;) {			
378
			FieldBinding field = fields[f];
379
380
			if (field.isSynthetic()) continue next;
381
			
382
			if (onlyStaticFields && !field.isStatic()) continue next;
383
			
384
			if (!field.canBeSeenBy(receiverType, invocationSite, scope)) continue next;
385
			
386
			for (int i = fieldsFound.size; --i >= 0;) {
387
				FieldBinding otherField = (FieldBinding) fieldsFound.elementAt(i);
388
				if (CharOperation.equals(field.name, otherField.name, true)) {
389
					continue next;
390
				}
391
			}
392
393
			for (int l = localsFound.size; --l >= 0;) {
394
				LocalVariableBinding local = (LocalVariableBinding) localsFound.elementAt(l);	
395
396
				if (CharOperation.equals(field.name, local.name, true)) {
397
					continue next;
398
				}
399
			}
400
			
401
			newFieldsFound.add(field);
402
		}
403
		
404
		fieldsFound.addAll(newFieldsFound);
405
	}
406
	
407
	private void searchVisibleFields(
408
			ReferenceBinding receiverType,
409
			Scope scope,
410
			InvocationSite invocationSite,
411
			Scope invocationScope,
412
			boolean onlyStaticFields,
413
			boolean notInJavadoc,
414
			ObjectVector localsFound,
415
			ObjectVector fieldsFound) {
416
417
		ReferenceBinding currentType = receiverType;
418
		ReferenceBinding[] interfacesToVisit = null;
419
		int nextPosition = 0;
420
		do {
421
			ReferenceBinding[] itsInterfaces = currentType.superInterfaces();
422
			if (notInJavadoc && itsInterfaces != Binding.NO_SUPERINTERFACES) {
423
				if (interfacesToVisit == null) {
424
					interfacesToVisit = itsInterfaces;
425
					nextPosition = interfacesToVisit.length;
426
				} else {
427
					int itsLength = itsInterfaces.length;
428
					if (nextPosition + itsLength >= interfacesToVisit.length)
429
						System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition);
430
					nextInterface : for (int a = 0; a < itsLength; a++) {
431
						ReferenceBinding next = itsInterfaces[a];
432
						for (int b = 0; b < nextPosition; b++)
433
							if (next == interfacesToVisit[b]) continue nextInterface;
434
						interfacesToVisit[nextPosition++] = next;
435
					}
436
				}
437
			}
438
439
			FieldBinding[] fields = currentType.availableFields();
440
			if(fields != null && fields.length > 0) {
441
				
442
				searchVisibleFields(
443
						fields,
444
						receiverType,
445
						scope,
446
						invocationSite,
447
						invocationScope,
448
						onlyStaticFields,
449
						localsFound,
450
						fieldsFound);
451
			}
452
			currentType = currentType.superclass();
453
		} while (notInJavadoc && currentType != null);
454
455
		if (notInJavadoc && interfacesToVisit != null) {
456
			for (int i = 0; i < nextPosition; i++) {
457
				ReferenceBinding anInterface = interfacesToVisit[i];
458
				FieldBinding[] fields = anInterface.availableFields();
459
				if(fields !=  null) {
460
					searchVisibleFields(
461
							fields,
462
							receiverType,
463
							scope,
464
							invocationSite,
465
							invocationScope,
466
							onlyStaticFields,
467
							localsFound,
468
							fieldsFound);
469
				}
470
471
				ReferenceBinding[] itsInterfaces = anInterface.superInterfaces();
472
				if (itsInterfaces != Binding.NO_SUPERINTERFACES) {
473
					int itsLength = itsInterfaces.length;
474
					if (nextPosition + itsLength >= interfacesToVisit.length)
475
						System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition);
476
					nextInterface : for (int a = 0; a < itsLength; a++) {
477
						ReferenceBinding next = itsInterfaces[a];
478
						for (int b = 0; b < nextPosition; b++)
479
							if (next == interfacesToVisit[b]) continue nextInterface;
480
						interfacesToVisit[nextPosition++] = next;
481
					}
482
				}
483
			}
484
		}
485
	}
486
487
	private void searchVisibleInterfaceMethods(
488
			ReferenceBinding[] itsInterfaces,
489
			ReferenceBinding receiverType,
490
			Scope scope,
491
			InvocationSite invocationSite,
492
			Scope invocationScope,
493
			boolean onlyStaticMethods,
494
			ObjectVector methodsFound) {
495
		if (itsInterfaces != Binding.NO_SUPERINTERFACES) {
496
			ReferenceBinding[] interfacesToVisit = itsInterfaces;
497
			int nextPosition = interfacesToVisit.length;
498
499
			for (int i = 0; i < nextPosition; i++) {
500
				ReferenceBinding currentType = interfacesToVisit[i];
501
				MethodBinding[] methods = currentType.availableMethods();
502
				if(methods != null) {
503
					searchVisibleLocalMethods(
504
							methods,
505
							receiverType,
506
							scope,
507
							invocationSite,
508
							invocationScope,
509
							onlyStaticMethods,
510
							methodsFound);
511
				}
512
513
				itsInterfaces = currentType.superInterfaces();
514
				if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) {
515
					int itsLength = itsInterfaces.length;
516
					if (nextPosition + itsLength >= interfacesToVisit.length)
517
						System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition);
518
					nextInterface : for (int a = 0; a < itsLength; a++) {
519
						ReferenceBinding next = itsInterfaces[a];
520
						for (int b = 0; b < nextPosition; b++)
521
							if (next == interfacesToVisit[b]) continue nextInterface;
522
						interfacesToVisit[nextPosition++] = next;
523
					}
524
				}
525
			}
526
		}
527
	}
528
	
529
	private void searchVisibleLocalMethods(
530
			MethodBinding[] methods,
531
			ReferenceBinding receiverType,
532
			Scope scope,
533
			InvocationSite invocationSite,
534
			Scope invocationScope,
535
			boolean onlyStaticMethods,
536
			ObjectVector methodsFound) {
537
		ObjectVector newMethodsFound =  new ObjectVector();
538
		// Inherited methods which are hidden by subclasses are filtered out
539
		// No visibility checks can be performed without the scope & invocationSite
540
541
		next : for (int f = methods.length; --f >= 0;) {
542
			MethodBinding method = methods[f];
543
544
			if (method.isSynthetic()) continue next;
545
546
			if (method.isDefaultAbstract())	continue next;
547
548
			if (method.isConstructor()) continue next;
549
			
550
			if (onlyStaticMethods && !method.isStatic()) continue next;
551
552
			if (!method.canBeSeenBy(receiverType, invocationSite, scope)) continue next;
553
			
554
			for (int i = methodsFound.size; --i >= 0;) {
555
				MethodBinding otherMethod = (MethodBinding) methodsFound.elementAt(i);
556
				if (method == otherMethod)
557
					continue next;
558
				
559
				if (CharOperation.equals(method.selector, otherMethod.selector, true)) {
560
					if (this.lookupEnvironment.methodVerifier().isMethodSubsignature(otherMethod, method)) {
561
						continue next;
562
					}
563
				}
564
			}
565
566
			newMethodsFound.add(method);
567
		}
568
		
569
		methodsFound.addAll(newMethodsFound);
570
	}
571
	
572
	private void searchVisibleMethods(
573
			ReferenceBinding receiverType,
574
			Scope scope,
575
			InvocationSite invocationSite,
576
			Scope invocationScope,
577
			boolean onlyStaticMethods,
578
			boolean notInJavadoc,
579
			ObjectVector methodsFound) {
580
		ReferenceBinding currentType = receiverType;
581
		if (notInJavadoc) {
582
			if (receiverType.isInterface()) {
583
				searchVisibleInterfaceMethods(
584
						new ReferenceBinding[]{currentType},
585
						receiverType,
586
						scope,
587
						invocationSite,
588
						invocationScope,
589
						onlyStaticMethods,
590
						methodsFound);
591
				
592
				currentType = scope.getJavaLangObject();
593
			}
594
		}
595
		boolean hasPotentialDefaultAbstractMethods = true;
596
		while (currentType != null) {
597
			
598
			MethodBinding[] methods = currentType.availableMethods();
599
			if (methods != null) {
600
				searchVisibleLocalMethods(
601
						methods,
602
						receiverType,
603
						scope,
604
						invocationSite,
605
						invocationScope,
606
						onlyStaticMethods,
607
						methodsFound);
608
			}
609
			
610
			if (notInJavadoc &&
611
					hasPotentialDefaultAbstractMethods &&
612
					(currentType.isAbstract() ||
613
							currentType.isTypeVariable() ||
614
							currentType.isIntersectionType() ||
615
							currentType.isEnum())){
616
				
617
				ReferenceBinding[] superInterfaces = currentType.superInterfaces();
618
				if (superInterfaces != null && currentType.isIntersectionType()) {
619
					for (int i = 0; i < superInterfaces.length; i++) {
620
						superInterfaces[i] = (ReferenceBinding)superInterfaces[i].capture(invocationScope, invocationSite.sourceEnd());
621
					}
622
				}
623
				
624
				searchVisibleInterfaceMethods(
625
						superInterfaces,
626
						receiverType,
627
						scope,
628
						invocationSite,
629
						invocationScope,
630
						onlyStaticMethods,
631
						methodsFound);
632
			} else {
633
				hasPotentialDefaultAbstractMethods = false;
634
			}
635
			if(currentType.isParameterizedType()) {
636
				currentType = ((ParameterizedTypeBinding)currentType).genericType().superclass();
637
			} else {
638
				currentType = currentType.superclass();
639
			}
640
		}
641
	}
642
	private void searchVisibleVariablesAndMethods(
643
			Scope scope,
644
			ObjectVector localsFound,
645
			ObjectVector fieldsFound,
646
			ObjectVector methodsFound,
647
			boolean notInJavadoc) {
648
		
649
		InvocationSite invocationSite = CompletionEngine.FakeInvocationSite;
650
		
651
		boolean staticsOnly = false;
652
		// need to know if we're in a static context (or inside a constructor)
653
654
		Scope currentScope = scope;
655
		
656
		done1 : while (true) { // done when a COMPILATION_UNIT_SCOPE is found
657
658
			switch (currentScope.kind) {
659
660
				case Scope.METHOD_SCOPE :
661
					// handle the error case inside an explicit constructor call (see MethodScope>>findField)
662
					MethodScope methodScope = (MethodScope) currentScope;
663
					staticsOnly |= methodScope.isStatic | methodScope.isConstructorCall;
664
665
				case Scope.BLOCK_SCOPE :
666
					BlockScope blockScope = (BlockScope) currentScope;
667
668
					next : for (int i = 0, length = blockScope.locals.length; i < length; i++) {
669
						LocalVariableBinding local = blockScope.locals[i];
670
671
						if (local == null)
672
							break next;
673
674
						if (local.isSecret())
675
							continue next;
676
677
						for (int f = 0; f < localsFound.size; f++) {
678
							LocalVariableBinding otherLocal =
679
								(LocalVariableBinding) localsFound.elementAt(f);
680
							if (CharOperation.equals(otherLocal.name, local.name, true))
681
								continue next;
682
						}
683
						
684
						localsFound.add(local);
685
					}
686
					break;
687
688
				case Scope.COMPILATION_UNIT_SCOPE :
689
					break done1;
690
			}
691
			currentScope = currentScope.parent;
692
		}
693
		
694
		staticsOnly = false;
695
		currentScope = scope;
696
		
697
		done2 : while (true) { // done when a COMPILATION_UNIT_SCOPE is found
698
699
			switch (currentScope.kind) {
700
				case Scope.METHOD_SCOPE :
701
					// handle the error case inside an explicit constructor call (see MethodScope>>findField)
702
					MethodScope methodScope = (MethodScope) currentScope;
703
					staticsOnly |= methodScope.isStatic | methodScope.isConstructorCall;
704
					break;
705
				case Scope.CLASS_SCOPE :
706
					ClassScope classScope = (ClassScope) currentScope;
707
					SourceTypeBinding enclosingType = classScope.referenceContext.binding;
708
					
709
					searchVisibleFields(
710
							enclosingType,
711
							classScope,
712
							invocationSite,
713
							scope,
714
							staticsOnly,
715
							notInJavadoc,
716
							localsFound,
717
							fieldsFound);
718
					
719
					searchVisibleMethods(
720
							enclosingType,
721
							classScope,
722
							invocationSite,
723
							scope,
724
							staticsOnly,
725
							notInJavadoc,
726
							methodsFound);
727
					
728
					staticsOnly |= enclosingType.isStatic();
729
					break;
730
731
				case Scope.COMPILATION_UNIT_SCOPE :
732
					break done2;
733
			}
734
			currentScope = currentScope.parent;
735
		}
736
		
737
		// search in static import
738
		ImportBinding[] importBindings = scope.compilationUnitScope().imports;
739
		for (int i = 0; i < importBindings.length; i++) {
740
			ImportBinding importBinding = importBindings[i];
741
			if(importBinding.isValidBinding() && importBinding.isStatic()) {
742
				Binding binding = importBinding.resolvedImport;
743
				if(binding != null && binding.isValidBinding()) {
744
					if(importBinding.onDemand) {
745
						if((binding.kind() & Binding.TYPE) != 0) {
746
							searchVisibleFields(
747
									(ReferenceBinding)binding,
748
									scope,
749
									invocationSite,
750
									scope,
751
									staticsOnly,
752
									notInJavadoc,
753
									localsFound,
754
									fieldsFound);
755
							
756
							searchVisibleMethods(
757
									(ReferenceBinding)binding,
758
									scope,
759
									invocationSite,
760
									scope,
761
									staticsOnly,
762
									notInJavadoc,
763
									methodsFound);
764
						}
765
					} else {
766
						if ((binding.kind() & Binding.FIELD) != 0) {
767
							searchVisibleFields(
768
									new FieldBinding[]{(FieldBinding)binding},
769
									((FieldBinding)binding).declaringClass,
770
									scope,
771
									invocationSite,
772
									scope,
773
									staticsOnly,
774
									localsFound,
775
									fieldsFound);
776
						} else if ((binding.kind() & Binding.METHOD) != 0) {
777
							MethodBinding methodBinding = (MethodBinding)binding;
778
							
779
							searchVisibleLocalMethods(
780
									methodBinding.declaringClass.getMethods(methodBinding.selector),
781
									methodBinding.declaringClass,
782
									scope,
783
									invocationSite,
784
									scope,
785
									true,
786
									methodsFound);
787
						}
788
					}
789
				}
790
			}
791
		}
792
	}
793
}
(-)src/org/eclipse/jdt/core/tests/compiler/parser/GenericDietRecoveryTest.java (-1 / +2 lines)
Lines 236-242 Link Here
236
				new ProblemReporter(
236
				new ProblemReporter(
237
					DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
237
					DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
238
					options, 
238
					options, 
239
					new DefaultProblemFactory(Locale.getDefault())));
239
					new DefaultProblemFactory(Locale.getDefault())),
240
				false);
240
			
241
			
241
		ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null);
242
		ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null);
242
		CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);	
243
		CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);	
(-)src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java (-1 / +2 lines)
Lines 230-236 Link Here
230
				new ProblemReporter(
230
				new ProblemReporter(
231
					DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
231
					DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
232
					options, 
232
					options, 
233
					new DefaultProblemFactory(Locale.getDefault())));
233
					new DefaultProblemFactory(Locale.getDefault())),
234
				false);
234
			
235
			
235
		ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null);
236
		ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null);
236
		CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);	
237
		CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);	
(-)src/org/eclipse/jdt/core/tests/compiler/parser/EnumDietRecoveryTest.java (-1 / +2 lines)
Lines 193-199 Link Here
193
				new ProblemReporter(
193
				new ProblemReporter(
194
					DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
194
					DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
195
					options, 
195
					options, 
196
					new DefaultProblemFactory(Locale.getDefault())));
196
					new DefaultProblemFactory(Locale.getDefault())),
197
				false);
197
			
198
			
198
		ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null);
199
		ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null);
199
		CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);	
200
		CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);	
(-)src/org/eclipse/jdt/core/tests/compiler/parser/JavadocCompletionParserTest.java (-1 / +2 lines)
Lines 98-104 Link Here
98
	CompilerOptions options = new CompilerOptions(getCompilerOptions());
98
	CompilerOptions options = new CompilerOptions(getCompilerOptions());
99
	CompletionParser parser = new CompletionParser(new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(),
99
	CompletionParser parser = new CompletionParser(new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(),
100
		options,
100
		options,
101
		new DefaultProblemFactory(Locale.getDefault())));
101
		new DefaultProblemFactory(Locale.getDefault())),
102
		false);
102
103
103
	ICompilationUnit sourceUnit = new CompilationUnit(source.toCharArray(), "Test.java", null);
104
	ICompilationUnit sourceUnit = new CompilationUnit(source.toCharArray(), "Test.java", null);
104
	CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
105
	CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
(-)src/org/eclipse/jdt/core/tests/compiler/parser/AbstractCompletionTest.java (-2 / +4 lines)
Lines 78-84 Link Here
78
			new ProblemReporter(
78
			new ProblemReporter(
79
				DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
79
				DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
80
				options, 
80
				options, 
81
				new DefaultProblemFactory(Locale.getDefault())));
81
				new DefaultProblemFactory(Locale.getDefault())),
82
			false);
82
83
83
	ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null);
84
	ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null);
84
	CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);	
85
	CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);	
Lines 115-121 Link Here
115
			new ProblemReporter(
116
			new ProblemReporter(
116
				DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
117
				DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
117
				options, 
118
				options, 
118
				new DefaultProblemFactory(Locale.getDefault())));
119
				new DefaultProblemFactory(Locale.getDefault())),
120
			false);
119
121
120
	ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null);
122
	ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null);
121
	CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);	
123
	CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);	
(-)src/org/eclipse/jdt/core/tests/compiler/parser/AnnotationDietRecoveryTest.java (-1 / +2 lines)
Lines 204-210 Link Here
204
				new ProblemReporter(
204
				new ProblemReporter(
205
					DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
205
					DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
206
					options, 
206
					options, 
207
					new DefaultProblemFactory(Locale.getDefault())));
207
					new DefaultProblemFactory(Locale.getDefault())),
208
				false);
208
			
209
			
209
		ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null);
210
		ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null);
210
		CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);	
211
		CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);	
(-)src/org/eclipse/jdt/core/tests/model/CompletionContextTests_1_5.java (+352 lines)
Lines 778-781 Link Here
778
		"completion token location=UNKNOWN",
778
		"completion token location=UNKNOWN",
779
		result.context);
779
		result.context);
780
}
780
}
781
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
782
public void test0028() throws JavaModelException {
783
	this.workingCopies = new ICompilationUnit[2];
784
	this.workingCopies[0] = getWorkingCopy(
785
		"/Completion/src3/test/X.java",
786
		"package test;\n" + 
787
		"public class X<TX> extends A<String> {\n" + 
788
		"  public void methodX(TX x) {}\n" + 
789
		"  public void foo() {\n" +
790
		"    zzzz\n" +
791
		"  }\n" +
792
		"}");
793
	
794
	this.workingCopies[1] = getWorkingCopy(
795
		"/Completion/src3/test/A.java",
796
		"package test;\n" + 
797
		"public class A<TA> {\n" + 
798
		"  public void methodA(TA a) {}\n" + 
799
		"}");
800
	
801
	String str = this.workingCopies[0].getSource();
802
	int tokenStart = str.lastIndexOf("zzzz");
803
	int tokenEnd = tokenStart + "zzzz".length() - 1;
804
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
805
806
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true);
807
	
808
	String jclPath = getExternalJCLPathString("1.5");
809
	assertResults(
810
		"completion offset="+(cursorLocation)+"\n" +
811
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
812
		"completion token=\"zzzz\"\n" +
813
		"completion token kind=TOKEN_KIND_NAME\n" +
814
		"expectedTypesSignatures=null\n" +
815
		"expectedTypesKeys=null\n" +
816
		"completion token location={STATEMENT_START}\n" +
817
		"visibleElements={\n" +
818
		"	methodX(TX) {key=Ltest/X;.methodX(TTX;)V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
819
		"	foo() {key=Ltest/X;.foo()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
820
		"	methodA(TA) {key=Ltest/A<Ljava/lang/String;>;.methodA(Ljava/lang/String;)V} [in A [in [Working copy] A.java [in test [in src3 [in Completion]]]]],\n" +
821
		"	wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
822
		"	wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
823
		"	wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
824
		"	toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
825
		"	notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
826
		"	notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
827
		"	hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
828
		"	getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class<+Ljava/lang/Object;>;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
829
		"	finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
830
		"	equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
831
		"	clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
832
		"}",
833
		result.context);
834
}
835
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
836
public void test0029() throws JavaModelException {
837
	this.workingCopies = new ICompilationUnit[2];
838
	this.workingCopies[0] = getWorkingCopy(
839
		"/Completion/src3/test/X.java",
840
		"package test;\n" + 
841
		"public class X {\n" + 
842
		"  public A<String> methodX() {return null;}\n" + 
843
		"  public void foo() {\n" +
844
		"    zzzz\n" +
845
		"  }\n" +
846
		"}");
847
	
848
	this.workingCopies[1] = getWorkingCopy(
849
		"/Completion/src3/test/A.java",
850
		"package test;\n" + 
851
		"public class A<TA> {\n" + 
852
		"}");
853
	
854
	String str = this.workingCopies[0].getSource();
855
	int tokenStart = str.lastIndexOf("zzzz");
856
	int tokenEnd = tokenStart + "zzzz".length() - 1;
857
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
858
859
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "Ltest/A<Ljava/lang/String;>;");
860
	
861
	assertResults(
862
		"completion offset="+(cursorLocation)+"\n" +
863
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
864
		"completion token=\"zzzz\"\n" +
865
		"completion token kind=TOKEN_KIND_NAME\n" +
866
		"expectedTypesSignatures=null\n" +
867
		"expectedTypesKeys=null\n" +
868
		"completion token location={STATEMENT_START}\n" +
869
		"visibleElements={\n" +
870
		"	methodX() {key=Ltest/X;.methodX()Ltest/A<Ljava/lang/String;>;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
871
		"}",
872
		result.context);
873
}
874
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
875
public void test0030() throws JavaModelException {
876
	this.workingCopies = new ICompilationUnit[3];
877
	this.workingCopies[0] = getWorkingCopy(
878
		"/Completion/src3/test/X.java",
879
		"package test;\n" + 
880
		"public class X {\n" + 
881
		"  public A<String> methodX() {return null;}\n" + 
882
		"  public void foo() {\n" +
883
		"    zzzz\n" +
884
		"  }\n" +
885
		"}");
886
	
887
	this.workingCopies[1] = getWorkingCopy(
888
		"/Completion/src3/test/A.java",
889
		"package test;\n" + 
890
		"public class A<TA> {\n" + 
891
		"}");
892
	
893
	this.workingCopies[2] = getWorkingCopy(
894
		"/Completion/src3/test/B.java",
895
		"package test;\n" + 
896
		"public class B<TB> {\n" + 
897
		"}");
898
	
899
	String str = this.workingCopies[0].getSource();
900
	int tokenStart = str.lastIndexOf("zzzz");
901
	int tokenEnd = tokenStart + "zzzz".length() - 1;
902
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
903
904
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "Ltest/B<Ljava/lang/String;>;");
905
	
906
	assertResults(
907
		"completion offset="+(cursorLocation)+"\n" +
908
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
909
		"completion token=\"zzzz\"\n" +
910
		"completion token kind=TOKEN_KIND_NAME\n" +
911
		"expectedTypesSignatures=null\n" +
912
		"expectedTypesKeys=null\n" +
913
		"completion token location={STATEMENT_START}\n" +
914
		"visibleElements={}",
915
		result.context);
916
}
917
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
918
public void test0031() throws JavaModelException {
919
	this.workingCopies = new ICompilationUnit[3];
920
	this.workingCopies[0] = getWorkingCopy(
921
		"/Completion/src3/test/X.java",
922
		"package test;\n" + 
923
		"public class X {\n" + 
924
		"  public A<String> methodX() {return null;}\n" + 
925
		"  public void foo() {\n" +
926
		"    zzzz\n" +
927
		"  }\n" +
928
		"}");
929
	
930
	this.workingCopies[1] = getWorkingCopy(
931
		"/Completion/src3/test/A.java",
932
		"package test;\n" + 
933
		"public class A<TA> extends B<TA>{\n" + 
934
		"}");
935
	
936
	this.workingCopies[2] = getWorkingCopy(
937
		"/Completion/src3/test/B.java",
938
		"package test;\n" + 
939
		"public class B<TB> {\n" + 
940
		"}");
941
	
942
	String str = this.workingCopies[0].getSource();
943
	int tokenStart = str.lastIndexOf("zzzz");
944
	int tokenEnd = tokenStart + "zzzz".length() - 1;
945
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
946
947
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "Ltest/B<Ljava/lang/String;>;");
948
	
949
	assertResults(
950
		"completion offset="+(cursorLocation)+"\n" +
951
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
952
		"completion token=\"zzzz\"\n" +
953
		"completion token kind=TOKEN_KIND_NAME\n" +
954
		"expectedTypesSignatures=null\n" +
955
		"expectedTypesKeys=null\n" +
956
		"completion token location={STATEMENT_START}\n" +
957
		"visibleElements={\n" +
958
		"	methodX() {key=Ltest/X;.methodX()Ltest/A<Ljava/lang/String;>;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
959
		"}",
960
		result.context);
961
}
962
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
963
public void test0032() throws JavaModelException {
964
	this.workingCopies = new ICompilationUnit[2];
965
	this.workingCopies[0] = getWorkingCopy(
966
		"/Completion/src3/test/X.java",
967
		"package test;\n" + 
968
		"public class X {\n" + 
969
		"  public A<String> methodX() {return null;}\n" + 
970
		"  public void foo() {\n" +
971
		"    zzzz\n" +
972
		"  }\n" +
973
		"}");
974
	
975
	this.workingCopies[1] = getWorkingCopy(
976
		"/Completion/src3/test/A.java",
977
		"package test;\n" + 
978
		"public class A<TA> {\n" + 
979
		"}");
980
	
981
	String str = this.workingCopies[0].getSource();
982
	int tokenStart = str.lastIndexOf("zzzz");
983
	int tokenEnd = tokenStart + "zzzz".length() - 1;
984
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
985
986
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "Ltest/Zork<Ljava/lang/String;>;");
987
	
988
	assertResults(
989
		"completion offset="+(cursorLocation)+"\n" +
990
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
991
		"completion token=\"zzzz\"\n" +
992
		"completion token kind=TOKEN_KIND_NAME\n" +
993
		"expectedTypesSignatures=null\n" +
994
		"expectedTypesKeys=null\n" +
995
		"completion token location={STATEMENT_START}\n" +
996
		"visibleElements={}",
997
		result.context);
998
}
999
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
1000
public void test0033() throws JavaModelException {
1001
	this.workingCopies = new ICompilationUnit[2];
1002
	this.workingCopies[0] = getWorkingCopy(
1003
		"/Completion/src3/test/X.java",
1004
		"package test;\n" + 
1005
		"public class X {\n" + 
1006
		"  public A<String> methodX() {return null;}\n" + 
1007
		"  public void foo() {\n" +
1008
		"    zzzz\n" +
1009
		"  }\n" +
1010
		"}");
1011
	
1012
	this.workingCopies[1] = getWorkingCopy(
1013
		"/Completion/src3/test/A.java",
1014
		"package test;\n" + 
1015
		"public class A<TA> {\n" + 
1016
		"}");
1017
	
1018
	
1019
	String str = this.workingCopies[0].getSource();
1020
	int tokenStart = str.lastIndexOf("zzzz");
1021
	int tokenEnd = tokenStart + "zzzz".length() - 1;
1022
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
1023
1024
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "Ltest/A<LZork;>;");
1025
	
1026
	assertResults(
1027
		"completion offset="+(cursorLocation)+"\n" +
1028
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
1029
		"completion token=\"zzzz\"\n" +
1030
		"completion token kind=TOKEN_KIND_NAME\n" +
1031
		"expectedTypesSignatures=null\n" +
1032
		"expectedTypesKeys=null\n" +
1033
		"completion token location={STATEMENT_START}\n" +
1034
		"visibleElements={}",
1035
		result.context);
1036
}
1037
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
1038
public void test0034() throws JavaModelException {
1039
	this.workingCopies = new ICompilationUnit[1];
1040
	this.workingCopies[0] = getWorkingCopy(
1041
		"/Completion/src3/test/X.java",
1042
		"package test;\n" + 
1043
		"public class X<T> {\n" + 
1044
		"  public T methodX() {return null;}\n" + 
1045
		"  public void foo() {\n" +
1046
		"    zzzz\n" +
1047
		"  }\n" +
1048
		"}");
1049
	
1050
	String str = this.workingCopies[0].getSource();
1051
	int tokenStart = str.lastIndexOf("zzzz");
1052
	int tokenEnd = tokenStart + "zzzz".length() - 1;
1053
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
1054
1055
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "TT;");
1056
	
1057
	assertResults(
1058
		"completion offset="+(cursorLocation)+"\n" +
1059
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
1060
		"completion token=\"zzzz\"\n" +
1061
		"completion token kind=TOKEN_KIND_NAME\n" +
1062
		"expectedTypesSignatures=null\n" +
1063
		"expectedTypesKeys=null\n" +
1064
		"completion token location={STATEMENT_START}\n" +
1065
		"visibleElements={\n" +
1066
		"	methodX() {key=Ltest/X;.methodX()TT;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
1067
		"}",
1068
		result.context);
1069
}
1070
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
1071
public void test0035() throws JavaModelException {
1072
	this.workingCopies = new ICompilationUnit[1];
1073
	this.workingCopies[0] = getWorkingCopy(
1074
		"/Completion/src3/test/X.java",
1075
		"package test;\n" + 
1076
		"public class X {\n" + 
1077
		"  public <T> T methodX() {return null;}\n" + 
1078
		"  public void foo() {\n" +
1079
		"    zzzz\n" +
1080
		"  }\n" +
1081
		"}");
1082
	
1083
	String str = this.workingCopies[0].getSource();
1084
	int tokenStart = str.lastIndexOf("zzzz");
1085
	int tokenEnd = tokenStart + "zzzz".length() - 1;
1086
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
1087
1088
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "TT;");
1089
	
1090
	assertResults(
1091
		"completion offset="+(cursorLocation)+"\n" +
1092
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
1093
		"completion token=\"zzzz\"\n" +
1094
		"completion token kind=TOKEN_KIND_NAME\n" +
1095
		"expectedTypesSignatures=null\n" +
1096
		"expectedTypesKeys=null\n" +
1097
		"completion token location={STATEMENT_START}\n" +
1098
		"visibleElements={}",
1099
		result.context);
1100
}
1101
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
1102
public void test0036() throws JavaModelException {
1103
	this.workingCopies = new ICompilationUnit[1];
1104
	this.workingCopies[0] = getWorkingCopy(
1105
		"/Completion/src3/test/X.java",
1106
		"package test;\n" + 
1107
		"public class X {\n" + 
1108
		"  public <T> T methodX() {\n" + 
1109
		"    zzzz\n" +
1110
		"  }\n" +
1111
		"}");
1112
	
1113
	String str = this.workingCopies[0].getSource();
1114
	int tokenStart = str.lastIndexOf("zzzz");
1115
	int tokenEnd = tokenStart + "zzzz".length() - 1;
1116
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
1117
1118
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "TT;");
1119
	
1120
	assertResults(
1121
		"completion offset="+(cursorLocation)+"\n" +
1122
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
1123
		"completion token=\"zzzz\"\n" +
1124
		"completion token kind=TOKEN_KIND_NAME\n" +
1125
		"expectedTypesSignatures=null\n" +
1126
		"expectedTypesKeys=null\n" +
1127
		"completion token location={STATEMENT_START}\n" +
1128
		"visibleElements={\n" +
1129
		"	methodX() {key=Ltest/X;.methodX<T:Ljava/lang/Object;>()TT;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
1130
		"}",
1131
		result.context);
1132
}
781
}
1133
}
(-)src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java (+825 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.model;
11
package org.eclipse.jdt.core.tests.model;
12
12
13
import java.io.IOException;
14
15
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.jdt.core.*;
16
import org.eclipse.jdt.core.*;
14
17
15
import org.eclipse.jdt.internal.codeassist.RelevanceConstants;
18
import org.eclipse.jdt.internal.codeassist.RelevanceConstants;
Lines 3914-3917 Link Here
3914
		"completion token location={STATEMENT_START}",
3917
		"completion token location={STATEMENT_START}",
3915
		result.context);
3918
		result.context);
3916
}
3919
}
3920
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
3921
public void test0143() throws JavaModelException {
3922
	this.workingCopies = new ICompilationUnit[1];
3923
	this.workingCopies[0] = getWorkingCopy(
3924
		"/Completion/src3/test/X.java",
3925
		"package test;\n" + 
3926
		"zzzz\n" + 
3927
		"public class X {\n" + 
3928
		"  public int field0;\n" + 
3929
		"}");
3930
	
3931
	String str = this.workingCopies[0].getSource();
3932
	int tokenStart = str.lastIndexOf("zzzz");
3933
	int tokenEnd = tokenStart + "zzzz".length() - 1;
3934
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
3935
3936
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true);
3937
	
3938
	assertResults(
3939
		"completion offset="+(cursorLocation)+"\n" +
3940
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
3941
		"completion token=\"zzzz\"\n" +
3942
		"completion token kind=TOKEN_KIND_NAME\n" +
3943
		"expectedTypesSignatures=null\n" +
3944
		"expectedTypesKeys=null\n" +
3945
		"completion token location=UNKNOWN\n" +
3946
		"visibleElements={}",
3947
		result.context);
3948
}
3949
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
3950
public void test0144() throws JavaModelException {
3951
	this.workingCopies = new ICompilationUnit[1];
3952
	this.workingCopies[0] = getWorkingCopy(
3953
		"/Completion/src3/test/X.java",
3954
		"package test;\n" + 
3955
		"public class X {\n" + 
3956
		"  zzzz\n" + 
3957
		"  public int field0;\n" + 
3958
		"}");
3959
	
3960
	String str = this.workingCopies[0].getSource();
3961
	int tokenStart = str.lastIndexOf("zzzz");
3962
	int tokenEnd = tokenStart + "zzzz".length() - 1;
3963
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
3964
3965
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true);
3966
	
3967
	assertResults(
3968
		"completion offset="+(cursorLocation)+"\n" +
3969
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
3970
		"completion token=\"zzzz\"\n" +
3971
		"completion token kind=TOKEN_KIND_NAME\n" +
3972
		"expectedTypesSignatures=null\n" +
3973
		"expectedTypesKeys=null\n" +
3974
		"completion token location={MEMBER_START}\n" +
3975
		"visibleElements={}",
3976
		result.context);
3977
}
3978
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
3979
public void test0145() throws JavaModelException {
3980
	this.workingCopies = new ICompilationUnit[1];
3981
	this.workingCopies[0] = getWorkingCopy(
3982
		"/Completion/src3/test/X.java",
3983
		"package test;\n" + 
3984
		"public class X {\n" + 
3985
		"  public int field0;\n" + 
3986
		"  public int field1 = zzzz;\n" + 
3987
		"}");
3988
	
3989
	String str = this.workingCopies[0].getSource();
3990
	int tokenStart = str.lastIndexOf("zzzz");
3991
	int tokenEnd = tokenStart + "zzzz".length() - 1;
3992
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
3993
3994
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true);
3995
	
3996
	String jclPath = getExternalJCLPathString();
3997
	assertResults(
3998
		"completion offset="+(cursorLocation)+"\n" +
3999
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4000
		"completion token=\"zzzz\"\n" +
4001
		"completion token kind=TOKEN_KIND_NAME\n" +
4002
		"expectedTypesSignatures={I}\n" +
4003
		"expectedTypesKeys={I}\n" +
4004
		"completion token location=UNKNOWN\n" +
4005
		"visibleElements={\n" +
4006
		"	field1 {key=Ltest/X;.field1)I} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
4007
		"	field0 {key=Ltest/X;.field0)I} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
4008
		"	wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4009
		"	wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4010
		"	wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4011
		"	toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4012
		"	notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4013
		"	notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4014
		"	hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4015
		"	getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4016
		"	finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4017
		"	equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4018
		"	clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4019
		"}",
4020
		result.context);
4021
}
4022
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
4023
public void test0146() throws JavaModelException {
4024
	this.workingCopies = new ICompilationUnit[1];
4025
	this.workingCopies[0] = getWorkingCopy(
4026
		"/Completion/src3/test/X.java",
4027
		"package test;\n" + 
4028
		"public class X {\n" + 
4029
		"  public int field0;\n" + 
4030
		"  { zzzz }\n" + 
4031
		"}");
4032
	
4033
	String str = this.workingCopies[0].getSource();
4034
	int tokenStart = str.lastIndexOf("zzzz");
4035
	int tokenEnd = tokenStart + "zzzz".length() - 1;
4036
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
4037
4038
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true);
4039
	
4040
	String jclPath = getExternalJCLPathString();
4041
	assertResults(
4042
		"completion offset="+(cursorLocation)+"\n" +
4043
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4044
		"completion token=\"zzzz\"\n" +
4045
		"completion token kind=TOKEN_KIND_NAME\n" +
4046
		"expectedTypesSignatures=null\n" +
4047
		"expectedTypesKeys=null\n" +
4048
		"completion token location={STATEMENT_START}\n" +
4049
		"visibleElements={\n" +
4050
		"	field0 {key=Ltest/X;.field0)I} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
4051
		"	wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4052
		"	wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4053
		"	wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4054
		"	toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4055
		"	notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4056
		"	notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4057
		"	hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4058
		"	getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4059
		"	finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4060
		"	equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4061
		"	clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4062
		"}",
4063
		result.context);
4064
}
4065
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
4066
public void test0147() throws JavaModelException {
4067
	this.workingCopies = new ICompilationUnit[1];
4068
	this.workingCopies[0] = getWorkingCopy(
4069
		"/Completion/src3/test/X.java",
4070
		"package test;\n" + 
4071
		"public class X {\n" + 
4072
		"  public int field0;\n" + 
4073
		"  public void foo() {\n" +
4074
		"    zzzz\n" +
4075
		"  }\n" + 
4076
		"}");
4077
	
4078
	String str = this.workingCopies[0].getSource();
4079
	int tokenStart = str.lastIndexOf("zzzz");
4080
	int tokenEnd = tokenStart + "zzzz".length() - 1;
4081
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
4082
4083
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true);
4084
	
4085
	String jclPath = getExternalJCLPathString();
4086
	assertResults(
4087
		"completion offset="+(cursorLocation)+"\n" +
4088
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4089
		"completion token=\"zzzz\"\n" +
4090
		"completion token kind=TOKEN_KIND_NAME\n" +
4091
		"expectedTypesSignatures=null\n" +
4092
		"expectedTypesKeys=null\n" +
4093
		"completion token location={STATEMENT_START}\n" +
4094
		"visibleElements={\n" +
4095
		"	field0 {key=Ltest/X;.field0)I} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
4096
		"	foo() {key=Ltest/X;.foo()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
4097
		"	wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4098
		"	wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4099
		"	wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4100
		"	toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4101
		"	notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4102
		"	notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4103
		"	hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4104
		"	getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4105
		"	finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4106
		"	equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4107
		"	clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4108
		"}",
4109
		result.context);
4110
}
4111
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
4112
public void test0148() throws JavaModelException {
4113
	this.workingCopies = new ICompilationUnit[1];
4114
	this.workingCopies[0] = getWorkingCopy(
4115
		"/Completion/src3/test/X.java",
4116
		"package test;\n" + 
4117
		"public class X {\n" + 
4118
		"  public int field0;\n" + 
4119
		"  public int fieldX0;\n" + 
4120
		"  public class Y {\n" +
4121
		"    public int field0;\n" + 
4122
		"    public int fieldY0;\n" + 
4123
		"    public void fooY() {\n" +
4124
		"      int local0;\n" +
4125
		"      int localfooY0;\n" +
4126
		"      if (true) {\n" +
4127
		"        int local0;\n" +
4128
		"        int localfooY1;\n" +
4129
		"        zzzz\n" +
4130
		"      }\n" +
4131
		"  }\n" + 
4132
		"}");
4133
	
4134
	String str = this.workingCopies[0].getSource();
4135
	int tokenStart = str.lastIndexOf("zzzz");
4136
	int tokenEnd = tokenStart + "zzzz".length() - 1;
4137
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
4138
4139
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true);
4140
	
4141
	String jclPath = getExternalJCLPathString();
4142
	assertResults(
4143
		"completion offset="+(cursorLocation)+"\n" +
4144
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4145
		"completion token=\"zzzz\"\n" +
4146
		"completion token kind=TOKEN_KIND_NAME\n" +
4147
		"expectedTypesSignatures=null\n" +
4148
		"expectedTypesKeys=null\n" +
4149
		"completion token location={STATEMENT_START}\n" +
4150
		"visibleElements={\n" +
4151
		"	local0 [in fooY() [in Y [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]]],\n" +
4152
		"	localfooY0 [in fooY() [in Y [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]]],\n" +
4153
		"	localfooY1 [in fooY() [in Y [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]]],\n" +
4154
		"	fieldY0 {key=Ltest/X$Y;.fieldY0)I} [in Y [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
4155
		"	field0 {key=Ltest/X$Y;.field0)I} [in Y [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
4156
		"	fieldX0 {key=Ltest/X;.fieldX0)I} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
4157
		"	fooY() {key=Ltest/X$Y;.fooY()V} [in Y [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
4158
		"	wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4159
		"	wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4160
		"	wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4161
		"	toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4162
		"	notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4163
		"	notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4164
		"	hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4165
		"	getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4166
		"	finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4167
		"	equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4168
		"	clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4169
		"}",
4170
		result.context);
4171
}
4172
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
4173
public void test0149() throws JavaModelException {
4174
	this.workingCopies = new ICompilationUnit[1];
4175
	this.workingCopies[0] = getWorkingCopy(
4176
		"/Completion/src3/test/X.java",
4177
		"package test;\n" + 
4178
		"public class X {\n" + 
4179
		"  public void method0() {}\n" + 
4180
		"  public void method0(int i) {}\n" + 
4181
		"  public class Y {\n" +
4182
		"    public void method1() {}\n" + 
4183
		"    public void method0(int i) {}\n" + 
4184
		"    public void foo() {\n" +
4185
		"      zzzz\n" +
4186
		"    }\n" +
4187
		"  }\n" + 
4188
		"}");
4189
	
4190
	String str = this.workingCopies[0].getSource();
4191
	int tokenStart = str.lastIndexOf("zzzz");
4192
	int tokenEnd = tokenStart + "zzzz".length() - 1;
4193
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
4194
4195
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true);
4196
	
4197
	String jclPath = getExternalJCLPathString();
4198
	assertResults(
4199
		"completion offset="+(cursorLocation)+"\n" +
4200
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4201
		"completion token=\"zzzz\"\n" +
4202
		"completion token kind=TOKEN_KIND_NAME\n" +
4203
		"expectedTypesSignatures=null\n" +
4204
		"expectedTypesKeys=null\n" +
4205
		"completion token location={STATEMENT_START}\n" +
4206
		"visibleElements={\n" +
4207
		"	method1() {key=Ltest/X$Y;.method1()V} [in Y [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
4208
		"	method0(int) {key=Ltest/X$Y;.method0(I)V} [in Y [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
4209
		"	foo() {key=Ltest/X$Y;.foo()V} [in Y [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
4210
		"	wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4211
		"	wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4212
		"	wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4213
		"	toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4214
		"	notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4215
		"	notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4216
		"	hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4217
		"	getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4218
		"	finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4219
		"	equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4220
		"	clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4221
		"	method0() {key=Ltest/X;.method0()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
4222
		"}",
4223
		result.context);
4224
}
4225
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
4226
public void test0150() throws JavaModelException {
4227
	this.workingCopies = new ICompilationUnit[3];
4228
	this.workingCopies[0] = getWorkingCopy(
4229
		"/Completion/src3/test/X.java",
4230
		"package test;\n" + 
4231
		"public class X extends A {\n" + 
4232
		"  public void method0() {}\n" + 
4233
		"  public void method0(int i) {}\n" + 
4234
		"  public class Y extends B {\n" +
4235
		"    public void method1() {}\n" + 
4236
		"    public void method0(int i) {}\n" + 
4237
		"    public void foo() {\n" +
4238
		"      zzzz\n" +
4239
		"    }\n" +
4240
		"  }\n" + 
4241
		"}");
4242
	
4243
	this.workingCopies[1] = getWorkingCopy(
4244
		"/Completion/src3/test/A.java",
4245
		"package test;\n" + 
4246
		"public class A {\n" + 
4247
		"  public void methodA() {}\n" + 
4248
		"  public void method0(int i) {}\n" + 
4249
		"}");
4250
	
4251
	this.workingCopies[2] = getWorkingCopy(
4252
		"/Completion/src3/test/B.java",
4253
		"package test;\n" + 
4254
		"public class B {\n" + 
4255
		"  public void methodB() {}\n" + 
4256
		"  public void method0(int i) {}\n" + 
4257
		"}");
4258
	
4259
	String str = this.workingCopies[0].getSource();
4260
	int tokenStart = str.lastIndexOf("zzzz");
4261
	int tokenEnd = tokenStart + "zzzz".length() - 1;
4262
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
4263
4264
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true);
4265
	
4266
	String jclPath = getExternalJCLPathString();
4267
	assertResults(
4268
		"completion offset="+(cursorLocation)+"\n" +
4269
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4270
		"completion token=\"zzzz\"\n" +
4271
		"completion token kind=TOKEN_KIND_NAME\n" +
4272
		"expectedTypesSignatures=null\n" +
4273
		"expectedTypesKeys=null\n" +
4274
		"completion token location={STATEMENT_START}\n" +
4275
		"visibleElements={\n" +
4276
		"	method1() {key=Ltest/X$Y;.method1()V} [in Y [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
4277
		"	method0(int) {key=Ltest/X$Y;.method0(I)V} [in Y [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
4278
		"	foo() {key=Ltest/X$Y;.foo()V} [in Y [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
4279
		"	methodB() {key=Ltest/B;.methodB()V} [in B [in [Working copy] B.java [in test [in src3 [in Completion]]]]],\n" +
4280
		"	wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4281
		"	wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4282
		"	wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4283
		"	toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4284
		"	notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4285
		"	notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4286
		"	hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4287
		"	getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4288
		"	finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4289
		"	equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4290
		"	clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4291
		"	method0() {key=Ltest/X;.method0()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
4292
		"	methodA() {key=Ltest/A;.methodA()V} [in A [in [Working copy] A.java [in test [in src3 [in Completion]]]]],\n" +
4293
		"}",
4294
		result.context);
4295
}
4296
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
4297
public void test0151() throws CoreException, IOException {
4298
	this.workingCopies = new ICompilationUnit[3];
4299
	this.workingCopies[0] = getWorkingCopy(
4300
		"/Completion/src3/test/X.java",
4301
		"package test;\n" + 
4302
		"public class X extends A {\n" + 
4303
		"  public void method0() {}\n" + 
4304
		"  public void method0(int i) {}\n" + 
4305
		"  public class Y extends B {\n" +
4306
		"    public void method1() {}\n" + 
4307
		"    public void method0(int i) {}\n" + 
4308
		"    public void foo() {\n" +
4309
		"      zzzz\n" +
4310
		"    }\n" +
4311
		"  }\n" + 
4312
		"}");
4313
	
4314
	this.workingCopies[1] = getWorkingCopy(
4315
		"/Completion/src3/test/B.java",
4316
		"package test;\n" + 
4317
		"public class B extends D {\n" + 
4318
		"  public void methodB() {}\n" + 
4319
		"  public void method0(int i) {}\n" + 
4320
		"}");
4321
	
4322
	this.workingCopies[2] = getWorkingCopy(
4323
		"/Completion/src3/test/D.java",
4324
		"package test;\n" + 
4325
		"public class D {\n" + 
4326
		"  public void methodD() {}\n" + 
4327
		"  public void method0(int i) {}\n" + 
4328
		"}");
4329
	
4330
	this.addLibrary(
4331
		getJavaProject("Completion"),
4332
		"test.jar",
4333
		"testsrc.zip",
4334
		new String[] {
4335
			"/Completion/test/A.java",
4336
			"package test;\n" + 
4337
			"public class A extends C {\n" + 
4338
			"  public void methodA() {}\n" + 
4339
			"  public void method0(int i) {}\n" + 
4340
			"}",
4341
			"/Completion/test/C.java",
4342
			"package test;\n" + 
4343
			"public class C {\n" + 
4344
			"  public void methodC() {}\n" + 
4345
			"  public void method0(int i) {}\n" + 
4346
			"}"
4347
		},
4348
		"1.4");
4349
4350
	
4351
	String str = this.workingCopies[0].getSource();
4352
	int tokenStart = str.lastIndexOf("zzzz");
4353
	int tokenEnd = tokenStart + "zzzz".length() - 1;
4354
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
4355
4356
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true);
4357
	
4358
	String jclPath = getExternalJCLPathString();
4359
	assertResults(
4360
		"completion offset="+(cursorLocation)+"\n" +
4361
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4362
		"completion token=\"zzzz\"\n" +
4363
		"completion token kind=TOKEN_KIND_NAME\n" +
4364
		"expectedTypesSignatures=null\n" +
4365
		"expectedTypesKeys=null\n" +
4366
		"completion token location={STATEMENT_START}\n" +
4367
		"visibleElements={\n" +
4368
		"	method1() {key=Ltest/X$Y;.method1()V} [in Y [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
4369
		"	method0(int) {key=Ltest/X$Y;.method0(I)V} [in Y [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
4370
		"	foo() {key=Ltest/X$Y;.foo()V} [in Y [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
4371
		"	methodB() {key=Ltest/B;.methodB()V} [in B [in [Working copy] B.java [in test [in src3 [in Completion]]]]],\n" +
4372
		"	methodD() {key=Ltest/D;.methodD()V} [in D [in [Working copy] D.java [in test [in src3 [in Completion]]]]],\n" +
4373
		"	wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4374
		"	wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4375
		"	wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4376
		"	toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4377
		"	notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4378
		"	notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4379
		"	hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4380
		"	getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4381
		"	finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4382
		"	equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4383
		"	clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4384
		"	method0() {key=Ltest/X;.method0()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
4385
		"	methodA() {key=Ltest/A;.methodA()V} [in A [in A.class [in test [in test.jar [in Completion]]]]],\n" +
4386
		"	methodC() {key=Ltest/C;.methodC()V} [in C [in C.class [in test [in test.jar [in Completion]]]]],\n" +
4387
		"}",
4388
		result.context);
4389
}
4390
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
4391
public void test0152() throws JavaModelException {
4392
	this.workingCopies = new ICompilationUnit[1];
4393
	this.workingCopies[0] = getWorkingCopy(
4394
		"/Completion/src3/test/X.java",
4395
		"package test;\n" + 
4396
		"public class X {\n" + 
4397
		"  public void method0() {}\n" + 
4398
		"  public void method0(int i) {}\n" + 
4399
		"  public class Y {\n" +
4400
		"    public void method1() {}\n" + 
4401
		"    public void method0(int i) {}\n" + 
4402
		"    public void foo() {\n" +
4403
		"      zzzz\n" +
4404
		"    }\n" +
4405
		"  }\n" + 
4406
		"}");
4407
	
4408
	String str = this.workingCopies[0].getSource();
4409
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
4410
	
4411
	boolean unsupported = false;
4412
	try {
4413
		contextComplete0(this.workingCopies[0], cursorLocation, false /*do not use extended context*/,true /*ask enclosing element*/, true /*ask visible elements*/, null);
4414
	} catch (UnsupportedOperationException e) {
4415
		// this is expected because visible elements computation require heavy context
4416
		unsupported = true;
4417
	}
4418
	assertTrue("getVisibleElements() shouldn't be supported", unsupported);
4419
}
4420
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
4421
public void test0153() throws JavaModelException {
4422
	this.workingCopies = new ICompilationUnit[2];
4423
	this.workingCopies[0] = getWorkingCopy(
4424
		"/Completion/src3/test/X.java",
4425
		"package test;\n" + 
4426
		"public class X {\n" + 
4427
		"  public A methodX() {return null;}\n" + 
4428
		"  public void foo() {\n" +
4429
		"    zzzz\n" +
4430
		"  }\n" +
4431
		"}");
4432
	
4433
	this.workingCopies[1] = getWorkingCopy(
4434
		"/Completion/src3/test/A.java",
4435
		"package test;\n" + 
4436
		"public class A {\n" + 
4437
		"}");
4438
	
4439
	
4440
	String str = this.workingCopies[0].getSource();
4441
	int tokenStart = str.lastIndexOf("zzzz");
4442
	int tokenEnd = tokenStart + "zzzz".length() - 1;
4443
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
4444
4445
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "Ltest/A;");
4446
	
4447
	assertResults(
4448
		"completion offset="+(cursorLocation)+"\n" +
4449
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4450
		"completion token=\"zzzz\"\n" +
4451
		"completion token kind=TOKEN_KIND_NAME\n" +
4452
		"expectedTypesSignatures=null\n" +
4453
		"expectedTypesKeys=null\n" +
4454
		"completion token location={STATEMENT_START}\n" +
4455
		"visibleElements={\n" +
4456
		"	methodX() {key=Ltest/X;.methodX()Ltest/A;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
4457
		"}",
4458
		result.context);
4459
}
4460
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
4461
public void test0154() throws JavaModelException {
4462
	this.workingCopies = new ICompilationUnit[3];
4463
	this.workingCopies[0] = getWorkingCopy(
4464
		"/Completion/src3/test/X.java",
4465
		"package test;\n" + 
4466
		"public class X {\n" + 
4467
		"  public A methodX() {return null;}\n" + 
4468
		"  public void foo() {\n" +
4469
		"    zzzz\n" +
4470
		"  }\n" +
4471
		"}");
4472
	
4473
	this.workingCopies[1] = getWorkingCopy(
4474
		"/Completion/src3/test/A.java",
4475
		"package test;\n" + 
4476
		"public class A {\n" + 
4477
		"}");
4478
	
4479
	this.workingCopies[2] = getWorkingCopy(
4480
		"/Completion/src3/test/B.java",
4481
		"package test;\n" + 
4482
		"public class B {\n" + 
4483
		"}");
4484
	
4485
	
4486
	String str = this.workingCopies[0].getSource();
4487
	int tokenStart = str.lastIndexOf("zzzz");
4488
	int tokenEnd = tokenStart + "zzzz".length() - 1;
4489
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
4490
4491
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "Ltest/B;");
4492
	
4493
	assertResults(
4494
		"completion offset="+(cursorLocation)+"\n" +
4495
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4496
		"completion token=\"zzzz\"\n" +
4497
		"completion token kind=TOKEN_KIND_NAME\n" +
4498
		"expectedTypesSignatures=null\n" +
4499
		"expectedTypesKeys=null\n" +
4500
		"completion token location={STATEMENT_START}\n" +
4501
		"visibleElements={}",
4502
		result.context);
4503
}
4504
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
4505
public void test0155() throws JavaModelException {
4506
	this.workingCopies = new ICompilationUnit[3];
4507
	this.workingCopies[0] = getWorkingCopy(
4508
		"/Completion/src3/test/X.java",
4509
		"package test;\n" + 
4510
		"public class X {\n" + 
4511
		"  public A methodX() {return null;}\n" + 
4512
		"  public void foo() {\n" +
4513
		"    zzzz\n" +
4514
		"  }\n" +
4515
		"}");
4516
	
4517
	this.workingCopies[1] = getWorkingCopy(
4518
		"/Completion/src3/test/A.java",
4519
		"package test;\n" + 
4520
		"public class A extends B {\n" + 
4521
		"}");
4522
	
4523
	this.workingCopies[2] = getWorkingCopy(
4524
		"/Completion/src3/test/B.java",
4525
		"package test;\n" + 
4526
		"public class B {\n" + 
4527
		"}");
4528
	
4529
	
4530
	String str = this.workingCopies[0].getSource();
4531
	int tokenStart = str.lastIndexOf("zzzz");
4532
	int tokenEnd = tokenStart + "zzzz".length() - 1;
4533
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
4534
4535
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "Ltest/B;");
4536
	
4537
	assertResults(
4538
		"completion offset="+(cursorLocation)+"\n" +
4539
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4540
		"completion token=\"zzzz\"\n" +
4541
		"completion token kind=TOKEN_KIND_NAME\n" +
4542
		"expectedTypesSignatures=null\n" +
4543
		"expectedTypesKeys=null\n" +
4544
		"completion token location={STATEMENT_START}\n" +
4545
		"visibleElements={\n" +
4546
		"	methodX() {key=Ltest/X;.methodX()Ltest/A;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
4547
		"}",
4548
		result.context);
4549
}
4550
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
4551
public void test0156() throws JavaModelException {
4552
	this.workingCopies = new ICompilationUnit[3];
4553
	this.workingCopies[0] = getWorkingCopy(
4554
		"/Completion/src3/test/X.java",
4555
		"package test;\n" + 
4556
		"public class X {\n" + 
4557
		"  public A methodX() {return null;}\n" + 
4558
		"  public void foo() {\n" +
4559
		"    zzzz\n" +
4560
		"  }\n" +
4561
		"}");
4562
	
4563
	
4564
	String str = this.workingCopies[0].getSource();
4565
	int tokenStart = str.lastIndexOf("zzzz");
4566
	int tokenEnd = tokenStart + "zzzz".length() - 1;
4567
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
4568
4569
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "Ltest/Zork;");
4570
	
4571
	assertResults(
4572
		"completion offset="+(cursorLocation)+"\n" +
4573
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4574
		"completion token=\"zzzz\"\n" +
4575
		"completion token kind=TOKEN_KIND_NAME\n" +
4576
		"expectedTypesSignatures=null\n" +
4577
		"expectedTypesKeys=null\n" +
4578
		"completion token location={STATEMENT_START}\n" +
4579
		"visibleElements={}",
4580
		result.context);
4581
}
4582
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
4583
public void test0157() throws JavaModelException {
4584
	this.workingCopies = new ICompilationUnit[3];
4585
	this.workingCopies[0] = getWorkingCopy(
4586
		"/Completion/src3/test/X.java",
4587
		"package test;\n" + 
4588
		"public class X {\n" + 
4589
		"  public test.Zork methodX() {return null;}\n" + 
4590
		"  public void foo() {\n" +
4591
		"    zzzz\n" +
4592
		"  }\n" +
4593
		"}");
4594
	
4595
	
4596
	String str = this.workingCopies[0].getSource();
4597
	int tokenStart = str.lastIndexOf("zzzz");
4598
	int tokenEnd = tokenStart + "zzzz".length() - 1;
4599
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
4600
4601
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "Ltest/Zork;");
4602
	
4603
	assertResults(
4604
		"completion offset="+(cursorLocation)+"\n" +
4605
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4606
		"completion token=\"zzzz\"\n" +
4607
		"completion token kind=TOKEN_KIND_NAME\n" +
4608
		"expectedTypesSignatures=null\n" +
4609
		"expectedTypesKeys=null\n" +
4610
		"completion token location={STATEMENT_START}\n" +
4611
		"visibleElements={\n" +
4612
		"	methodX() {key=Ltest/X;.methodX()Ltest/Zork;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
4613
		"}",
4614
		result.context);
4615
}
4616
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
4617
public void test0158() throws JavaModelException {
4618
	this.workingCopies = new ICompilationUnit[3];
4619
	this.workingCopies[0] = getWorkingCopy(
4620
		"/Completion/src3/test/X.java",
4621
		"package test;\n" + 
4622
		"public class X {\n" + 
4623
		"  public void foo() {\n" +
4624
		"    zzzz\n" +
4625
		"  }\n" +
4626
		"}");
4627
	
4628
	
4629
	String str = this.workingCopies[0].getSource();
4630
	int tokenStart = str.lastIndexOf("zzzz");
4631
	int tokenEnd = tokenStart + "zzzz".length() - 1;
4632
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
4633
4634
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, true, false);
4635
	
4636
	assertResults(
4637
		"completion offset="+(cursorLocation)+"\n" +
4638
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4639
		"completion token=\"zzzz\"\n" +
4640
		"completion token kind=TOKEN_KIND_NAME\n" +
4641
		"expectedTypesSignatures=null\n" +
4642
		"expectedTypesKeys=null\n" +
4643
		"completion token location={STATEMENT_START}\n" +
4644
		"enclosingElement=foo() {key=Ltest/X;.foo()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]",
4645
		result.context);
4646
}
4647
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
4648
public void test0159() throws JavaModelException {
4649
	this.workingCopies = new ICompilationUnit[3];
4650
	this.workingCopies[0] = getWorkingCopy(
4651
		"/Completion/src3/test/X.java",
4652
		"package test;\n" + 
4653
		"public class X {\n" + 
4654
		"  public void foo() {}\n" +
4655
		"  zzzz\n" +
4656
		"  public void bar() {}\n" +
4657
		"}");
4658
	
4659
	
4660
	String str = this.workingCopies[0].getSource();
4661
	int tokenStart = str.lastIndexOf("zzzz");
4662
	int tokenEnd = tokenStart + "zzzz".length() - 1;
4663
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
4664
4665
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, true, false);
4666
	
4667
	assertResults(
4668
		"completion offset="+(cursorLocation)+"\n" +
4669
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4670
		"completion token=\"zzzz\"\n" +
4671
		"completion token kind=TOKEN_KIND_NAME\n" +
4672
		"expectedTypesSignatures=null\n" +
4673
		"expectedTypesKeys=null\n" +
4674
		"completion token location={MEMBER_START}\n" +
4675
		"enclosingElement=X {key=Ltest/X;} [in [Working copy] X.java [in test [in src3 [in Completion]]]]",
4676
		result.context);
4677
}
4678
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
4679
public void test0160() throws JavaModelException {
4680
	this.workingCopies = new ICompilationUnit[3];
4681
	this.workingCopies[0] = getWorkingCopy(
4682
		"/Completion/src3/test/X.java",
4683
		"package test;\n" + 
4684
		"zzzz\n" +
4685
		"public class X {\n" + 
4686
		"}");
4687
	
4688
	
4689
	String str = this.workingCopies[0].getSource();
4690
	int tokenStart = str.lastIndexOf("zzzz");
4691
	int tokenEnd = tokenStart + "zzzz".length() - 1;
4692
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
4693
4694
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, true, false);
4695
	
4696
	assertResults(
4697
		"completion offset="+(cursorLocation)+"\n" +
4698
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4699
		"completion token=\"zzzz\"\n" +
4700
		"completion token kind=TOKEN_KIND_NAME\n" +
4701
		"expectedTypesSignatures=null\n" +
4702
		"expectedTypesKeys=null\n" +
4703
		"completion token location=UNKNOWN\n" +
4704
		"enclosingElement=[Working copy] X.java [in test [in src3 [in Completion]]]",
4705
		result.context);
4706
}
4707
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202470
4708
public void test0161() throws JavaModelException {
4709
	this.workingCopies = new ICompilationUnit[3];
4710
	this.workingCopies[0] = getWorkingCopy(
4711
		"/Completion/src3/test/X.java",
4712
		"package test;\n" + 
4713
		"public class X {\n" + 
4714
		"  public void foo() {}\n" +
4715
		"  public class Y {\n" + 
4716
		"    public void fooY() {}\n" +
4717
		"      zzzz\n" +
4718
		"    public void barY() {}\n" +
4719
		"  }\n" +
4720
		"  public void bar() {}\n" +
4721
		"}");
4722
	
4723
	
4724
	String str = this.workingCopies[0].getSource();
4725
	int tokenStart = str.lastIndexOf("zzzz");
4726
	int tokenEnd = tokenStart + "zzzz".length() - 1;
4727
	int cursorLocation = str.lastIndexOf("zzzz") + "zzzz".length();
4728
4729
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, true, false);
4730
	
4731
	assertResults(
4732
		"completion offset="+(cursorLocation)+"\n" +
4733
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4734
		"completion token=\"zzzz\"\n" +
4735
		"completion token kind=TOKEN_KIND_NAME\n" +
4736
		"expectedTypesSignatures=null\n" +
4737
		"expectedTypesKeys=null\n" +
4738
		"completion token location={MEMBER_START}\n" +
4739
		"enclosingElement=Y {key=Ltest/X$Y;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]",
4740
		result.context);
4741
}
3917
}
4742
}
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaModelCompletionTests.java (+29 lines)
Lines 101-107 Link Here
101
	return result;
101
	return result;
102
}
102
}
103
protected CompletionResult contextComplete(ICompilationUnit cu, int cursorLocation) throws JavaModelException {
103
protected CompletionResult contextComplete(ICompilationUnit cu, int cursorLocation) throws JavaModelException {
104
	return contextComplete0(cu, cursorLocation, false, false, false, null);
105
}
106
protected CompletionResult contextComplete(
107
		ICompilationUnit cu,
108
		int cursorLocation,
109
		boolean computeEnclosingElement,
110
		boolean computeVisibleElements) throws JavaModelException {
111
	return contextComplete0(cu, cursorLocation, true, computeEnclosingElement, computeVisibleElements, null);
112
}
113
protected CompletionResult contextComplete(
114
		ICompilationUnit cu,
115
		int cursorLocation,
116
		boolean computeEnclosingElement,
117
		boolean computeVisibleElements,
118
		String typeSignature) throws JavaModelException {
119
	return contextComplete0(cu, cursorLocation, true, computeEnclosingElement, computeVisibleElements, typeSignature);
120
}
121
protected CompletionResult contextComplete0(
122
		ICompilationUnit cu,
123
		int cursorLocation,
124
		boolean useExtendedContext,
125
		boolean computeEnclosingElement,
126
		boolean computeVisibleElements,
127
		String typeSignature) throws JavaModelException {
104
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, false);
128
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, false);
129
	requestor.setRequireExtendedContext(useExtendedContext);
130
	requestor.setComputeEnclosingElement(computeEnclosingElement);
131
	requestor.setComputeVisibleElements(computeVisibleElements);
132
	requestor.setAssignableType(typeSignature);
133
	
105
	cu.codeComplete(cursorLocation, requestor, this.wcOwner);
134
	cu.codeComplete(cursorLocation, requestor, this.wcOwner);
106
	
135
	
107
	CompletionResult result =  new CompletionResult();
136
	CompletionResult result =  new CompletionResult();
(-)src/org/eclipse/jdt/core/tests/model/CompletionTestsRequestor2.java (+49 lines)
Lines 16-23 Link Here
16
import org.eclipse.jdt.core.CompletionContext;
16
import org.eclipse.jdt.core.CompletionContext;
17
import org.eclipse.jdt.core.CompletionProposal;
17
import org.eclipse.jdt.core.CompletionProposal;
18
import org.eclipse.jdt.core.CompletionRequestor;
18
import org.eclipse.jdt.core.CompletionRequestor;
19
import org.eclipse.jdt.core.IJavaElement;
19
import org.eclipse.jdt.core.Signature;
20
import org.eclipse.jdt.core.Signature;
20
import org.eclipse.jdt.core.compiler.IProblem;
21
import org.eclipse.jdt.core.compiler.IProblem;
22
import org.eclipse.jdt.internal.core.JavaElement;
21
23
22
public class CompletionTestsRequestor2 extends CompletionRequestor {
24
public class CompletionTestsRequestor2 extends CompletionRequestor {
23
	private final char[] NULL_LITERAL = "null".toCharArray();//$NON-NLS-1$
25
	private final char[] NULL_LITERAL = "null".toCharArray();//$NON-NLS-1$
Lines 35-40 Link Here
35
	private boolean shortContext;
37
	private boolean shortContext;
36
	private boolean showMissingTypes;
38
	private boolean showMissingTypes;
37
	
39
	
40
	private boolean computeVisibleElements;
41
	private boolean computeEnclosingElement;
42
	private String assignableType;
43
	
38
	public boolean fDebug = false;
44
	public boolean fDebug = false;
39
45
40
	public CompletionTestsRequestor2() {
46
	public CompletionTestsRequestor2() {
Lines 181-186 Link Here
181
				buffer.append('}');
187
				buffer.append('}');
182
			}
188
			}
183
		}
189
		}
190
		
191
		if (this.computeEnclosingElement) {
192
			buffer.append('\n');
193
			buffer.append("enclosingElement="); //$NON-NLS-1$
194
			JavaElement enclosingElement = (JavaElement)this.context.getEnclosingElement();
195
			if (enclosingElement == null) {
196
				buffer.append("null"); //$NON-NLS-1$
197
			} else {
198
				buffer.append(enclosingElement.toStringWithAncestors(true /*show resolved info*/));
199
			}
200
		}
201
		
202
		if (this.computeVisibleElements) {
203
			buffer.append('\n');
204
			
205
			IJavaElement[] visibleElements = this.context.getVisibleElements(this.assignableType);
206
			buffer.append("visibleElements="); //$NON-NLS-1$
207
			if (visibleElements == null) {
208
				buffer.append("null"); //$NON-NLS-1$
209
			} else if (visibleElements.length == 0) {
210
				buffer.append("{}"); //$NON-NLS-1$
211
			} else {
212
				buffer.append('{');
213
				buffer.append('\n');
214
				for (int i = 0; i < visibleElements.length; i++) {
215
					JavaElement element = (JavaElement) visibleElements[i];
216
					buffer.append('\t');
217
					buffer.append(element.toStringWithAncestors(true /*show resolved info*/));
218
					buffer.append(",\n"); //$NON-NLS-1$
219
				}
220
				buffer.append('}');
221
			}
222
		}
223
		
184
		//buffer.append('\n');
224
		//buffer.append('\n');
185
		
225
		
186
		
226
		
Lines 522-525 Link Here
522
	public String toString() {
562
	public String toString() {
523
		return getResults();
563
		return getResults();
524
	}
564
	}
565
	public void setComputeVisibleElements(boolean computeVisibleElements) {
566
		this.computeVisibleElements = computeVisibleElements;
567
	}
568
	public void setAssignableType(String typeSignature) {
569
		this.assignableType = typeSignature;
570
	}
571
	public void setComputeEnclosingElement(boolean computeEnclosingElement) {
572
		this.computeEnclosingElement = computeEnclosingElement;
573
	}
525
}
574
}

Return to bug 202470