use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class ExtractMethodAnalyzer method initReturnType.
private void initReturnType(ImportRewrite rewriter) {
AST ast = fEnclosingBodyDeclaration.getAST();
fReturnType = null;
fReturnTypeBinding = null;
switch(fReturnKind) {
case ACCESS_TO_LOCAL:
VariableDeclaration declaration = ASTNodes.findVariableDeclaration(fReturnValue, fEnclosingBodyDeclaration);
fReturnType = ASTNodeFactory.newType(ast, declaration, rewriter, new ContextSensitiveImportRewriteContext(declaration, rewriter));
if (declaration.resolveBinding() != null) {
fReturnTypeBinding = declaration.resolveBinding().getType();
}
break;
case EXPRESSION:
Expression expression = (Expression) getFirstSelectedNode();
if (expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) {
fExpressionBinding = ((ClassInstanceCreation) expression).getType().resolveBinding();
} else {
fExpressionBinding = expression.resolveTypeBinding();
}
if (fExpressionBinding != null) {
if (fExpressionBinding.isNullType()) {
getStatus().addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_null_type, JavaStatusContext.create(fCUnit, expression));
} else {
ITypeBinding normalizedBinding = Bindings.normalizeForDeclarationUse(fExpressionBinding, ast);
if (normalizedBinding != null) {
ImportRewriteContext context = new ContextSensitiveImportRewriteContext(fEnclosingBodyDeclaration, rewriter);
fReturnType = rewriter.addImport(normalizedBinding, ast, context);
fReturnTypeBinding = normalizedBinding;
}
}
} else {
fReturnType = ast.newPrimitiveType(PrimitiveType.VOID);
//$NON-NLS-1$
fReturnTypeBinding = ast.resolveWellKnownType("void");
getStatus().addError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_determine_return_type, JavaStatusContext.create(fCUnit, expression));
}
break;
case RETURN_STATEMENT_VALUE:
LambdaExpression enclosingLambdaExpr = ASTResolving.findEnclosingLambdaExpression(getFirstSelectedNode());
if (enclosingLambdaExpr != null) {
fReturnType = ASTNodeFactory.newReturnType(enclosingLambdaExpr, ast, rewriter, null);
IMethodBinding methodBinding = enclosingLambdaExpr.resolveMethodBinding();
fReturnTypeBinding = methodBinding != null ? methodBinding.getReturnType() : null;
} else if (fEnclosingBodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION) {
fReturnType = ((MethodDeclaration) fEnclosingBodyDeclaration).getReturnType2();
fReturnTypeBinding = fReturnType != null ? fReturnType.resolveBinding() : null;
}
break;
default:
fReturnType = ast.newPrimitiveType(PrimitiveType.VOID);
//$NON-NLS-1$
fReturnTypeBinding = ast.resolveWellKnownType("void");
}
if (fReturnType == null) {
fReturnType = ast.newPrimitiveType(PrimitiveType.VOID);
//$NON-NLS-1$
fReturnTypeBinding = ast.resolveWellKnownType("void");
}
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class InlineMethodRefactoring method resolveSourceProvider.
private static SourceProvider resolveSourceProvider(RefactoringStatus status, ITypeRoot typeRoot, ASTNode invocation) {
CompilationUnit root = (CompilationUnit) invocation.getRoot();
IMethodBinding methodBinding = Invocations.resolveBinding(invocation);
if (methodBinding == null) {
status.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration);
return null;
}
MethodDeclaration declaration = (MethodDeclaration) root.findDeclaringNode(methodBinding);
if (declaration != null) {
return new SourceProvider(typeRoot, declaration);
}
IMethod method = (IMethod) methodBinding.getJavaElement();
if (method != null) {
CompilationUnit methodDeclarationAstRoot;
ICompilationUnit methodCu = method.getCompilationUnit();
if (methodCu != null) {
methodDeclarationAstRoot = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(methodCu, true);
} else {
IClassFile classFile = method.getClassFile();
if (!JavaElementUtil.isSourceAvailable(classFile)) {
String methodLabel = JavaElementLabels.getTextLabel(method, JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.M_PARAMETER_TYPES);
status.addFatalError(Messages.format(RefactoringCoreMessages.InlineMethodRefactoring_error_classFile, methodLabel));
return null;
}
methodDeclarationAstRoot = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(classFile, true);
}
ASTNode node = methodDeclarationAstRoot.findDeclaringNode(methodBinding.getMethodDeclaration().getKey());
if (node instanceof MethodDeclaration) {
return new SourceProvider(methodDeclarationAstRoot.getTypeRoot(), (MethodDeclaration) node);
}
}
status.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration);
return null;
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class Invocations method getInferredTypeArguments.
public static ITypeBinding[] getInferredTypeArguments(Expression invocation) {
IMethodBinding methodBinding;
switch(invocation.getNodeType()) {
case ASTNode.METHOD_INVOCATION:
methodBinding = ((MethodInvocation) invocation).resolveMethodBinding();
return methodBinding == null ? null : methodBinding.getTypeArguments();
case ASTNode.SUPER_METHOD_INVOCATION:
methodBinding = ((SuperMethodInvocation) invocation).resolveMethodBinding();
return methodBinding == null ? null : methodBinding.getTypeArguments();
case ASTNode.CLASS_INSTANCE_CREATION:
Type type = ((ClassInstanceCreation) invocation).getType();
ITypeBinding typeBinding = type.resolveBinding();
return typeBinding == null ? null : typeBinding.getTypeArguments();
default:
throw new IllegalArgumentException(invocation.toString());
}
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project AutoRefactor by JnRouvignac.
the class AnnotationRefactoring method toElementsMap.
private Map<String, IMethodBinding> toElementsMap(IAnnotationBinding annotBinding) {
if (annotBinding == null) {
return Collections.emptyMap();
}
ITypeBinding annotationType = annotBinding.getAnnotationType();
IMethodBinding[] elements = annotationType.getDeclaredMethods();
Map<String, IMethodBinding> results = new HashMap<String, IMethodBinding>();
for (IMethodBinding element : elements) {
results.put(element.getName(), element);
}
return results;
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project AutoRefactor by JnRouvignac.
the class RemoveUnneededThisExpressionRefactoring method isCallingMethodDeclaredInEnclosingType.
private boolean isCallingMethodDeclaredInEnclosingType(MethodInvocation node) {
final ASTNode currentType = getEnclosingType(node);
final IMethodBinding mb = node.resolveMethodBinding();
if (currentType instanceof AnonymousClassDeclaration) {
final AnonymousClassDeclaration c = (AnonymousClassDeclaration) currentType;
final ITypeBinding enclosingTypeBinding = c.resolveBinding();
return enclosingTypeBinding.isSubTypeCompatible(mb.getDeclaringClass());
} else if (currentType instanceof AbstractTypeDeclaration) {
final AbstractTypeDeclaration ed = (AbstractTypeDeclaration) currentType;
final ITypeBinding enclosingTypeBinding = ed.resolveBinding();
return enclosingTypeBinding.isSubTypeCompatible(mb.getDeclaringClass());
}
throw new NotImplementedException(node, node);
}
Aggregations