Search in sources :

Example 76 with IMethodBinding

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

the class AbstractExceptionAnalyzer method visit.

@Override
public boolean visit(VariableDeclarationExpression node) {
    if (node.getLocationInParent() == TryStatement.RESOURCES_PROPERTY) {
        Type type = node.getType();
        ITypeBinding resourceTypeBinding = type.resolveBinding();
        if (resourceTypeBinding != null) {
            //$NON-NLS-1$
            IMethodBinding methodBinding = Bindings.findMethodInHierarchy(resourceTypeBinding, "close", new ITypeBinding[0]);
            if (methodBinding != null) {
                addExceptions(methodBinding.getExceptionTypes(), node.getAST());
            }
        }
    }
    return super.visit(node);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) Type(org.eclipse.jdt.core.dom.Type) UnionType(org.eclipse.jdt.core.dom.UnionType) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 77 with IMethodBinding

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

the class ImportRemover method applyRemoves.

public void applyRemoves(ImportRewrite importRewrite) {
    IBinding[] bindings = getImportsToRemove();
    for (int i = 0; i < bindings.length; i++) {
        if (bindings[i] instanceof ITypeBinding) {
            ITypeBinding typeBinding = (ITypeBinding) bindings[i];
            importRewrite.removeImport(typeBinding.getTypeDeclaration().getQualifiedName());
        } else if (bindings[i] instanceof IMethodBinding) {
            IMethodBinding binding = (IMethodBinding) bindings[i];
            importRewrite.removeStaticImport(binding.getDeclaringClass().getQualifiedName() + '.' + binding.getName());
        } else if (bindings[i] instanceof IVariableBinding) {
            IVariableBinding binding = (IVariableBinding) bindings[i];
            importRewrite.removeStaticImport(binding.getDeclaringClass().getQualifiedName() + '.' + binding.getName());
        }
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) IBinding(org.eclipse.jdt.core.dom.IBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding)

Example 78 with IMethodBinding

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

the class RemoveDeclarationCorrectionProposal method getName.

@Override
public String getName() {
    IBinding binding = fName.resolveBinding();
    String name = BasicElementLabels.getJavaElementName(fName.getIdentifier());
    switch(binding.getKind()) {
        case IBinding.TYPE:
            return Messages.format(CorrectionMessages.RemoveDeclarationCorrectionProposal_removeunusedtype_description, name);
        case IBinding.METHOD:
            if (((IMethodBinding) binding).isConstructor()) {
                return Messages.format(CorrectionMessages.RemoveDeclarationCorrectionProposal_removeunusedconstructor_description, name);
            } else {
                return Messages.format(CorrectionMessages.RemoveDeclarationCorrectionProposal_removeunusedmethod_description, name);
            }
        case IBinding.VARIABLE:
            if (((IVariableBinding) binding).isField()) {
                return Messages.format(CorrectionMessages.RemoveDeclarationCorrectionProposal_removeunusedfield_description, name);
            } else {
                return Messages.format(CorrectionMessages.RemoveDeclarationCorrectionProposal_removeunusedvar_description, name);
            }
        default:
            return super.getDisplayString();
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) IBinding(org.eclipse.jdt.core.dom.IBinding) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding)

Example 79 with IMethodBinding

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

the class TypeChangeCorrectionProposal method sortTypes.

private void sortTypes(ITypeBinding[] typeProposals) {
    ITypeBinding oldType;
    if (fBinding instanceof IMethodBinding) {
        oldType = ((IMethodBinding) fBinding).getReturnType();
    } else {
        oldType = ((IVariableBinding) fBinding).getType();
    }
    if (!oldType.isParameterizedType())
        return;
    final ITypeBinding oldTypeDeclaration = oldType.getTypeDeclaration();
    Arrays.sort(typeProposals, new Comparator<ITypeBinding>() {

        public int compare(ITypeBinding o1, ITypeBinding o2) {
            return rank(o2) - rank(o1);
        }

        private int rank(ITypeBinding type) {
            if (type.getTypeDeclaration().equals(oldTypeDeclaration))
                return 1;
            return 0;
        }
    });
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 80 with IMethodBinding

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

the class BindingLabelProvider method getAdornmentFlags.

/*extends LabelProvider */
private static int getAdornmentFlags(IBinding binding) {
    int adornments = 0;
    final int modifiers = binding.getModifiers();
    if (Modifier.isAbstract(modifiers))
        adornments |= JavaElementImageDescriptor.ABSTRACT;
    if (Modifier.isFinal(modifiers))
        adornments |= JavaElementImageDescriptor.FINAL;
    if (Modifier.isStatic(modifiers))
        adornments |= JavaElementImageDescriptor.STATIC;
    if (binding.isDeprecated())
        adornments |= JavaElementImageDescriptor.DEPRECATED;
    if (binding instanceof IMethodBinding) {
        if (((IMethodBinding) binding).isConstructor())
            adornments |= JavaElementImageDescriptor.CONSTRUCTOR;
        if (Modifier.isSynchronized(modifiers))
            adornments |= JavaElementImageDescriptor.SYNCHRONIZED;
        if (Modifier.isNative(modifiers))
            adornments |= JavaElementImageDescriptor.NATIVE;
        ITypeBinding type = ((IMethodBinding) binding).getDeclaringClass();
        if (type.isInterface() && !Modifier.isAbstract(modifiers) && !Modifier.isStatic(modifiers))
            adornments |= JavaElementImageDescriptor.DEFAULT_METHOD;
        if (((IMethodBinding) binding).getDefaultValue() != null)
            adornments |= JavaElementImageDescriptor.ANNOTATION_DEFAULT;
    }
    if (binding instanceof IVariableBinding && ((IVariableBinding) binding).isField()) {
        if (Modifier.isTransient(modifiers))
            adornments |= JavaElementImageDescriptor.TRANSIENT;
        if (Modifier.isVolatile(modifiers))
            adornments |= JavaElementImageDescriptor.VOLATILE;
    }
    return adornments;
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) Point(org.eclipse.swt.graphics.Point)

Aggregations

IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)173 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)110 ASTNode (org.eclipse.jdt.core.dom.ASTNode)46 Expression (org.eclipse.jdt.core.dom.Expression)36 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)33 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)32 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)29 ArrayList (java.util.ArrayList)27 IBinding (org.eclipse.jdt.core.dom.IBinding)25 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)21 CastExpression (org.eclipse.jdt.core.dom.CastExpression)20 SimpleName (org.eclipse.jdt.core.dom.SimpleName)20 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)20 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)19 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)19 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)19 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