Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.jdt.internal.codeassist.impl;
 
 import java.util.Map;
 
 
 
 public abstract class Engine implements ITypeRequestor {
 
 
 
 	public boolean forbiddenReferenceIsError;
 	public boolean discouragedReferenceIsError;
 
 	public boolean importCachesInitialized = false;
 	public char[][][] importsCache;
 	public int importCacheCount = 0;
 	public int onDemandImportCacheCount = 0;
 	public char[] currentPackageName = null;
 
 	public Engine(Map settings){
 		this. = new AssistOptions(settings);
 		this. = new CompilerOptions(settings);
 	}

Add an additional binary type
 
 	public void accept(IBinaryType binaryTypePackageBinding packageBindingAccessRestriction accessRestriction) {
 		this..createBinaryTypeFrom(binaryTypepackageBindingaccessRestriction);
 	}

Add an additional compilation unit.
 
 	public void accept(ICompilationUnit sourceUnitAccessRestriction accessRestriction) {
 		CompilationResult result = new CompilationResult(sourceUnit, 1, 1, this..);
 		
 		AssistParser assistParser = getParser();
 		Object parserState = assistParser.becomeSimpleParser();
 		
 			assistParser.dietParse(sourceUnitresult);
 		
 		assistParser.restoreAssistParser(parserState);
 
 		this..buildTypeBindings(parsedUnitaccessRestriction);
 		this..completeTypeBindings(parsedUnittrue);
 	}

Add additional source types (the first one is the requested type, the rest is formed by the secondary types defined in the same compilation unit).
 
 	public void accept(ISourceType[] sourceTypesPackageBinding packageBindingAccessRestriction accessRestriction) {
 		CompilationResult result =
 			new CompilationResult(sourceTypes[0].getFileName(), 1, 1, this..);
 			SourceTypeConverter.buildCompilationUnit(
 				sourceTypes,//sourceTypes[0] is always toplevel here
 				. // need field and methods
 				| .// need member types
 				// no need for field initialization
 				result);
 
 		if (unit != null) {
 			this..buildTypeBindings(unitaccessRestriction);
		}
	}
	public abstract AssistParser getParser();
	public void initializeImportCaches() {
		if (this. == null) {
		}
		ImportBinding[] importBindings = this..;
		int length = importBindings == null ? 0 : importBindings.length;
		for (int i = 0; i < lengthi++) {
			ImportBinding importBinding = importBindings[i];
			if(importBinding.onDemand) {
				if(this. == null) {
					this. = new ImportBinding[length - i];
				}
					importBinding;
else {
				if(!(importBinding.resolvedImport instanceof MethodBinding) ||
						importBinding instanceof ImportConflictBinding) {
					if(this. == null) {
						this. = new char[length - i][][];
					}
					this.[this.++] = new char[][]{
							importBinding.compoundName[importBinding.compoundName.length - 1],
							CharOperation.concatWith(importBinding.compoundName'.')
						};
				}
			}
		}
	}
	public void initializePackageCache() {
		if (this.. != null) {
			this. = CharOperation.concatWith(this...'.');
else if (this.. != null &&
else {
		}
	}
	protected boolean mustQualifyType(
		char[] packageName,
		char[] typeName,
		char[] enclosingTypeNames,
		int modifiers) {
		// If there are no types defined into the current CU yet.
		if (this. == null)
			return true;
		}
		for (int i = 0; i < this.i++) {
			char[][] importName = this.[i];
			if(CharOperation.equals(typeNameimportName[0])) {
				char[] fullyQualifiedTypeName =
					enclosingTypeNames == null || enclosingTypeNames.length == 0
							? CharOperation.concat(
									packageName,
									typeName,
									'.')
							: CharOperation.concat(
									CharOperation.concat(
										packageName,
										enclosingTypeNames,
										'.'),
									typeName,
									'.');
				return !CharOperation.equals(fullyQualifiedTypeNameimportName[1]);
			}
		}
		if ((enclosingTypeNames == null || enclosingTypeNames.length == 0 ) && CharOperation.equals(this.packageName))
			return false;
		char[] fullyQualifiedEnclosingTypeName = null;
		for (int i = 0; i < this.i++) {
			ImportBinding importBinding = this.[i];
			Binding resolvedImport = importBinding.resolvedImport;
			char[][] importName = importBinding.compoundName;
			char[] importFlatName = CharOperation.concatWith(importName'.');
			boolean isFound = false;
			// resolvedImport is a ReferenceBindng or a PackageBinding
			if(resolvedImport instanceof ReferenceBinding) {
				if(enclosingTypeNames != null && enclosingTypeNames.length != 0) {
					if(fullyQualifiedEnclosingTypeName == null) {
						fullyQualifiedEnclosingTypeName =
							CharOperation.concat(
									packageName,
									enclosingTypeNames,
									'.');
					}
					if(CharOperation.equals(fullyQualifiedEnclosingTypeNameimportFlatName)) {
						if(importBinding.isStatic()) {
							isFound = (modifiers & .) != 0;
else {
							isFound = true;
						}
					}
				}
else {
				if(enclosingTypeNames == null || enclosingTypeNames.length == 0) {
					if(CharOperation.equals(packageNameimportFlatName)) {
						if(importBinding.isStatic()) {
							isFound = (modifiers & .) != 0;
else {
							isFound = true;
						}
					}
				}
			}
			// find potential conflict with another import
			if(isFound) {
				for (int j = 0; j < this.j++) {
					if(i != j) {
						ImportBinding conflictingImportBinding = this.[j];
						if(conflictingImportBinding.resolvedImport instanceof ReferenceBinding) {
							ReferenceBinding refBinding =
								(ReferenceBindingconflictingImportBinding.resolvedImport;
							if (refBinding.getMemberType(typeName) != null) {
								return true;
							}
else {
							char[] conflictingImportName =
								CharOperation.concatWith(conflictingImportBinding.compoundName'.');
									String.valueOf(typeName),
									String.valueOf(conflictingImportName),
									false,
									false/*don't check restrictions*/) != null) {
								return true;
							}
						}
					}
				}
				return false;
			}
		}
		return true;
	}
	/*
	 * Find the node (a field, a method or an initializer) at the given position
	 * and parse its block statements if it is a method or an initializer.
	 * Returns the node or null if not found
	 */
	protected ASTNode parseBlockStatements(CompilationUnitDeclaration unitint position) {
		int length = unit.types.length;
		for (int i = 0; i < lengthi++) {
			TypeDeclaration type = unit.types[i];
			if (type.declarationSourceStart < position
				&& type.declarationSourceEnd >= position) {
				getParser()..setSource(unit.compilationResult);
				return parseBlockStatements(typeunitposition);
			}
		}
		return null;
	}
		int position) {
		//members
		TypeDeclaration[] memberTypes = type.memberTypes;
		if (memberTypes != null) {
			int length = memberTypes.length;
			for (int i = 0; i < lengthi++) {
				TypeDeclaration memberType = memberTypes[i];
				if (memberType.bodyStart > position)
					continue;
				if (memberType.declarationSourceEnd >= position) {
					return parseBlockStatements(memberTypeunitposition);
				}
			}
		}
		//methods
		AbstractMethodDeclaration[] methods = type.methods;
		if (methods != null) {
			int length = methods.length;
			for (int i = 0; i < lengthi++) {
				AbstractMethodDeclaration method = methods[i];
				if (method.bodyStart > position + 1)
					continue;
					continue;
				if (method.declarationSourceEnd >= position) {
					return method;
				}
			}
		}
		//initializers
		FieldDeclaration[] fields = type.fields;
		if (fields != null) {
			int length = fields.length;
			for (int i = 0; i < lengthi++) {
				FieldDeclaration field = fields[i];
				if (field.sourceStart > position)
					continue;
				if (field.declarationSourceEnd >= position) {
					if (field instanceof Initializer) {
					}
					return field;
				}
			}
		}
		return null;
	}
	protected void reset(boolean resetLookupEnvironment) {
		if (resetLookupEnvironmentthis..reset();
	}
	public static char[] getTypeSignature(TypeBinding typeBinding) {
		char[] result = typeBinding.signature();
		if (result != null) {
			result = CharOperation.replaceOnCopy(result'/''.');
		}
		return result;
	}
	public static char[] getSignature(MethodBinding methodBinding) {
		char[] result = null;
		int oldMod = methodBinding.modifiers;
		//TODO remove the next line when method from binary type will be able to generate generic signature
		methodBinding.modifiers |= .;
		result = methodBinding.genericSignature();
		if(result == null) {
			result = methodBinding.signature();
		}
		methodBinding.modifiers = oldMod;
		if (result != null) {
			result = CharOperation.replaceOnCopy(result'/''.');
		}
		return result;
	}
	public static char[] getSignature(TypeBinding typeBinding) {
		char[] result = null;
		result = typeBinding.genericTypeSignature();
		if (result != null) {
			result = CharOperation.replaceOnCopy(result'/''.');
		}
		return result;
	}
New to GrepCode? Check out our FAQ X