use of org.eclipse.jdt.core.dom.IBinding in project flux by eclipse.
the class ScopeAnalyzer method getDeclarationsInScope.
public IBinding[] getDeclarationsInScope(int offset, int flags) {
org.eclipse.jdt.core.dom.NodeFinder finder = new org.eclipse.jdt.core.dom.NodeFinder(fRoot, offset, 0);
ASTNode node = finder.getCoveringNode();
if (node == null) {
return NO_BINDING;
}
if (node instanceof SimpleName) {
return getDeclarationsInScope((SimpleName) node, flags);
}
try {
ITypeBinding binding = Bindings.getBindingOfParentType(node);
DefaultBindingRequestor requestor = new DefaultBindingRequestor(binding, flags);
addLocalDeclarations(node, offset, flags, requestor);
if (binding != null) {
addTypeDeclarations(binding, flags, requestor);
}
List<IBinding> result = requestor.getResult();
return result.toArray(new IBinding[result.size()]);
} finally {
clearLists();
}
}
use of org.eclipse.jdt.core.dom.IBinding in project flux by eclipse.
the class ImportReferencesCollector method possibleStaticImportFound.
private void possibleStaticImportFound(Name name) {
if (fStaticImports == null || fASTRoot == null) {
return;
}
while (name.isQualifiedName()) {
name = ((QualifiedName) name).getQualifier();
}
if (!isAffected(name)) {
return;
}
IBinding binding = name.resolveBinding();
SimpleName simpleName = (SimpleName) name;
if (binding == null || binding instanceof ITypeBinding || !Modifier.isStatic(binding.getModifiers()) || simpleName.isDeclaration()) {
return;
}
if (binding instanceof IVariableBinding) {
IVariableBinding varBinding = (IVariableBinding) binding;
if (varBinding.isField()) {
varBinding = varBinding.getVariableDeclaration();
ITypeBinding declaringClass = varBinding.getDeclaringClass();
if (declaringClass != null && !declaringClass.isLocal()) {
if (new ScopeAnalyzer(fASTRoot).isDeclaredInScope(varBinding, simpleName, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY))
return;
fStaticImports.add(simpleName);
}
}
} else if (binding instanceof IMethodBinding) {
IMethodBinding methodBinding = ((IMethodBinding) binding).getMethodDeclaration();
ITypeBinding declaringClass = methodBinding.getDeclaringClass();
if (declaringClass != null && !declaringClass.isLocal()) {
if (new ScopeAnalyzer(fASTRoot).isDeclaredInScope(methodBinding, simpleName, ScopeAnalyzer.METHODS | ScopeAnalyzer.CHECK_VISIBILITY))
return;
fStaticImports.add(simpleName);
}
}
}
use of org.eclipse.jdt.core.dom.IBinding in project flux by eclipse.
the class StubUtility method getParameterTypeNamesForSeeTag.
/*
* Returns the parameters type names used in see tags. Currently, these are always fully qualified.
*/
private static String[] getParameterTypeNamesForSeeTag(IMethod overridden) {
try {
ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setProject(overridden.getJavaProject());
IBinding[] bindings = parser.createBindings(new IJavaElement[] { overridden }, null);
if (bindings.length == 1 && bindings[0] instanceof IMethodBinding) {
return getParameterTypeNamesForSeeTag((IMethodBinding) bindings[0]);
}
} catch (IllegalStateException e) {
// method does not exist
}
// fall back code. Not good for generic methods!
String[] paramTypes = overridden.getParameterTypes();
String[] paramTypeNames = new String[paramTypes.length];
for (int i = 0; i < paramTypes.length; i++) {
paramTypeNames[i] = Signature.toString(Signature.getTypeErasure(paramTypes[i]));
}
return paramTypeNames;
}
use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method endVisit.
@Override
public void endVisit(SimpleName node) {
if (node.resolveBoxing()) {
ImmutableTypeVariable2 boxed = fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
setConstraintVariable(node, boxed);
return;
}
IBinding binding = node.resolveBinding();
if (binding instanceof IVariableBinding) {
//TODO: code is similar to handling of method return value
IVariableBinding variableBinding = (IVariableBinding) binding;
ITypeBinding declaredVariableType = variableBinding.getVariableDeclaration().getType();
if (declaredVariableType.isTypeVariable()) {
Expression receiver = getSimpleNameReceiver(node);
if (receiver != null) {
ConstraintVariable2 receiverCv = getConstraintVariable(receiver);
// the type variable must come from the receiver!
Assert.isNotNull(receiverCv);
ConstraintVariable2 elementCv = fTCModel.getElementVariable(receiverCv, declaredVariableType);
// [retVal] =^= Elem[receiver]:
setConstraintVariable(node, elementCv);
return;
}
} else if (declaredVariableType.isParameterizedType()) {
Expression receiver = getSimpleNameReceiver(node);
if (receiver != null) {
ConstraintVariable2 receiverCv = getConstraintVariable(receiver);
if (receiverCv != null) {
// ITypeBinding genericVariableType= declaredVariableType.getTypeDeclaration();
ConstraintVariable2 returnTypeCv = fTCModel.makeParameterizedTypeVariable(declaredVariableType);
setConstraintVariable(node, returnTypeCv);
// Elem[retVal] =^= Elem[receiver]
TType declaredVariableTType = fTCModel.createTType(declaredVariableType);
fTCModel.createTypeVariablesEqualityConstraints(receiverCv, Collections.<String, IndependentTypeVariable2>emptyMap(), returnTypeCv, declaredVariableTType);
return;
}
}
} else {
//TODO: array...
//logUnexpectedNode(node, null);
}
// default:
VariableVariable2 cv = fTCModel.makeVariableVariable(variableBinding);
setConstraintVariable(node, cv);
}
// TODO else?
}
use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class IntroduceIndirectionRefactoring method checkInitialConditions.
// ********** CONDITION CHECKING **********
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
try {
pm.beginTask(RefactoringCoreMessages.IntroduceIndirectionRefactoring_checking_activation, 1);
fRewrites = new HashMap<ICompilationUnit, CompilationUnitRewrite>();
if (fTargetMethod == null) {
if (fSelectionStart == 0)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_not_available_on_this_selection);
// if a text selection exists, source is available.
CompilationUnit selectionCURoot;
ASTNode selectionNode;
if (fSelectionCompilationUnit != null) {
// compilation unit - could use CuRewrite later on
selectionCURoot = getCachedCURewrite(fSelectionCompilationUnit).getRoot();
selectionNode = getSelectedNode(fSelectionCompilationUnit, selectionCURoot, fSelectionStart, fSelectionLength);
} else {
// binary class file - no cu rewrite
ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setResolveBindings(true);
parser.setSource(fSelectionClassFile);
selectionCURoot = (CompilationUnit) parser.createAST(null);
selectionNode = getSelectedNode(null, selectionCURoot, fSelectionStart, fSelectionLength);
}
if (selectionNode == null)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_not_available_on_this_selection);
IMethodBinding targetMethodBinding = null;
if (selectionNode.getNodeType() == ASTNode.METHOD_INVOCATION) {
targetMethodBinding = ((MethodInvocation) selectionNode).resolveMethodBinding();
} else if (selectionNode.getNodeType() == ASTNode.METHOD_DECLARATION) {
targetMethodBinding = ((MethodDeclaration) selectionNode).resolveBinding();
} else if (selectionNode.getNodeType() == ASTNode.SUPER_METHOD_INVOCATION) {
// Allow invocation on super methods calls. makes sense as other
// calls or even only the declaration can be updated.
targetMethodBinding = ((SuperMethodInvocation) selectionNode).resolveMethodBinding();
} else {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_not_available_on_this_selection);
}
// resolve generics
fTargetMethodBinding = targetMethodBinding.getMethodDeclaration();
fTargetMethod = (IMethod) fTargetMethodBinding.getJavaElement();
//allow single updating mode if an invocation was selected and the invocation can be updated
if (selectionNode instanceof MethodInvocation && fSelectionCompilationUnit != null)
fSelectionMethodInvocation = (MethodInvocation) selectionNode;
} else {
if (fTargetMethod.getDeclaringType().isAnnotation())
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_not_available_on_annotation);
if (fTargetMethod.getCompilationUnit() != null) {
// source method
CompilationUnit selectionCURoot = getCachedCURewrite(fTargetMethod.getCompilationUnit()).getRoot();
MethodDeclaration declaration = ASTNodeSearchUtil.getMethodDeclarationNode(fTargetMethod, selectionCURoot);
fTargetMethodBinding = declaration.resolveBinding().getMethodDeclaration();
} else {
// binary method - no CURewrite available (and none needed as we cannot update the method anyway)
ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setProject(fTargetMethod.getJavaProject());
IBinding[] bindings = parser.createBindings(new IJavaElement[] { fTargetMethod }, null);
fTargetMethodBinding = ((IMethodBinding) bindings[0]).getMethodDeclaration();
}
}
if (fTargetMethod == null || fTargetMethodBinding == null || (!RefactoringAvailabilityTester.isIntroduceIndirectionAvailable(fTargetMethod)))
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_not_available_on_this_selection);
if (fTargetMethod.getDeclaringType().isLocal() || fTargetMethod.getDeclaringType().isAnonymous())
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_not_available_for_local_or_anonymous_types);
if (fTargetMethod.isConstructor())
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_not_available_for_constructors);
if (fIntermediaryMethodName == null)
fIntermediaryMethodName = fTargetMethod.getElementName();
if (fIntermediaryType == null) {
if (fSelectionCompilationUnit != null && !fSelectionCompilationUnit.isReadOnly())
fIntermediaryType = getEnclosingInitialSelectionMember().getDeclaringType();
else if (!fTargetMethod.isBinary() && !fTargetMethod.isReadOnly())
fIntermediaryType = fTargetMethod.getDeclaringType();
}
return new RefactoringStatus();
} finally {
pm.done();
}
}
Aggregations