org.eclipse.jdt.internal.compiler.ast.ImportReference Java Examples

The following examples show how to use org.eclipse.jdt.internal.compiler.ast.ImportReference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaDerivedStateComputer.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public void installStubs(Resource resource) {
	if (isInfoFile(resource)) {
		return;
	}
	CompilationUnit compilationUnit = getCompilationUnit(resource);
	ProblemReporter problemReporter = new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(),
			getCompilerOptions(resource), new DefaultProblemFactory());
	Parser parser = new Parser(problemReporter, true);
	CompilationResult compilationResult = new CompilationResult(compilationUnit, 0, 1, -1);
	CompilationUnitDeclaration result = parser.dietParse(compilationUnit, compilationResult);
	if (result.types != null) {
		for (TypeDeclaration type : result.types) {
			ImportReference currentPackage = result.currentPackage;
			String packageName = null;
			if (currentPackage != null) {
				char[][] importName = currentPackage.getImportName();
				if (importName != null) {
					packageName = CharOperation.toString(importName);
				}
			}
			JvmDeclaredType jvmType = createType(type, packageName);
			resource.getContents().add(jvmType);
		}
	}
}
 
Example #2
Source File: EclipseImportList.java    From EasyMPermission with MIT License 6 votes vote down vote up
private static boolean isEqual(String packageName, ImportReference pkgOrStarImport) {
	if (pkgOrStarImport == null || pkgOrStarImport.tokens == null || pkgOrStarImport.tokens.length == 0) return packageName.isEmpty();
	int pos = 0;
	int len = packageName.length();
	for (int i = 0; i < pkgOrStarImport.tokens.length; i++) {
		if (i != 0) {
			if (pos >= len) return false;
			if (packageName.charAt(pos++) != '.') return false;
		}
		for (int j = 0; j < pkgOrStarImport.tokens[i].length; j++) {
			if (pos >= len) return false;
			if (packageName.charAt(pos++) != pkgOrStarImport.tokens[i][j]) return false;
		}
	}
	return true;
}
 
Example #3
Source File: RecoveredUnit.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public RecoveredElement add(ImportReference importReference, int bracketBalanceValue) {
	resetPendingModifiers();

	if (this.imports == null) {
		this.imports = new RecoveredImport[5];
		this.importCount = 0;
	} else {
		if (this.importCount == this.imports.length) {
			System.arraycopy(
				this.imports,
				0,
				(this.imports = new RecoveredImport[2 * this.importCount]),
				0,
				this.importCount);
		}
	}
	RecoveredImport element = new RecoveredImport(importReference, this, bracketBalanceValue);
	this.imports[this.importCount++] = element;

	/* if import not finished, then import becomes current */
	if (importReference.declarationSourceEnd == 0) return element;
	return this;
}
 
Example #4
Source File: SourceElementNotifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected void notifySourceElementRequestor(
	ImportReference importReference,
	boolean isPackage) {
	if (isPackage) {
		this.requestor.acceptPackage(importReference);
	} else {
		final boolean onDemand = (importReference.bits & ASTNode.OnDemand) != 0;
		this.requestor.acceptImport(
			importReference.declarationSourceStart,
			importReference.declarationSourceEnd,
			importReference.sourceStart,
			onDemand ? importReference.trailingStarPosition : importReference.sourceEnd,
			importReference.tokens,
			onDemand,
			importReference.modifiers);
	}
}
 
Example #5
Source File: TypeConverter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected ImportReference createImportReference(
	String[] importName,
	int start,
	int end,
	boolean onDemand,
	int modifiers) {

	int length = importName.length;
	long[] positions = new long[length];
	long position = ((long) start << 32) + end;
	char[][] qImportName = new char[length][];
	for (int i = 0; i < length; i++) {
		qImportName[i] = importName[i].toCharArray();
		positions[i] = position; // dummy positions
	}
	return new ImportReference(
		qImportName,
		positions,
		onDemand,
		modifiers);
}
 
Example #6
Source File: EclipseImportList.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override public String getFullyQualifiedNameForSimpleName(String unqualified) {
	if (imports != null) {
		outer:
		for (ImportReference imp : imports) {
			if ((imp.bits & ASTNode.OnDemand) != 0) continue;
			char[][] tokens = imp.tokens;
			char[] token = tokens.length == 0 ? new char[0] : tokens[tokens.length - 1];
			int len = token.length;
			if (len != unqualified.length()) continue;
			for (int i = 0; i < len; i++) if (token[i] != unqualified.charAt(i)) continue outer;
			return LombokInternalAliasing.processAliases(toQualifiedName(tokens));
		}
	}
	return null;
}
 
Example #7
Source File: RecoveredElement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public RecoveredElement add(ImportReference importReference, int bracketBalanceValue){

	/* default behavior is to delegate recording to parent if any */
	resetPendingModifiers();
	if (this.parent == null) return this; // ignore
	this.updateSourceEndIfNecessary(previousAvailableLineEnd(importReference.declarationSourceStart - 1));
	return this.parent.add(importReference, bracketBalanceValue);
}
 
Example #8
Source File: DefaultBindingResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
synchronized IPackageBinding resolvePackage(PackageDeclaration pkg) {
	if (this.scope == null) return null;
	try {
		org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(pkg);
		if (node instanceof ImportReference) {
			ImportReference importReference = (ImportReference) node;
			Binding binding = this.scope.getOnlyPackage(CharOperation.subarray(importReference.tokens, 0, importReference.tokens.length));
			if ((binding != null) && (binding.isValidBinding())) {
				if (binding instanceof ReferenceBinding) {
					// this only happens if a type name has the same name as its package
					ReferenceBinding referenceBinding = (ReferenceBinding) binding;
					binding = referenceBinding.fPackage;
				}
				if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
					IPackageBinding packageBinding = getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding) binding);
					if (packageBinding == null) {
						return null;
					}
					this.bindingsToAstNodes.put(packageBinding, pkg);
					String key = packageBinding.getKey();
					if (key != null) {
						this.bindingTables.bindingKeysToBindings.put(key, packageBinding);
					}
					return packageBinding;
				}
			}
		}
	} catch (AbortCompilation e) {
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=63550
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=64299
	}
	return null;
}
 
Example #9
Source File: BinaryTypeConverter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Convert a binary type into an AST type declaration and put it in the given compilation unit.
 */
public TypeDeclaration buildTypeDeclaration(IType type, CompilationUnitDeclaration compilationUnit)  throws JavaModelException {
	PackageFragment pkg = (PackageFragment) type.getPackageFragment();
	char[][] packageName = Util.toCharArrays(pkg.names);

	if (packageName.length > 0) {
		compilationUnit.currentPackage = new ImportReference(packageName, new long[]{0}, false, ClassFileConstants.AccDefault);
	}

	/* convert type */
	TypeDeclaration typeDeclaration = convert(type, null, null);

	IType alreadyComputedMember = type;
	IType parent = type.getDeclaringType();
	TypeDeclaration previousDeclaration = typeDeclaration;
	while(parent != null) {
		TypeDeclaration declaration = convert(parent, alreadyComputedMember, previousDeclaration);

		alreadyComputedMember = parent;
		previousDeclaration = declaration;
		parent = parent.getDeclaringType();
	}

	compilationUnit.types = new TypeDeclaration[]{previousDeclaration};

	return typeDeclaration;
}
 
Example #10
Source File: BinaryTypeConverter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ImportReference[] buildImports(ClassFileReader reader) {
	// add remaining references to the list of type names
	// (code extracted from BinaryIndexer#extractReferenceFromConstantPool(...))
	int[] constantPoolOffsets = reader.getConstantPoolOffsets();
	int constantPoolCount = constantPoolOffsets.length;
	for (int i = 0; i < constantPoolCount; i++) {
		int tag = reader.u1At(constantPoolOffsets[i]);
		char[] name = null;
		switch (tag) {
			case ClassFileConstants.MethodRefTag :
			case ClassFileConstants.InterfaceMethodRefTag :
				int constantPoolIndex = reader.u2At(constantPoolOffsets[i] + 3);
				int utf8Offset = constantPoolOffsets[reader.u2At(constantPoolOffsets[constantPoolIndex] + 3)];
				name = reader.utf8At(utf8Offset + 3, reader.u2At(utf8Offset + 1));
				break;
			case ClassFileConstants.ClassTag :
				utf8Offset = constantPoolOffsets[reader.u2At(constantPoolOffsets[i] + 1)];
				name = reader.utf8At(utf8Offset + 3, reader.u2At(utf8Offset + 1));
				break;
		}
		if (name == null || (name.length > 0 && name[0] == '['))
			break; // skip over array references
		this.typeNames.add(CharOperation.splitOn('/', name));
	}

	// convert type names into import references
	int typeNamesLength = this.typeNames.size();
	ImportReference[] imports = new ImportReference[typeNamesLength];
	char[][][] set = this.typeNames.set;
	int index = 0;
	for (int i = 0, length = set.length; i < length; i++) {
		char[][] typeName = set[i];
		if (typeName != null) {
			imports[index++] = new ImportReference(typeName, new long[typeName.length]/*dummy positions*/, false/*not on demand*/, 0);
		}
	}
	return imports;
}
 
Example #11
Source File: CompilationUnitStructureRequestor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see ISourceElementRequestor
 */
public void acceptPackage(ImportReference importReference) {

		Object parentInfo = this.infoStack.peek();
		JavaElement parentHandle= (JavaElement) this.handleStack.peek();
		PackageDeclaration handle = null;

		if (parentHandle.getElementType() == IJavaElement.COMPILATION_UNIT) {
			char[] name = CharOperation.concatWith(importReference.getImportName(), '.');
			handle = createPackageDeclaration(parentHandle, new String(name));
		}
		else {
			Assert.isTrue(false); // Should not happen
		}
		resolveDuplicates(handle);

		AnnotatableInfo info = new AnnotatableInfo();
		info.setSourceRangeStart(importReference.declarationSourceStart);
		info.setSourceRangeEnd(importReference.declarationSourceEnd);
		info.setNameSourceStart(importReference.sourceStart);
		info.setNameSourceEnd(importReference.sourceEnd);

		addToChildren(parentInfo, handle);
		this.newElements.put(handle, info);

		if (importReference.annotations != null) {
			for (int i = 0, length = importReference.annotations.length; i < length; i++) {
				org.eclipse.jdt.internal.compiler.ast.Annotation annotation = importReference.annotations[i];
				acceptAnnotation(annotation, info, handle);
			}
		}
}
 
Example #12
Source File: AndLocator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void matchReportImportRef(ImportReference importRef, Binding binding, IJavaElement element, int accuracy, MatchLocator locator) throws CoreException {
	PatternLocator weakestPattern = null;
	int level = IMPOSSIBLE_MATCH;
	for (int i = 0, length = this.patternLocators.length; i < length; i++) {
		int newLevel = this.patternLocators[i].matchLevel(importRef);
		if (newLevel == IMPOSSIBLE_MATCH) return;
		if (weakestPattern == null || newLevel < level) {
			weakestPattern = this.patternLocators[i];
			level = newLevel;
		}
	}
	weakestPattern.matchReportImportRef(importRef, binding, element, accuracy, locator);
}
 
Example #13
Source File: OrLocator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void matchReportImportRef(ImportReference importRef, Binding binding, IJavaElement element, int accuracy, MatchLocator locator) throws CoreException {
	PatternLocator closestPattern = null;
	int level = IMPOSSIBLE_MATCH;
	for (int i = 0, length = this.patternLocators.length; i < length; i++) {
		int newLevel = this.patternLocators[i].matchLevel(importRef);
		if (newLevel > level) {
			closestPattern = this.patternLocators[i];
			if (newLevel == ACCURATE_MATCH) break;
			level = newLevel;
		}
	}
	if (closestPattern != null)
		closestPattern.matchReportImportRef(importRef, binding, element, accuracy, locator);
}
 
Example #14
Source File: OrLocator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void matchLevelAndReportImportRef(ImportReference importRef, Binding binding, MatchLocator locator) throws CoreException {

	// for static import, binding can be a field binding or a member type binding
	// verify that in this case binding is static and use declaring class for fields
	Binding refBinding = binding;
	if (importRef.isStatic()) {
		if (binding instanceof FieldBinding) {
			FieldBinding fieldBinding = (FieldBinding) binding;
			if (!fieldBinding.isStatic()) return;
			refBinding = fieldBinding.declaringClass;
		} else if (binding instanceof MethodBinding) {
			MethodBinding methodBinding = (MethodBinding) binding;
			if (!methodBinding.isStatic()) return;
			refBinding = methodBinding.declaringClass;
		} else if (binding instanceof MemberTypeBinding) {
			MemberTypeBinding memberBinding = (MemberTypeBinding) binding;
			if (!memberBinding.isStatic()) return;
		}
	}

	// Look for closest pattern
	PatternLocator closestPattern = null;
	int level = IMPOSSIBLE_MATCH;
	for (int i = 0, length = this.patternLocators.length; i < length; i++) {
		PatternLocator patternLocator = this.patternLocators[i];
		int newLevel = patternLocator.referenceType() == 0 ? IMPOSSIBLE_MATCH : patternLocator.resolveLevel(refBinding);
		if (newLevel > level) {
			closestPattern = patternLocator;
			if (newLevel == ACCURATE_MATCH) break;
			level = newLevel;
		}
	}
	if (closestPattern != null) {
		closestPattern.matchLevelAndReportImportRef(importRef, binding, locator);
	}
}
 
Example #15
Source File: IndexingParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected ImportReference newImportReference(char[][] tokens, long[] sourcePositions, boolean onDemand, int mod) {
	ImportReference ref = this.importReference;
	ref.tokens = tokens;
	ref.sourcePositions = sourcePositions;
	if (onDemand) {
		ref.bits |= ASTNode.OnDemand;
	}
	ref.sourceEnd = (int) (sourcePositions[sourcePositions.length-1] & 0x00000000FFFFFFFF);
	ref.sourceStart = (int) (sourcePositions[0] >>> 32);
	ref.modifiers = this.modifiers;
	return ref;
}
 
Example #16
Source File: CompletionElementNotifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void notifySourceElementRequestor(ImportReference importReference, boolean isPackage) {
	if (importReference instanceof CompletionOnKeyword2) return;
	if (importReference instanceof CompletionOnImportReference ||
			importReference instanceof CompletionOnPackageReference) {
		if (importReference.tokens[importReference.tokens.length - 1].length == 0) return;
	}

	super.notifySourceElementRequestor(importReference, isPackage);
}
 
Example #17
Source File: EclipseImportList.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override public Collection<String> applyNameToStarImports(String startsWith, String name) {
	List<String> out = Collections.emptyList();
	
	if (pkg != null && pkg.tokens != null && pkg.tokens.length != 0) {
		char[] first = pkg.tokens[0];
		int len = first.length;
		boolean match = true;
		if (startsWith.length() == len) {
			for (int i = 0; match && i < len; i++) {
				if (startsWith.charAt(i) != first[i]) match = false;
			}
			if (match) out.add(toQualifiedName(pkg.tokens) + "." + name);
		}
	}
	
	if (imports != null) {
		outer:
		for (ImportReference imp : imports) {
			if ((imp.bits & ASTNode.OnDemand) == 0) continue;
			if (imp.isStatic()) continue;
			if (imp.tokens == null || imp.tokens.length == 0) continue;
			char[] firstToken = imp.tokens[0];
			if (firstToken.length != startsWith.length()) continue;
			for (int i = 0; i < firstToken.length; i++) if (startsWith.charAt(i) != firstToken[i]) continue outer;
			String fqn = toQualifiedName(imp.tokens) + "." + name;
			if (out.isEmpty()) out = Collections.singletonList(fqn);
			else if (out.size() == 1) {
				out = new ArrayList<String>(out);
				out.add(fqn);
			} else {
				out.add(fqn);
			}
		}
	}
	return out;
}
 
Example #18
Source File: SetGeneratedByVisitor.java    From EasyMPermission with MIT License 5 votes vote down vote up
private void fixPositions(ImportReference node) {
	node.sourceEnd = sourceEnd;
	node.sourceStart = sourceStart;
	node.declarationEnd = sourceEnd;
	node.declarationSourceEnd = sourceEnd;
	node.declarationSourceStart = sourceStart;
	if (node.sourcePositions == null || node.sourcePositions.length != node.tokens.length) node.sourcePositions = new long[node.tokens.length];
	Arrays.fill(node.sourcePositions, sourcePos);
}
 
Example #19
Source File: SourceMapper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see ISourceElementRequestor
 */
public void acceptPackage(ImportReference importReference) {
	//do nothing
}
 
Example #20
Source File: ImportBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public ImportBinding(char[][] compoundName, boolean isOnDemand, Binding binding, ImportReference reference) {
	this.compoundName = compoundName;
	this.onDemand = isOnDemand;
	this.resolvedImport = binding;
	this.reference = reference;
}
 
Example #21
Source File: ImportConflictBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public ImportConflictBinding(char[][] compoundName, Binding methodBinding, ReferenceBinding conflictingTypeBinding, ImportReference reference) {
	super(compoundName, false, methodBinding, reference);
	this.conflictingTypeBinding = conflictingTypeBinding;
}
 
Example #22
Source File: RecoveredUnit.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public CompilationUnitDeclaration updatedCompilationUnitDeclaration(){

	/* update imports */
	if (this.importCount > 0){
		ImportReference[] importRefences = new ImportReference[this.importCount];
		for (int i = 0; i < this.importCount; i++){
			importRefences[i] = this.imports[i].updatedImportReference();
		}
		this.unitDeclaration.imports = importRefences;
	}
	/* update types */
	if (this.typeCount > 0){
		int existingCount = this.unitDeclaration.types == null ? 0 : this.unitDeclaration.types.length;
		TypeDeclaration[] typeDeclarations = new TypeDeclaration[existingCount + this.typeCount];
		if (existingCount > 0){
			System.arraycopy(this.unitDeclaration.types, 0, typeDeclarations, 0, existingCount);
		}
		// may need to update the declarationSourceEnd of the last type
		if (this.types[this.typeCount - 1].typeDeclaration.declarationSourceEnd == 0){
			this.types[this.typeCount - 1].typeDeclaration.declarationSourceEnd = this.unitDeclaration.sourceEnd;
			this.types[this.typeCount - 1].typeDeclaration.bodyEnd = this.unitDeclaration.sourceEnd;
		}
		
		Set knownTypes = new HashSet();
		int actualCount = existingCount;
		for (int i = 0; i < this.typeCount; i++){
			TypeDeclaration typeDecl = this.types[i].updatedTypeDeclaration(0, knownTypes);
			// filter out local types (12454)
			if (typeDecl != null && (typeDecl.bits & ASTNode.IsLocalType) == 0){
				typeDeclarations[actualCount++] = typeDecl;
			}
		}
		if (actualCount != this.typeCount){
			System.arraycopy(
				typeDeclarations,
				0,
				typeDeclarations = new TypeDeclaration[existingCount+actualCount],
				0,
				existingCount+actualCount);
		}
		this.unitDeclaration.types = typeDeclarations;
	}
	return this.unitDeclaration;
}
 
Example #23
Source File: EclipseAST.java    From EasyMPermission with MIT License 4 votes vote down vote up
private static String packageDeclaration(CompilationUnitDeclaration cud) {
	ImportReference pkg = cud.currentPackage;
	return pkg == null ? null : Eclipse.toQualifiedName(pkg.getImportName());
}
 
Example #24
Source File: RecoveredImport.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public RecoveredImport(ImportReference importReference, RecoveredElement parent, int bracketBalance){
	super(parent, bracketBalance);
	this.importReference = importReference;
}
 
Example #25
Source File: SetGeneratedByVisitor.java    From EasyMPermission with MIT License 4 votes vote down vote up
@Override public boolean visit(ImportReference node, CompilationUnitScope scope) {
	fixPositions(setGeneratedBy(node, source));
	return super.visit(node, scope);
}
 
Example #26
Source File: SourceElementNotifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void notifySourceElementRequestor(
		CompilationUnitDeclaration parsedUnit,
		int sourceStart,
		int sourceEnd,
		boolean reportReference,
		HashtableOfObjectToInt sourceEndsMap,
		Map nodesToCategoriesMap) {

	this.initialPosition = sourceStart;
	this.eofPosition = sourceEnd;

	this.reportReferenceInfo = reportReference;
	this.sourceEnds = sourceEndsMap;
	this.nodesToCategories = nodesToCategoriesMap;

	try {
		// range check
		boolean isInRange =
					this.initialPosition <= parsedUnit.sourceStart
					&& this.eofPosition >= parsedUnit.sourceEnd;

		// collect the top level ast nodes
		int length = 0;
		ASTNode[] nodes = null;
		if (isInRange) {
			this.requestor.enterCompilationUnit();
		}
		ImportReference currentPackage = parsedUnit.currentPackage;
		if (this.localDeclarationVisitor !=  null) {
			this.localDeclarationVisitor.currentPackage = currentPackage;
		}
		ImportReference[] imports = parsedUnit.imports;
		TypeDeclaration[] types = parsedUnit.types;
		length =
			(currentPackage == null ? 0 : 1)
			+ (imports == null ? 0 : imports.length)
			+ (types == null ? 0 : types.length);
		nodes = new ASTNode[length];
		int index = 0;
		if (currentPackage != null) {
			nodes[index++] = currentPackage;
		}
		if (imports != null) {
			for (int i = 0, max = imports.length; i < max; i++) {
				nodes[index++] = imports[i];
			}
		}
		if (types != null) {
			for (int i = 0, max = types.length; i < max; i++) {
				nodes[index++] = types[i];
			}
		}

		// notify the nodes in the syntactical order
		if (length > 0) {
			quickSort(nodes, 0, length-1);
			for (int i=0;i<length;i++) {
				ASTNode node = nodes[i];
				if (node instanceof ImportReference) {
					ImportReference importRef = (ImportReference)node;
					if (node == parsedUnit.currentPackage) {
						notifySourceElementRequestor(importRef, true);
					} else {
						notifySourceElementRequestor(importRef, false);
					}
				} else { // instanceof TypeDeclaration
					notifySourceElementRequestor((TypeDeclaration)node, true, null, currentPackage);
				}
			}
		}

		if (isInRange) {
			this.requestor.exitCompilationUnit(parsedUnit.sourceEnd);
		}
	} finally {
		reset();
	}
}
 
Example #27
Source File: SelectionParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected void consumeStaticImportOnDemandDeclarationName() {
	// TypeImportOnDemandDeclarationName ::= 'import' 'static' Name '.' '*'
	/* push an ImportRef build from the last name
	stored in the identifier stack. */

	int index;

	/* no need to take action if not inside assist identifiers */
	if ((index = indexOfAssistIdentifier()) < 0) {
		super.consumeStaticImportOnDemandDeclarationName();
		return;
	}
	/* retrieve identifiers subset and whole positions, the assist node positions
		should include the entire replaced source. */
	int length = this.identifierLengthStack[this.identifierLengthPtr];
	char[][] subset = identifierSubSet(index+1); // include the assistIdentifier
	this.identifierLengthPtr--;
	this.identifierPtr -= length;
	long[] positions = new long[length];
	System.arraycopy(
		this.identifierPositionStack,
		this.identifierPtr + 1,
		positions,
		0,
		length);

	/* build specific assist node on import statement */
	ImportReference reference = createAssistImportReference(subset, positions, ClassFileConstants.AccStatic);
	reference.bits |= ASTNode.OnDemand;
	// star end position
	reference.trailingStarPosition = this.intStack[this.intPtr--];
	this.assistNode = reference;
	this.lastCheckPoint = reference.sourceEnd + 1;

	pushOnAstStack(reference);

	if (this.currentToken == TokenNameSEMICOLON){
		reference.declarationSourceEnd = this.scanner.currentPosition - 1;
	} else {
		reference.declarationSourceEnd = (int) positions[length-1];
	}
	//endPosition is just before the ;
	reference.declarationSourceStart = this.intStack[this.intPtr--];
	// flush annotations defined prior to import statements
	reference.declarationSourceEnd = flushCommentsDefinedPriorTo(reference.declarationSourceEnd);

	// recovery
	if (this.currentElement != null){
		this.lastCheckPoint = reference.declarationSourceEnd+1;
		this.currentElement = this.currentElement.add(reference, 0);
		this.lastIgnoredToken = -1;
		this.restartRecovery = true; // used to avoid branching back into the regular automaton
	}
}
 
Example #28
Source File: SourceElementRequestorAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see ISourceElementRequestor#acceptPackage(ImportReference)
 */
public void acceptPackage(ImportReference importReference) {
	// default implementation: do nothing
}
 
Example #29
Source File: SimpleDOMBuilder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void acceptPackage(ImportReference importReference) {
	int[] sourceRange= new int[] {importReference.declarationSourceStart, importReference.declarationSourceEnd};
	char[] name = CharOperation.concatWith(importReference.getImportName(), '.');
	this.fNode= new DOMPackage(this.fDocument, sourceRange, new String(name));
	addChild(this.fNode);
}
 
Example #30
Source File: AssistParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected void consumeTypeImportOnDemandDeclarationName() {
	// TypeImportOnDemandDeclarationName ::= 'import' Name '.' '*'
	/* push an ImportRef build from the last name
	stored in the identifier stack. */

	int index;

	/* no need to take action if not inside assist identifiers */
	if ((index = indexOfAssistIdentifier()) < 0) {
		super.consumeTypeImportOnDemandDeclarationName();
		return;
	}
	/* retrieve identifiers subset and whole positions, the assist node positions
		should include the entire replaced source. */
	int length = this.identifierLengthStack[this.identifierLengthPtr];
	char[][] subset = identifierSubSet(index+1); // include the assistIdentifier
	this.identifierLengthPtr--;
	this.identifierPtr -= length;
	long[] positions = new long[length];
	System.arraycopy(
		this.identifierPositionStack,
		this.identifierPtr + 1,
		positions,
		0,
		length);

	/* build specific assist node on import statement */
	ImportReference reference = createAssistImportReference(subset, positions, ClassFileConstants.AccDefault);
	reference.bits |= ASTNode.OnDemand;
	// star end position
	reference.trailingStarPosition = this.intStack[this.intPtr--];
	this.assistNode = reference;
	this.lastCheckPoint = reference.sourceEnd + 1;

	pushOnAstStack(reference);

	if (this.currentToken == TokenNameSEMICOLON){
		reference.declarationSourceEnd = this.scanner.currentPosition - 1;
	} else {
		reference.declarationSourceEnd = (int) positions[length-1];
	}
	//endPosition is just before the ;
	reference.declarationSourceStart = this.intStack[this.intPtr--];
	// flush comments defined prior to import statements
	reference.declarationSourceEnd = flushCommentsDefinedPriorTo(reference.declarationSourceEnd);

	// recovery
	if (this.currentElement != null){
		this.lastCheckPoint = reference.declarationSourceEnd+1;
		this.currentElement = this.currentElement.add(reference, 0);
		this.lastIgnoredToken = -1;
		this.restartRecovery = true; // used to avoid branching back into the regular automaton
	}
}