Example usage for org.eclipse.jdt.core.dom MethodDeclaration resolveBinding

List of usage examples for org.eclipse.jdt.core.dom MethodDeclaration resolveBinding

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom MethodDeclaration resolveBinding.

Prototype

public IMethodBinding resolveBinding() 

Source Link

Document

Resolves and returns the binding for the method or constructor declared in this method or constructor declaration.

Usage

From source file:br.uff.ic.mergeguider.javaparser.ProjectAST.java

public List<MyMethodInvocation> getMethodCallers(MethodDeclaration methodDeclaration) {
    List<MyMethodInvocation> invocations = new ArrayList<>();

    IMethodBinding methodDeclarationBinding = methodDeclaration.resolveBinding();
    if (methodDeclarationBinding == null) {
        //Method does not have binding
        return null;
    }/*  ww  w . j ava  2s .com*/

    for (ClassLanguageContructs languageConstructsByClass : classesLanguageConstructs) {
        for (MyMethodInvocation methoInvocation : languageConstructsByClass.getMethodInvocations()) {

            IMethodBinding methodInvocationBinding = methoInvocation.getMethodInvocation()
                    .resolveMethodBinding();

            if (methodInvocationBinding == null) {
                //no binding
                continue;
            }

            if (methodDeclarationBinding.equals(methodInvocationBinding)) {
                invocations.add(methoInvocation);
            }
        }
    }

    return invocations;
}

From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java

License:Open Source License

private IDSModel processComponent(TypeDeclaration type, ITypeBinding typeBinding, Annotation annotation,
        IAnnotationBinding annotationBinding, Collection<DSAnnotationProblem> problems) {
    HashMap<String, Object> params = new HashMap<String, Object>();
    for (IMemberValuePairBinding pair : annotationBinding.getDeclaredMemberValuePairs()) {
        params.put(pair.getName(), pair.getValue());
    }/*from w ww  .jav  a2 s  .  co m*/

    boolean requiresV12 = false;

    String implClass = typeBinding.getBinaryName();

    String name = implClass;
    Object value;
    if ((value = params.get("name")) instanceof String) { //$NON-NLS-1$
        name = (String) value;
        validateComponentName(annotation, name, problems);
    }

    Collection<String> services;
    if ((value = params.get("service")) instanceof Object[]) { //$NON-NLS-1$
        Object[] elements = (Object[]) value;
        services = new LinkedHashSet<String>(elements.length);
        Map<String, Integer> serviceDuplicates = errorLevel.isNone() ? null : new HashMap<String, Integer>();
        for (int i = 0; i < elements.length; ++i) {
            ITypeBinding serviceType = (ITypeBinding) elements[i];
            String serviceName = serviceType.getBinaryName();
            if (!errorLevel.isNone()) {
                if (serviceDuplicates.containsKey(serviceName)) {
                    reportProblem(annotation, "service", i, problems, //$NON-NLS-1$
                            Messages.AnnotationProcessor_duplicateServiceDeclaration, serviceName);
                    Integer pos = serviceDuplicates.put(serviceName, null);
                    if (pos != null)
                        reportProblem(annotation, "service", pos.intValue(), problems, //$NON-NLS-1$
                                Messages.AnnotationProcessor_duplicateServiceDeclaration, serviceName);
                } else {
                    serviceDuplicates.put(serviceName, i);
                }
            }

            services.add(serviceName);
            validateComponentService(annotation, typeBinding, serviceType, i, problems);
        }
    } else {
        ITypeBinding[] serviceTypes = typeBinding.getInterfaces();
        services = new ArrayList<String>(serviceTypes.length);
        for (int i = 0; i < serviceTypes.length; ++i) {
            services.add(serviceTypes[i].getBinaryName());
        }
    }

    String factory = null;
    if ((value = params.get("factory")) instanceof String) { //$NON-NLS-1$
        factory = (String) value;
        validateComponentFactory(annotation, factory, problems);
    }

    Boolean serviceFactory = null;
    if ((value = params.get("servicefactory")) instanceof Boolean) { //$NON-NLS-1$
        serviceFactory = (Boolean) value;
    }

    Boolean enabled = null;
    if ((value = params.get("enabled")) instanceof Boolean) { //$NON-NLS-1$
        enabled = (Boolean) value;
    }

    Boolean immediate = null;
    if ((value = params.get("immediate")) instanceof Boolean) { //$NON-NLS-1$
        immediate = (Boolean) value;
    }

    String[] properties;
    if ((value = params.get("property")) instanceof Object[]) { //$NON-NLS-1$
        Object[] elements = (Object[]) value;
        ArrayList<String> list = new ArrayList<String>(elements.length);
        for (int i = 0; i < elements.length; ++i) {
            if (elements[i] instanceof String)
                list.add((String) elements[i]);
        }

        properties = list.toArray(new String[list.size()]);
    } else {
        properties = new String[0];
    }

    String[] propertyFiles;
    if ((value = params.get("properties")) instanceof Object[]) { //$NON-NLS-1$
        Object[] elements = (Object[]) value;
        ArrayList<String> list = new ArrayList<String>(elements.length);
        for (int i = 0; i < elements.length; ++i) {
            if (elements[i] instanceof String)
                list.add((String) elements[i]);
        }

        propertyFiles = list.toArray(new String[list.size()]);
        validateComponentPropertyFiles(annotation,
                ((IType) typeBinding.getJavaElement()).getJavaProject().getProject(), propertyFiles, problems);
    } else {
        propertyFiles = new String[0];
    }

    String configPolicy = null;
    if ((value = params.get("configurationPolicy")) instanceof IVariableBinding) { //$NON-NLS-1$
        IVariableBinding configPolicyBinding = (IVariableBinding) value;
        ConfigurationPolicy configPolicyLiteral = ConfigurationPolicy.valueOf(configPolicyBinding.getName());
        if (configPolicyLiteral != null)
            configPolicy = configPolicyLiteral.toString();
    }

    String configPid = null;
    if ((value = params.get("configurationPid")) instanceof String) { //$NON-NLS-1$
        configPid = (String) value;
        validateComponentConfigPID(annotation, configPid, problems);
        requiresV12 = true;
    }

    DSModel model = new DSModel(new Document(), false);
    IDSComponent component = model.getDSComponent();

    if (name != null)
        component.setAttributeName(name);

    if (factory != null)
        component.setFactory(factory);

    if (enabled != null)
        component.setEnabled(enabled.booleanValue());

    if (immediate != null)
        component.setImmediate(immediate.booleanValue());

    if (configPolicy != null)
        component.setConfigurationPolicy(configPolicy);

    if (configPid != null)
        component.setXMLAttribute("configuration-pid", configPid); //$NON-NLS-1$

    IDSDocumentFactory dsFactory = component.getModel().getFactory();
    IDSImplementation impl = dsFactory.createImplementation();
    component.setImplementation(impl);
    impl.setClassName(implClass);

    if (!services.isEmpty()) {
        IDSService service = dsFactory.createService();
        component.setService(service);
        for (String serviceName : services) {
            IDSProvide provide = dsFactory.createProvide();
            service.addProvidedService(provide);
            provide.setInterface(serviceName);
        }

        if (serviceFactory != null)
            service.setServiceFactory(serviceFactory.booleanValue());
    }

    if (properties.length > 0) {
        HashMap<String, IDSProperty> map = new HashMap<String, IDSProperty>(properties.length);
        for (int i = 0; i < properties.length; ++i) {
            String propertyStr = properties[i];
            String[] pair = propertyStr.split("=", 2); //$NON-NLS-1$
            int colon = pair[0].indexOf(':');
            String propertyName, propertyType;
            if (colon == -1) {
                propertyName = pair[0];
                propertyType = null;
            } else {
                propertyName = pair[0].substring(0, colon);
                propertyType = pair[0].substring(colon + 1);
            }

            String propertyValue = pair.length > 1 ? pair[1].trim() : null;

            IDSProperty property = map.get(propertyName);
            if (property == null) {
                // create a new property
                property = dsFactory.createProperty();
                component.addPropertyElement(property);
                map.put(propertyName, property);
                property.setPropertyName(propertyName);
                property.setPropertyType(propertyType);
                property.setPropertyValue(propertyValue);
                validateComponentProperty(annotation, propertyName, propertyType, propertyValue, i, problems);
            } else {
                // property exists; make it multi-valued
                String content = property.getPropertyElemBody();
                if (content == null) {
                    content = property.getPropertyValue();
                    property.setPropertyElemBody(content);
                    property.setPropertyValue(null);
                }

                if (!errorLevel.isNone()) {
                    String expected = property.getPropertyType() == null || property.getPropertyType().isEmpty()
                            || String.class.getSimpleName().equals(property.getPropertyType())
                                    ? Messages.AnnotationProcessor_stringOrEmpty
                                    : property.getPropertyType();
                    String actual = propertyType == null || String.class.getSimpleName().equals(propertyType)
                            ? Messages.AnnotationProcessor_stringOrEmpty
                            : propertyType;
                    if (!actual.equals(expected))
                        reportProblem(annotation, "property", i, problems, //$NON-NLS-1$
                                NLS.bind(Messages.AnnotationProcessor_inconsistentComponentPropertyType, actual,
                                        expected),
                                actual);
                    else
                        validateComponentProperty(annotation, propertyName, propertyType, propertyValue, i,
                                problems);
                }

                if (propertyValue != null)
                    property.setPropertyElemBody(content + "\n" + pair[1]); //$NON-NLS-1$
            }
        }
    }

    if (propertyFiles.length > 0) {
        for (String propertyFile : propertyFiles) {
            IDSProperties propertiesElement = dsFactory.createProperties();
            component.addPropertiesElement(propertiesElement);
            propertiesElement.setEntry(propertyFile);
        }
    }

    String activate = null;
    Annotation activateAnnotation = null;
    String deactivate = null;
    Annotation deactivateAnnotation = null;
    String modified = null;
    Annotation modifiedAnnotation = null;

    ArrayList<IDSReference> references = new ArrayList<IDSReference>();
    HashMap<String, Annotation> referenceNames = new HashMap<String, Annotation>();

    for (MethodDeclaration method : type.getMethods()) {
        for (Object modifier : method.modifiers()) {
            if (!(modifier instanceof Annotation))
                continue;

            Annotation methodAnnotation = (Annotation) modifier;
            IAnnotationBinding methodAnnotationBinding = methodAnnotation.resolveAnnotationBinding();
            if (methodAnnotationBinding == null) {
                if (debug.isDebugging())
                    debug.trace(
                            String.format("Unable to resolve binding for annotation: %s", methodAnnotation)); //$NON-NLS-1$

                continue;
            }

            String annotationName = methodAnnotationBinding.getAnnotationType().getQualifiedName();

            if (ACTIVATE_ANNOTATION.equals(annotationName)) {
                if (activate == null) {
                    activate = method.getName().getIdentifier();
                    activateAnnotation = methodAnnotation;
                    validateLifeCycleMethod(methodAnnotation, "activate", method, problems); //$NON-NLS-1$
                } else if (!errorLevel.isNone()) {
                    reportProblem(methodAnnotation, null, problems,
                            Messages.AnnotationProcessor_duplicateActivateMethod,
                            method.getName().getIdentifier());
                    if (activateAnnotation != null) {
                        reportProblem(activateAnnotation, null, problems,
                                Messages.AnnotationProcessor_duplicateActivateMethod, activate);
                        activateAnnotation = null;
                    }
                }

                continue;
            }

            if (DEACTIVATE_ANNOTATION.equals(annotationName)) {
                if (deactivate == null) {
                    deactivate = method.getName().getIdentifier();
                    deactivateAnnotation = methodAnnotation;
                    validateLifeCycleMethod(methodAnnotation, "deactivate", method, problems); //$NON-NLS-1$
                } else if (!errorLevel.isNone()) {
                    reportProblem(methodAnnotation, null, problems,
                            Messages.AnnotationProcessor_duplicateDeactivateMethod,
                            method.getName().getIdentifier());
                    if (deactivateAnnotation != null) {
                        reportProblem(deactivateAnnotation, null, problems,
                                Messages.AnnotationProcessor_duplicateDeactivateMethod, deactivate);
                        deactivateAnnotation = null;
                    }
                }

                continue;
            }

            if (MODIFIED_ANNOTATION.equals(annotationName)) {
                if (modified == null) {
                    modified = method.getName().getIdentifier();
                    modifiedAnnotation = methodAnnotation;
                    validateLifeCycleMethod(methodAnnotation, "modified", method, problems); //$NON-NLS-1$
                } else if (!errorLevel.isNone()) {
                    reportProblem(methodAnnotation, null, problems,
                            Messages.AnnotationProcessor_duplicateModifiedMethod,
                            method.getName().getIdentifier());
                    if (modifiedAnnotation != null) {
                        reportProblem(modifiedAnnotation, null, problems,
                                Messages.AnnotationProcessor_duplicateModifiedMethod, modified);
                        modifiedAnnotation = null;
                    }
                }

                continue;
            }

            if (REFERENCE_ANNOTATION.equals(annotationName)) {
                IMethodBinding methodBinding = method.resolveBinding();
                if (methodBinding == null) {
                    if (debug.isDebugging())
                        debug.trace(String.format("Unable to resolve binding for method: %s", method)); //$NON-NLS-1$
                } else {
                    requiresV12 |= processReference(method, methodBinding, methodAnnotation,
                            methodAnnotationBinding, dsFactory, references, referenceNames, problems);
                }

                continue;
            }
        }
    }

    if (activate != null)
        component.setActivateMethod(activate);

    if (deactivate != null)
        component.setDeactivateMethod(deactivate);

    if (modified != null)
        component.setModifiedeMethod(modified);

    if (!references.isEmpty()) {
        // references must be declared in ascending lexicographical order of their names
        Collections.sort(references, REF_NAME_COMPARATOR);
        for (IDSReference reference : references) {
            component.addReference(reference);
        }
    }

    String xmlns = null;
    if ((value = params.get("xmlns")) instanceof String) { //$NON-NLS-1$
        xmlns = (String) value;
        validateComponentXMLNS(annotation, xmlns, requiresV12, problems);
    } else if (requiresV12) {
        xmlns = NAMESPACE_1_2;
    }

    if (xmlns != null)
        component.setNamespace(xmlns);

    return model;
}

From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java

License:Open Source License

private void validateLifeCycleMethod(Annotation annotation, String methodName, MethodDeclaration method,
        Collection<DSAnnotationProblem> problems) {
    if (errorLevel.isNone())
        return;//from ww  w  .j  a va 2  s.  c  o  m

    IMethodBinding methodBinding = method.resolveBinding();
    if (methodBinding == null) {
        if (debug.isDebugging())
            debug.trace(String.format("Unable to resolve binding for method: %s", method)); //$NON-NLS-1$

        return;
    }

    String returnTypeName = methodBinding.getReturnType().getName();
    if (!Void.TYPE.getName().equals(returnTypeName))
        reportProblem(annotation, methodName, problems,
                NLS.bind(Messages.AnnotationProcessor_invalidLifeCycleMethodReturnType, methodName,
                        returnTypeName),
                returnTypeName);

    ITypeBinding[] paramTypeBindings = methodBinding.getParameterTypes();

    if (paramTypeBindings.length == 0)
        // no-arg method
        return;

    // every argument must be either Map, ComponentContext, or BundleContext
    boolean hasMap = false;
    boolean hasCompCtx = false;
    boolean hasBundleCtx = false;
    boolean hasInt = false;
    for (ITypeBinding paramTypeBinding : paramTypeBindings) {
        String paramTypeName = paramTypeBinding.getErasure().getQualifiedName();
        boolean isDuplicate = false;

        if (Map.class.getName().equals(paramTypeName)) {
            if (hasMap)
                isDuplicate = true;
            else
                hasMap = true;
        } else if (ComponentContext.class.getName().equals(paramTypeName)) {
            if (hasCompCtx)
                isDuplicate = true;
            else
                hasCompCtx = true;
        } else if (BundleContext.class.getName().equals(paramTypeName)) {
            if (hasBundleCtx)
                isDuplicate = true;
            else
                hasBundleCtx = true;
        } else if ("deactivate".equals(methodName) //$NON-NLS-1$
                && (Integer.class.getName().equals(paramTypeName)
                        || Integer.TYPE.getName().equals(paramTypeName))) {
            if (hasInt)
                isDuplicate = true;
            else
                hasInt = true;
        } else {
            reportProblem(annotation, methodName, problems,
                    NLS.bind(Messages.AnnotationProcessor_invalidLifeCycleMethodParameterType, methodName,
                            paramTypeName),
                    paramTypeName);
        }

        if (isDuplicate)
            reportProblem(annotation, methodName, problems,
                    NLS.bind(Messages.AnnotationProcessor_duplicateLifeCycleMethodParameterType, methodName,
                            paramTypeName),
                    paramTypeName);
    }
}

From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

@Override
public boolean visit(final MarkerAnnotation node) {
    final ITypeBinding binding = node.resolveTypeBinding();
    if (ASTCrawler.checkForNull(binding))
        return false;
    final IElement annoteElem = ASTCrawler.convertBinding(binding);
    this.aDB.addElement(annoteElem, binding.getModifiers());

    final ASTNode annotatedNode = node.getParent();
    switch (annotatedNode.getNodeType()) {
    case ASTNode.METHOD_DECLARATION: {
        final MethodDeclaration annotatedMethod = (MethodDeclaration) annotatedNode;
        final IMethodBinding mBinding = annotatedMethod.resolveBinding();
        return this.addAnnotationRelation(annoteElem, mBinding);

    }//www  .jav  a  2  s.co  m
    case ASTNode.ANNOTATION_TYPE_DECLARATION: {
        final AnnotationTypeDeclaration annotatedAnnotation = (AnnotationTypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = annotatedAnnotation.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.VARIABLE_DECLARATION_STATEMENT: {
        return processVariableDeclarationStatement(annoteElem, (VariableDeclarationStatement) annotatedNode);
    }
    case ASTNode.VARIABLE_DECLARATION_FRAGMENT: {
        return processVariableDeclarationFragment(annoteElem, (VariableDeclarationFragment) annotatedNode);
    }
    case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION: {
        AnnotationTypeMemberDeclaration atmd = (AnnotationTypeMemberDeclaration) annotatedNode;
        IMethodBinding methodBinding = atmd.resolveBinding();
        return this.addAnnotationRelation(annoteElem, methodBinding);
    }

    case ASTNode.PACKAGE_DECLARATION: {
        final PackageDeclaration packDecl = (PackageDeclaration) annotatedNode;
        final IPackageBinding pBinding = packDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, pBinding);
    }

    case ASTNode.SINGLE_VARIABLE_DECLARATION: {
        final SingleVariableDeclaration svd = (SingleVariableDeclaration) annotatedNode;
        final IVariableBinding vBinding = svd.resolveBinding();
        return this.addAnnotationRelation(annoteElem, vBinding);
    }
    case ASTNode.TYPE_DECLARATION: {
        final TypeDeclaration tDecl = (TypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = tDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.ENUM_DECLARATION: {
        final EnumDeclaration eDecl = (EnumDeclaration) annotatedNode;
        final ITypeBinding tBinding = eDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }

    case ASTNode.FIELD_DECLARATION: {
        final FieldDeclaration fieldDecl = (FieldDeclaration) annotatedNode;
        for (final Object obj : fieldDecl.fragments()) {
            final VariableDeclarationFragment vdf = (VariableDeclarationFragment) obj;
            final IVariableBinding vBinding = vdf.resolveBinding();
            return this.addAnnotationRelation(annoteElem, vBinding);
        }
    }

    default: {
        throw new IllegalStateException("Illegal annotated node type: " + annotatedNode);
    }
    }
}

From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

@Override
public boolean visit(final MethodDeclaration pNode) {
    final IMethodBinding lMBinding = pNode.resolveBinding();

    if (ASTCrawler.checkForNull(lMBinding))
        return false;
    this.saveMethodRelation(lMBinding);

    this.aDB.addRelation(this.aCurrType, Relation.DECLARES_METHOD, this.aCurrMethod);

    // If this is a constructor, we dump the class initilization relations
    // into the constructor
    if (lMBinding.isConstructor())
        this.aCurrConstructorList.add(this.aCurrMethod);
    // aDB.copyRelations( aTempMethod, aCurrMethod ); // TODO: But what if
    // there're fields that have not yet be parsed?

    // System.out.println(this.aCurrMethod);
    // IJavaElement elem = lMBinding.getJavaElement();
    // if ( AJModel.getInstance().isAdvised(elem) ) {
    // List<AdviceElement> applicableAdvice = getApplicableAdvice(elem);
    // for (AdviceElement advice: applicableAdvice ) {
    // if ( advice != null && advice.equals(this.selectedAdvice) ) {
    // IElement adviceElem = Utils.convertBinding(Category.ADVICE,
    // advice.getHandleIdentifier());
    // try {// w  w  w .  j  a  v a2  s  .com
    // this.aDB.addElement(adviceElem, advice.getFlags());
    // } catch (JavaModelException e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // }
    //
    // this.aDB.addRelation(adviceElem, Relation.ADVISES, aCurrMethod);
    // }
    // }
    // }
    return true;
}

From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

@Override
public boolean visit(final NormalAnnotation node) {
    final ITypeBinding binding = node.resolveTypeBinding();
    if (ASTCrawler.checkForNull(binding))
        return false;
    final IElement annoteElem = ASTCrawler.convertBinding(binding);
    this.aDB.addElement(annoteElem, binding.getModifiers());

    final ASTNode annotatedNode = node.getParent();
    switch (annotatedNode.getNodeType()) {
    case ASTNode.METHOD_DECLARATION: {
        final MethodDeclaration annotatedMethod = (MethodDeclaration) annotatedNode;
        final IMethodBinding mBinding = annotatedMethod.resolveBinding();
        return this.addAnnotationRelation(annoteElem, mBinding);

    }// ww w  . ja  v a  2s  .com
    case ASTNode.ANNOTATION_TYPE_DECLARATION: {
        final AnnotationTypeDeclaration annotatedAnnotation = (AnnotationTypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = annotatedAnnotation.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.VARIABLE_DECLARATION_STATEMENT: {
        return processVariableDeclarationStatement(annoteElem, (VariableDeclarationStatement) annotatedNode);
    }
    case ASTNode.VARIABLE_DECLARATION_FRAGMENT: {
        return processVariableDeclarationFragment(annoteElem, (VariableDeclarationFragment) annotatedNode);
    }

    case ASTNode.PACKAGE_DECLARATION: {
        final PackageDeclaration packDecl = (PackageDeclaration) annotatedNode;
        final IPackageBinding pBinding = packDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, pBinding);
    }

    case ASTNode.SINGLE_VARIABLE_DECLARATION: {
        final SingleVariableDeclaration svd = (SingleVariableDeclaration) annotatedNode;
        final IVariableBinding vBinding = svd.resolveBinding();
        return this.addAnnotationRelation(annoteElem, vBinding);
    }
    case ASTNode.TYPE_DECLARATION: {
        final TypeDeclaration tDecl = (TypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = tDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.ENUM_DECLARATION: {
        final EnumDeclaration eDecl = (EnumDeclaration) annotatedNode;
        final ITypeBinding tBinding = eDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.FIELD_DECLARATION: {
        final FieldDeclaration fieldDecl = (FieldDeclaration) annotatedNode;
        for (final Object obj : fieldDecl.fragments()) {
            final VariableDeclarationFragment vdf = (VariableDeclarationFragment) obj;
            final IVariableBinding vBinding = vdf.resolveBinding();
            return this.addAnnotationRelation(annoteElem, vBinding);
        }
    }
    default: {
        throw new IllegalStateException("Illegal annotated node type: " + annotatedNode);
    }
    }
}

From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

@Override
public boolean visit(final SingleMemberAnnotation node) {
    final ITypeBinding binding = node.resolveTypeBinding();
    if (ASTCrawler.checkForNull(binding))
        return false;
    final IElement annoteElem = ASTCrawler.convertBinding(binding);
    this.aDB.addElement(annoteElem, binding.getModifiers());

    final ASTNode annotatedNode = node.getParent();
    switch (annotatedNode.getNodeType()) {
    case ASTNode.METHOD_DECLARATION: {
        final MethodDeclaration annotatedMethod = (MethodDeclaration) annotatedNode;
        final IMethodBinding mBinding = annotatedMethod.resolveBinding();
        return this.addAnnotationRelation(annoteElem, mBinding);

    }/* www.  j  a va2s  .  c o  m*/
    case ASTNode.ANNOTATION_TYPE_DECLARATION: {
        final AnnotationTypeDeclaration annotatedAnnotation = (AnnotationTypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = annotatedAnnotation.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }

    case ASTNode.VARIABLE_DECLARATION_STATEMENT: {
        VariableDeclarationStatement vds = (VariableDeclarationStatement) annotatedNode;
        return processVariableDeclarationStatement(annoteElem, vds);
    }

    case ASTNode.VARIABLE_DECLARATION_FRAGMENT: {
        return processVariableDeclarationFragment(annoteElem, (VariableDeclarationFragment) annotatedNode);
    }

    case ASTNode.PACKAGE_DECLARATION: {
        final PackageDeclaration packDecl = (PackageDeclaration) annotatedNode;
        final IPackageBinding pBinding = packDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, pBinding);
    }

    case ASTNode.SINGLE_VARIABLE_DECLARATION: {
        final SingleVariableDeclaration svd = (SingleVariableDeclaration) annotatedNode;
        final IVariableBinding vBinding = svd.resolveBinding();
        return this.addAnnotationRelation(annoteElem, vBinding);
    }
    case ASTNode.TYPE_DECLARATION: {
        final TypeDeclaration tDecl = (TypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = tDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.ENUM_DECLARATION: {
        final EnumDeclaration eDecl = (EnumDeclaration) annotatedNode;
        final ITypeBinding tBinding = eDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.FIELD_DECLARATION: {
        final FieldDeclaration fieldDecl = (FieldDeclaration) annotatedNode;
        for (final Object obj : fieldDecl.fragments()) {
            final VariableDeclarationFragment vdf = (VariableDeclarationFragment) obj;
            final IVariableBinding vBinding = vdf.resolveBinding();
            return this.addAnnotationRelation(annoteElem, vBinding);
        }
    }
    default: {
        throw new IllegalStateException("Illegal annotated node type: " + annotatedNode);
    }
    }
}

From source file:ca.mcgill.cs.swevo.ppa.inference.ReturnInferenceStrategy.java

License:Open Source License

public void inferTypes(ASTNode node) {
    ReturnStatement returnStmt = (ReturnStatement) node;

    Expression exp = returnStmt.getExpression();

    if (exp == null || !indexer.isIndexable(exp) || indexer.isSafe(exp)) {
        return;/*from  ww w  .  j av a2  s .  co  m*/
    }

    MethodDeclaration mDeclaration = (MethodDeclaration) PPAASTUtil.getSpecificParentType(returnStmt,
            ASTNode.METHOD_DECLARATION);
    if (mDeclaration != null) {
        IMethodBinding methodBinding = mDeclaration.resolveBinding();
        if (methodBinding != null) {
            ITypeBinding newBinding = methodBinding.getReturnType();
            ITypeBinding oldBinding = exp.resolveTypeBinding();
            TypeFact typeFact = new TypeFact(indexer.getMainIndex(exp), oldBinding, TypeFact.UNKNOWN,
                    newBinding, TypeFact.SUBTYPE, TypeFact.RETURN_STRATEGY);
            ppaEngine.reportTypeFact(typeFact);
        }
    }
}

From source file:cc.kave.eclipse.namefactory.NodeFactory.java

License:Apache License

private static Name createMethodDeclName(MethodDeclaration methodNode) {
    IMethodBinding methodBinding = methodNode.resolveBinding();
    return CsMethodName.newMethodName(methodNameHelper(methodNode, methodBinding, true));
}

From source file:cc.kave.eclipse.namefactory.NodeFactory.java

License:Apache License

/**
 * /*www  . j  av  a2s .  com*/
 * @param method
 *            Expects a MethodDeclaration, MethodInvocation or a
 *            SuperMethodInvocation node.
 * @return Returns an array of all parameterNames.
 */
protected static String[] createParameterNames(ASTNode method) {
    if (method instanceof MethodDeclaration) {
        MethodDeclaration methodDecl = (MethodDeclaration) method;
        return createParameterNames(methodDecl, methodDecl.resolveBinding());
    } else if (method instanceof MethodInvocation) {
        MethodInvocation methodInv = (MethodInvocation) method;
        return createParameterNames(null, methodInv.resolveMethodBinding());
    } else if (method instanceof SuperMethodInvocation) {
        SuperMethodInvocation superMethodInv = (SuperMethodInvocation) method;
        return createParameterNames(null, superMethodInv.resolveMethodBinding());
    }
    return null;
}