org.eclipse.jdt.internal.compiler.lookup.ClassScope Java Examples

The following examples show how to use org.eclipse.jdt.internal.compiler.lookup.ClassScope. 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: CompletionOnJavadocFieldReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected TypeBinding internalResolveType(Scope scope) {

		if (this.token != null) {
			return super.internalResolveType(scope);
		}

		// Resolve only receiver
		if (this.receiver == null) {
			this.actualReceiverType = scope.enclosingSourceType();
		} else if (scope.kind == Scope.CLASS_SCOPE) {
			this.actualReceiverType = this.receiver.resolveType((ClassScope) scope);
		} else {
			this.actualReceiverType = this.receiver.resolveType((BlockScope)scope);
		}
		return null;
	}
 
Example #2
Source File: Extractor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean visit(Argument argument, BlockScope scope) {
    Annotation[] annotations = argument.annotations;
    if (hasRelevantAnnotations(annotations)) {
        ReferenceContext referenceContext = scope.referenceContext();
        if (referenceContext instanceof AbstractMethodDeclaration) {
            MethodBinding binding = ((AbstractMethodDeclaration) referenceContext).binding;
            ClassScope classScope = findClassScope(scope);
            if (classScope == null) {
                return false;
            }
            String fqn = getFqn(classScope);
            ClassKind kind = ClassKind.forType(classScope.referenceContext);
            Item item = ParameterItem.create(
                    (AbstractMethodDeclaration) referenceContext, argument, fqn, kind,
                    binding, argument.binding);
            if (item != null) {
                addItem(fqn, item);
                addAnnotations(annotations, item);
            }
        }
    }
    return false;
}
 
Example #3
Source File: Extractor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope scope) {
    Annotation[] annotations = constructorDeclaration.annotations;
    if (hasRelevantAnnotations(annotations)) {
        MethodBinding constructorBinding = constructorDeclaration.binding;
        if (constructorBinding == null) {
            return false;
        }

        String fqn = getFqn(scope);
        ClassKind kind = ClassKind.forType(scope.referenceContext);
        Item item = MethodItem.create(fqn, kind, constructorDeclaration, constructorBinding);
        if (item != null) {
            addItem(fqn, item);
            addAnnotations(annotations, item);
        }
    }

    Argument[] arguments = constructorDeclaration.arguments;
    if (arguments != null) {
        for (Argument argument : arguments) {
            argument.traverse(this, constructorDeclaration.scope);
        }
    }
    return false;
}
 
Example #4
Source File: PatchExtensionMethodCompletionProposal.java    From EasyMPermission with MIT License 6 votes vote down vote up
private static ClassScope getClassScope(CompletionProposalCollector completionProposalCollector) {
	ClassScope scope = null;
	try {
		InternalCompletionContext context = (InternalCompletionContext) Reflection.contextField.get(completionProposalCollector);
		InternalExtendedCompletionContext extendedContext = (InternalExtendedCompletionContext) Reflection.extendedContextField.get(context);
		if (extendedContext != null) {
			Scope assistScope = ((Scope) Reflection.assistScopeField.get(extendedContext));
			if (assistScope != null) {
				scope = assistScope.classScope();
			}
		}
	} catch (IllegalAccessException ignore) {
		// ignore
	}
	return scope;
}
 
Example #5
Source File: InternalExtendedCompletionContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean canUseDiamond(String[] parameterTypes, char[] fullyQualifiedTypeName) {
	TypeBinding guessedType = null;
	char[][] cn = CharOperation.splitOn('.', fullyQualifiedTypeName);
	Scope scope = this.assistScope;
	if (scope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_7) return false;
	// If no LHS or return type expected, then we can safely use diamond
	char[][] expectedTypekeys= this.completionContext.getExpectedTypesKeys();
	if (expectedTypekeys == null || expectedTypekeys.length == 0)
		return true;
	// Next, find out whether any of the constructor parameters are the same as one of the 
	// class type variables. If yes, diamond cannot be used.
	TypeReference ref;
	if (cn.length == 1) {
		ref = new SingleTypeReference(cn[0], 0);
	} else {
		ref = new QualifiedTypeReference(cn,new long[cn.length]);
	}
	switch (scope.kind) {
		case Scope.METHOD_SCOPE :
		case Scope.BLOCK_SCOPE :
			guessedType = ref.resolveType((BlockScope)scope);
			break;
		case Scope.CLASS_SCOPE :
			guessedType = ref.resolveType((ClassScope)scope);
			break;
	}
	if (guessedType != null && guessedType.isValidBinding()) {
		// the erasure must be used because guessedType can be a RawTypeBinding
		guessedType = guessedType.erasure();
		TypeVariableBinding[] typeVars = guessedType.typeVariables();
		for (int i = 0; i < parameterTypes.length; i++) {
			for (int j = 0; j < typeVars.length; j++) {
				if (CharOperation.equals(parameterTypes[i].toCharArray(), typeVars[j].sourceName))
					return false;
			}
		}
		return true;
	}
	return false;
}
 
Example #6
Source File: Extractor.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private static String getFqn(@NonNull ClassScope scope) {
    TypeDeclaration typeDeclaration = scope.referenceType();
    if (typeDeclaration != null && typeDeclaration.binding != null) {
        return new String(typeDeclaration.binding.readableName());
    }
    return null;
}
 
Example #7
Source File: Extractor.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private static String getFqn(@NonNull MethodScope scope) {
    ClassScope classScope = findClassScope(scope);
    if (classScope != null) {
        return getFqn(classScope);
    }

    return null;
}
 
Example #8
Source File: CodeSnippetSingleNameReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check and/or redirect the field access to the delegate receiver if any
 */
public TypeBinding getReceiverType(BlockScope currentScope) {
	Scope scope = currentScope.parent;
	while (true) {
			switch (scope.kind) {
				case Scope.CLASS_SCOPE :
					return ((ClassScope) scope).referenceContext.binding;
				default:
					scope = scope.parent;
			}
	}
}
 
Example #9
Source File: LambdaExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void generateCode(ClassScope classScope, ClassFile classFile) {
	int problemResetPC = 0;
	classFile.codeStream.wideMode = false;
	boolean restart = false;
	do {
		try {
			problemResetPC = classFile.contentsOffset;
			this.generateCode(classFile);
			restart = false;
		} catch (AbortMethod e) {
			// Restart code generation if possible ...
			if (e.compilationResult == CodeStream.RESTART_IN_WIDE_MODE) {
				// a branch target required a goto_w, restart code generation in wide mode.
				classFile.contentsOffset = problemResetPC;
				classFile.methodCount--;
				classFile.codeStream.resetInWideMode(); // request wide mode
				restart = true;
			} else if (e.compilationResult == CodeStream.RESTART_CODE_GEN_FOR_UNUSED_LOCALS_MODE) {
				classFile.contentsOffset = problemResetPC;
				classFile.methodCount--;
				classFile.codeStream.resetForCodeGenUnusedLocals();
				restart = true;
			} else {
				throw new AbortType(this.compilationResult, e.problem);
			}
		}
	} while (restart);
}
 
Example #10
Source File: UnresolvedReferenceNameFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean visit(MethodDeclaration methodDeclaration, ClassScope classScope) {
	removeLocals(
			methodDeclaration.arguments,
			methodDeclaration.declarationSourceStart,
			methodDeclaration.declarationSourceEnd);
	removeLocals(
			methodDeclaration.statements,
			methodDeclaration.declarationSourceStart,
			methodDeclaration.declarationSourceEnd);
	pushParent(methodDeclaration);
	return true;
}
 
Example #11
Source File: MemberValuePair.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void traverse(ASTVisitor visitor, ClassScope scope) {
	if (visitor.visit(this, scope)) {
		if (this.value != null) {
			this.value.traverse(visitor, scope);
		}
	}
	visitor.endVisit(this, scope);
}
 
Example #12
Source File: UnresolvedReferenceNameFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void findAfter(
		char[] startWith,
		Scope scope,
		ClassScope classScope,
		int from,
		int to,
		char[][] discouragedNames,
		UnresolvedReferenceNameRequestor nameRequestor) {
	MethodDeclaration fakeMethod =
		this.findAfter(startWith, scope, from, to, MAX_LINE_COUNT / 2, true, discouragedNames, nameRequestor);
	if (fakeMethod != null) fakeMethod.traverse(this, classScope);
}
 
Example #13
Source File: NodeSearcher.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean visit(
	MethodDeclaration methodDeclaration,
	ClassScope scope) {

	if (methodDeclaration.declarationSourceStart <= this.position
		&& this.position <= methodDeclaration.declarationSourceEnd) {
			this.found = methodDeclaration;
			return false;
	}
	return true;
}
 
Example #14
Source File: SelectionOnParameterizedQualifiedTypeReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public TypeBinding resolveType(ClassScope scope, int location) {
	super.resolveType(scope, location);
	//// removed unnecessary code to solve bug 94653
	//if(this.resolvedType != null && this.resolvedType.isRawType()) {
	//	ParameterizedTypeBinding parameterizedTypeBinding = scope.createParameterizedType(((RawTypeBinding)this.resolvedType).type, new TypeBinding[0], this.resolvedType.enclosingType());
	//	throw new SelectionNodeFound(parameterizedTypeBinding);
	//}
	throw new SelectionNodeFound(this.resolvedType);
}
 
Example #15
Source File: ASTVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void endVisit(Argument argument,ClassScope scope) {
	// do nothing by default
}
 
Example #16
Source File: SelectionOnParameterizedSingleTypeReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public TypeBinding resolveType(ClassScope scope, int location) {
	super.resolveType(scope, location);
	throw new SelectionNodeFound(this.resolvedType);
}
 
Example #17
Source File: MissingTypesGuesser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void cleanUp(TypeReference convertedType, ClassScope scope) {
	convertedType.traverse(this, scope);
	this.firstCall = false;
}
 
Example #18
Source File: BinaryExpressionFragmentBuilder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean visit(
	ArrayQualifiedTypeReference arrayQualifiedTypeReference,
	ClassScope scope) {
		addRealFragment(arrayQualifiedTypeReference);
		return false;
}
 
Example #19
Source File: ASTVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean visit(FieldReference fieldReference, ClassScope scope) {
	return true; // do nothing by default, keep traversing
}
 
Example #20
Source File: ASTVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void endVisit(
   		QualifiedSuperReference qualifiedSuperReference,
   		ClassScope scope) {
	// do nothing by default
}
 
Example #21
Source File: UnresolvedReferenceNameFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope classScope) {
	removeFields(memberTypeDeclaration);
	pushParent(memberTypeDeclaration);
	return true;
}
 
Example #22
Source File: SingleNameReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void traverse(ASTVisitor visitor, ClassScope scope) {
	visitor.visit(this, scope);
	visitor.endVisit(this, scope);
}
 
Example #23
Source File: ASTVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void endVisit(JavadocMessageSend messageSend, ClassScope scope) {
	// do nothing by default
}
 
Example #24
Source File: ASTVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void endVisit(TypeParameter typeParameter, ClassScope scope) {
	// do nothing by default
}
 
Example #25
Source File: JavadocArraySingleTypeReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void traverse(ASTVisitor visitor, ClassScope scope) {
	visitor.visit(this, scope);
	visitor.endVisit(this, scope);
}
 
Example #26
Source File: ASTVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean visit(
	TypeDeclaration memberTypeDeclaration,
	ClassScope scope) {
	return true; // do nothing by default, keep traversing
}
 
Example #27
Source File: SetGeneratedByVisitor.java    From EasyMPermission with MIT License 4 votes vote down vote up
@Override public boolean visit(Wildcard node, ClassScope scope) {
	fixPositions(setGeneratedBy(node, source));
	return super.visit(node, scope);
}
 
Example #28
Source File: ASTVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean visit(
		SingleNameReference singleNameReference,
		ClassScope scope) {
	return true; // do nothing by default, keep traversing
}
 
Example #29
Source File: SetGeneratedByVisitor.java    From EasyMPermission with MIT License 4 votes vote down vote up
@Override public boolean visit(SingleTypeReference node, ClassScope scope) {
	fixPositions(setGeneratedBy(node, source));
	return super.visit(node, scope);
}
 
Example #30
Source File: SourceElementNotifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean visit(TypeDeclaration typeDeclaration, ClassScope scope) {
	notifySourceElementRequestor(typeDeclaration, true, peekDeclaringType(), this.currentPackage);
	return false; // don't visit members as this was done during notifySourceElementRequestor(...)
}