use of org.eclipse.jdt.core.dom.IMethodBinding in project flux by eclipse.
the class Bindings method findMethodInHierarchy.
/**
* Finds the method specified by <code>methodName</code> and <code>parameters</code> in
* the type hierarchy denoted by the given type. Returns <code>null</code> if no such method
* exists. If the method is defined in more than one super type only the first match is
* returned. First the super class is examined and then the implemented interfaces.
* @param type the type to search the method in
* @param methodName The name of the method to find
* @param parameters The parameter types of the method to find. If <code>null</code> is passed, only the name is matched and parameters are ignored.
* @return the method binding representing the method
*/
public static IMethodBinding findMethodInHierarchy(ITypeBinding type, String methodName, String[] parameters) {
IMethodBinding method = findMethodInType(type, methodName, parameters);
if (method != null)
return method;
ITypeBinding superClass = type.getSuperclass();
if (superClass != null) {
method = findMethodInHierarchy(superClass, methodName, parameters);
if (method != null)
return method;
}
ITypeBinding[] interfaces = type.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
method = findMethodInHierarchy(interfaces[i], methodName, parameters);
if (method != null)
return method;
}
return null;
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class SourceAnalyzer method checkActivation.
public RefactoringStatus checkActivation() throws JavaModelException {
RefactoringStatus result = new RefactoringStatus();
if (!fTypeRoot.isStructureKnown()) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_syntax_errors, JavaStatusContext.create(fTypeRoot));
return result;
}
IProblem[] problems = ASTNodes.getProblems(fDeclaration, ASTNodes.NODE_ONLY, ASTNodes.ERROR);
if (problems.length > 0) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_declaration_has_errors, JavaStatusContext.create(fTypeRoot, fDeclaration));
return result;
}
final IMethodBinding declarationBinding = fDeclaration.resolveBinding();
if (declarationBinding != null) {
final int modifiers = declarationBinding.getModifiers();
if (Modifier.isAbstract(modifiers)) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_abstract_methods, JavaStatusContext.create(fTypeRoot, fDeclaration));
return result;
} else if (Modifier.isNative(modifiers)) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_native_methods, JavaStatusContext.create(fTypeRoot, fDeclaration));
return result;
}
} else {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_methoddeclaration_has_errors, JavaStatusContext.create(fTypeRoot));
return result;
}
ActivationAnalyzer analyzer = new ActivationAnalyzer();
fDeclaration.accept(analyzer);
result.merge(analyzer.status);
if (!result.hasFatalError()) {
List<SingleVariableDeclaration> parameters = fDeclaration.parameters();
fParameters = new HashMap<IVariableBinding, ParameterData>(parameters.size() * 2);
for (Iterator<SingleVariableDeclaration> iter = parameters.iterator(); iter.hasNext(); ) {
SingleVariableDeclaration element = iter.next();
IVariableBinding binding = element.resolveBinding();
if (binding == null) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_declaration_has_errors, JavaStatusContext.create(fTypeRoot, fDeclaration));
return result;
}
fParameters.put(binding, (ParameterData) element.getProperty(ParameterData.PROPERTY));
}
fNames = new HashMap<IBinding, NameData>();
fImplicitReceivers = new ArrayList<Expression>(2);
fTypeParameterReferences = new ArrayList<NameData>(0);
fTypeParameterMapping = new HashMap<ITypeBinding, NameData>();
ITypeBinding declaringType = declarationBinding.getDeclaringClass();
if (declaringType == null) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_typedeclaration_has_errors, JavaStatusContext.create(fTypeRoot));
return result;
}
ITypeBinding[] typeParameters = declaringType.getTypeParameters();
for (int i = 0; i < typeParameters.length; i++) {
NameData data = new NameData(typeParameters[i].getName());
fTypeParameterReferences.add(data);
fTypeParameterMapping.put(typeParameters[i], data);
}
fMethodTypeParameterReferences = new ArrayList<NameData>(0);
fMethodTypeParameterMapping = new HashMap<ITypeBinding, NameData>();
IMethodBinding method = declarationBinding;
typeParameters = method.getTypeParameters();
for (int i = 0; i < typeParameters.length; i++) {
NameData data = new NameData(typeParameters[i].getName());
fMethodTypeParameterReferences.add(data);
fMethodTypeParameterMapping.put(typeParameters[i], data);
}
}
if (fDeclaration.isVarargs()) {
List<SingleVariableDeclaration> parameters = fDeclaration.parameters();
VarargAnalyzer vAnalyzer = new VarargAnalyzer(parameters.get(parameters.size() - 1).getName().resolveBinding());
fDeclaration.getBody().accept(vAnalyzer);
}
return result;
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class SourceProvider method updateImplicitReceivers.
private void updateImplicitReceivers(ASTRewrite rewriter, CallContext context) {
if (context.receiver == null)
return;
List<Expression> implicitReceivers = fAnalyzer.getImplicitReceivers();
for (Iterator<Expression> iter = implicitReceivers.iterator(); iter.hasNext(); ) {
ASTNode node = iter.next();
ImportRewriteContext importRewriteContext = new ContextSensitiveImportRewriteContext(node, context.importer);
if (node instanceof MethodInvocation) {
final MethodInvocation inv = (MethodInvocation) node;
rewriter.set(inv, MethodInvocation.EXPRESSION_PROPERTY, createReceiver(rewriter, context, (IMethodBinding) inv.getName().resolveBinding(), importRewriteContext), null);
} else if (node instanceof ClassInstanceCreation) {
final ClassInstanceCreation inst = (ClassInstanceCreation) node;
rewriter.set(inst, ClassInstanceCreation.EXPRESSION_PROPERTY, createReceiver(rewriter, context, inst.resolveConstructorBinding(), importRewriteContext), null);
} else if (node instanceof ThisExpression) {
rewriter.replace(node, rewriter.createStringPlaceholder(context.receiver, ASTNode.METHOD_INVOCATION), null);
} else if (node instanceof FieldAccess) {
final FieldAccess access = (FieldAccess) node;
rewriter.set(access, FieldAccess.EXPRESSION_PROPERTY, createReceiver(rewriter, context, access.resolveFieldBinding(), importRewriteContext), null);
} else if (node instanceof SimpleName && ((SimpleName) node).resolveBinding() instanceof IVariableBinding) {
IVariableBinding vb = (IVariableBinding) ((SimpleName) node).resolveBinding();
if (vb.isField()) {
Expression receiver = createReceiver(rewriter, context, vb, importRewriteContext);
if (receiver != null) {
FieldAccess access = node.getAST().newFieldAccess();
ASTNode target = rewriter.createMoveTarget(node);
access.setName((SimpleName) target);
access.setExpression(receiver);
rewriter.replace(node, access, null);
}
}
}
}
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class TargetProvider method create.
public static TargetProvider create(MethodDeclaration declaration) {
IMethodBinding method = declaration.resolveBinding();
if (method == null)
return new ErrorTargetProvider(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.TargetProvider_method_declaration_not_unique));
ITypeBinding type = method.getDeclaringClass();
if (type.isLocal()) {
if (((IType) type.getJavaElement()).isBinary()) {
return new ErrorTargetProvider(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.TargetProvider_cannot_local_method_in_binary));
} else {
IType declaringClassOfLocal = (IType) type.getDeclaringClass().getJavaElement();
return new LocalTypeTargetProvider(declaringClassOfLocal.getCompilationUnit(), declaration);
}
} else {
return new MemberTypeTargetProvider(declaration.resolveBinding());
}
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class PromoteTempToFieldRefactoring method checkTempInitializerForLocalTypeUsage.
private void checkTempInitializerForLocalTypeUsage() {
Expression initializer = fTempDeclarationNode.getInitializer();
if (initializer == null)
return;
IMethodBinding declaringMethodBinding = getMethodDeclaration().resolveBinding();
ITypeBinding[] methodTypeParameters = declaringMethodBinding == null ? new ITypeBinding[0] : declaringMethodBinding.getTypeParameters();
LocalTypeAndVariableUsageAnalyzer localTypeAnalyer = new LocalTypeAndVariableUsageAnalyzer(methodTypeParameters);
initializer.accept(localTypeAnalyer);
fInitializerUsesLocalTypes = !localTypeAnalyer.getUsageOfEnclosingNodes().isEmpty();
}
Aggregations