Search in sources :

Example 26 with IMethodBinding

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;
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) SingleVariableDeclaration(org.eclipse.jdt.core.dom.SingleVariableDeclaration) IBinding(org.eclipse.jdt.core.dom.IBinding) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) IProblem(org.eclipse.jdt.core.compiler.IProblem) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) LambdaExpression(org.eclipse.jdt.core.dom.LambdaExpression) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 27 with IMethodBinding

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);
                }
            }
        }
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ClassInstanceCreation(org.eclipse.jdt.core.dom.ClassInstanceCreation) SimpleName(org.eclipse.jdt.core.dom.SimpleName) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) ContextSensitiveImportRewriteContext(org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext) ImportRewriteContext(org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext) ContextSensitiveImportRewriteContext(org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) ASTNode(org.eclipse.jdt.core.dom.ASTNode) FieldAccess(org.eclipse.jdt.core.dom.FieldAccess)

Example 28 with IMethodBinding

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());
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) IType(org.eclipse.jdt.core.IType)

Example 29 with IMethodBinding

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();
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) Expression(org.eclipse.jdt.core.dom.Expression) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 30 with IMethodBinding

use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.

the class InferTypeArgumentsConstraintCreator method endVisit.

@Override
public void endVisit(ClassInstanceCreation node) {
    Expression receiver = node.getExpression();
    Type createdType = node.getType();
    ConstraintVariable2 typeCv;
    if (node.getAnonymousClassDeclaration() == null) {
        typeCv = getConstraintVariable(createdType);
    } else {
        typeCv = fTCModel.makeImmutableTypeVariable(createdType.resolveBinding(), null);
        setConstraintVariable(createdType, typeCv);
    }
    setConstraintVariable(node, typeCv);
    IMethodBinding methodBinding = node.resolveConstructorBinding();
    Map<String, IndependentTypeVariable2> methodTypeVariables = createMethodTypeArguments(methodBinding);
    List<Expression> arguments = node.arguments();
    doVisitMethodInvocationArguments(methodBinding, arguments, receiver, methodTypeVariables, createdType);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) GenericType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.GenericType) ParameterizedType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.ParameterizedType) WildcardType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.WildcardType) ArrayType(org.eclipse.jdt.core.dom.ArrayType) Type(org.eclipse.jdt.core.dom.Type) TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) IndependentTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.IndependentTypeVariable2)

Aggregations

IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)164 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)103 ASTNode (org.eclipse.jdt.core.dom.ASTNode)46 Expression (org.eclipse.jdt.core.dom.Expression)34 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)33 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)32 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)28 ArrayList (java.util.ArrayList)27 IBinding (org.eclipse.jdt.core.dom.IBinding)24 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)20 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)20 CastExpression (org.eclipse.jdt.core.dom.CastExpression)19 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)19 SimpleName (org.eclipse.jdt.core.dom.SimpleName)19 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)18 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)18 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)17 Image (org.eclipse.swt.graphics.Image)16 AST (org.eclipse.jdt.core.dom.AST)15 Type (org.eclipse.jdt.core.dom.Type)15