Example usage for org.eclipse.jdt.core.dom TypeDeclaration getMethods

List of usage examples for org.eclipse.jdt.core.dom TypeDeclaration getMethods

Introduction

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

Prototype

public MethodDeclaration[] getMethods() 

Source Link

Document

Returns the ordered list of method declarations of this type declaration.

Usage

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

License:Open Source License

private boolean hasDefaultConstructor(TypeDeclaration type) {
    boolean hasConstructor = false;
    for (MethodDeclaration method : type.getMethods()) {
        if (method.isConstructor()) {
            hasConstructor = true;/*from  www  .  jav a  2s.  c o m*/
            if (Modifier.isPublic(method.getModifiers()) && method.parameters().isEmpty())
                return true;
        }
    }

    return !hasConstructor;
}

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());
    }//  w w  w . j a v a  2s  .com

    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:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from   w ww .  j  av a  2 s.  c  om
public boolean visit(TypeDeclaration node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }
    // @Inria
    pushNode(node, node.getName().toString());
    visitListAsNode(EntityType.MODIFIERS, node.modifiers());
    visitListAsNode(EntityType.TYPE_ARGUMENTS, node.typeParameters());
    if (node.getSuperclassType() != null) {
        node.getSuperclassType().accept(this);
    }

    visitListAsNode(EntityType.SUPER_INTERFACE_TYPES, node.superInterfaceTypes());

    // @Inria
    // Change Distiller does not check the changes at Class Field declaration
    for (FieldDeclaration fd : node.getFields()) {
        fd.accept(this);
    }
    // @Inria
    // Visit Declaration and Body (inside MD visiting)
    for (MethodDeclaration md : node.getMethods()) {
        md.accept(this);
    }
    return false;
}

From source file:cn.ieclipse.adt.ext.jdt.SourceGenerator.java

License:Apache License

private static MethodDeclaration getMethod(TypeDeclaration type, String name, Type... types) {
    MethodDeclaration result = null;/*from w ww.j  a  va  2s .  co  m*/
    MethodDeclaration[] methods = type.getMethods();
    for (MethodDeclaration temp : methods) {
        if (temp.getName().getIdentifier().equals(name)) {
            List params = temp.typeParameters();
            if (params.isEmpty() && types == null) {
                result = temp;
                break;
            } else if (params.size() == types.length) {
                boolean eq = true;
                for (int i = 0; i < types.length; i++) {
                    if (!params.get(i).equals(types[i])) {
                        eq = false;
                        break;
                    }
                }
                if (eq) {
                    result = temp;
                    break;
                }
            }
        }
    }
    return result;
}

From source file:com.crispico.flower.codesync.tests.java.JavaTestsOnSourceCode.java

License:Open Source License

public BodyDeclaration getBody(TypeDeclaration javaClass, String bodyName) { // bodyDeclaration :FieldDeclaration,MethodDelcaration
    BodyDeclaration result = bodyMap.get(bodyName);
    if (result == null) {
        bodyMap.clear();//w  ww . j av  a  2s .c o  m
        for (FieldDeclaration f : javaClass.getFields())
            bodyMap.put(JavaSyncUtils.getSimpleNameString(f), f);
        for (MethodDeclaration m : javaClass.getMethods())
            bodyMap.put(JavaSyncUtils.getSimpleNameString(m), m);
        result = bodyMap.get(bodyName);
    }
    return result;
}

From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.reverse.ReverseJavaClass.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*  w w  w  . j av  a 2 s. c  om*/
protected ReverseStatus reverseInnerCollections(Class modelElement, CompilationUnit astElement)
        throws CodeSyncException {
    ReverseStatus result = super.reverseInnerCollections(modelElement, astElement);
    TypeDeclaration masterClass = JavaSyncUtils.getMasterClass(astElement);

    EList<Property> propertyList = modelElement.getOwnedAttributes();
    List<FieldDeclaration> fieldList = Arrays.asList(masterClass.getFields());
    result.applyOr(reverseJavaClassOwnedFields.reverse(propertyList, fieldList));

    EList<Operation> operationList = modelElement.getOwnedOperations();
    List<MethodDeclaration> methodList = Arrays.asList(masterClass.getMethods());
    result.applyOr(reverseJavaClassOwnedMethods.reverse(operationList, methodList));

    EList<InterfaceRealization> realizationList = modelElement.getInterfaceRealizations();
    List<Type> interfaceList = masterClass.superInterfaceTypes();
    result.applyOr(reverseJavaClassOwnedRealizations.reverse(realizationList, interfaceList));
    return result;
}

From source file:com.crispico.flower.mp.tests.suite.MMCSJ_S_ANNOT.java

License:Open Source License

/**
 * Add annotation for java Class/Interface on model; on synchronization it has a correspondent on source
 * Add annotation for attribute and operation also
 * /*from  w  w  w. j ava 2s  .  co m*/
 * Add annotation for java Class/Interface on source; on synchronization it has a correspondent on model
 */
public void testCase01() {
    IFile modelFile = copyFiles(true);
    EclipseFlowerEditingDomain model = TestUtils.loadModel(modelFile);
    // add annotation for class
    JavaClass class1 = (JavaClass) TestUtils.getNamedElementsFromModel(model, "java_src/Class01").get(0);
    JavaAnnotation annot = CodeSyncJavaFactory.eINSTANCE.createJavaAnnotation();
    model.getCommandStack().execute(SetCommand.create(model, annot,
            EcorePackage.eINSTANCE.getEAnnotation_Source(), classAnnotationName));
    model.getCommandStack().execute(
            AddCommand.create(model, class1, EcorePackage.eINSTANCE.getEModelElement_EAnnotations(), annot));
    // add annotation for interface
    JavaInterface interface1 = (JavaInterface) TestUtils
            .getNamedElementsFromModel(model, "java_src/Interface01").get(0);
    annot = CodeSyncJavaFactory.eINSTANCE.createJavaAnnotation();
    model.getCommandStack().execute(SetCommand.create(model, annot,
            EcorePackage.eINSTANCE.getEAnnotation_Source(), interfaceAnnotationName));
    model.getCommandStack().execute(AddCommand.create(model, interface1,
            EcorePackage.eINSTANCE.getEModelElement_EAnnotations(), annot));
    model.save();
    TestUtils.syncronizeModel(model, "java_src");
    // check if the synchronization was correct for the class 
    CompilationUnit asCompUnit = JavaTestUtils.loadJavaFile("java_src/Class01.java");
    List<JavaAnnotationHolder> annotationList = JavaSyncUtils.getAnnotations(asCompUnit);
    assertTrue(annotationList.size() == 1 && ((SimpleName) annotationList.get(0).getAnnotation().getTypeName())
            .getIdentifier().equals(classAnnotationName));
    // check if the synchronization was correct for the interface
    asCompUnit = JavaTestUtils.loadJavaFile("java_src/Interface01.java");
    annotationList = JavaSyncUtils.getAnnotations(asCompUnit);
    assertTrue(annotationList.size() == 1 && ((SimpleName) annotationList.get(0).getAnnotation().getTypeName())
            .getIdentifier().equals(interfaceAnnotationName));
    // add annotation for attribute
    JavaProperty prop = (JavaProperty) class1.getAllAttributes().get(0);
    annot = CodeSyncJavaFactory.eINSTANCE.createJavaAnnotation();
    model.getCommandStack().execute(SetCommand.create(model, annot,
            EcorePackage.eINSTANCE.getEAnnotation_Source(), attributeAnnotationName));
    model.getCommandStack().execute(
            AddCommand.create(model, prop, EcorePackage.eINSTANCE.getEModelElement_EAnnotations(), annot));
    // add annotation for operation
    JavaOperation op = (JavaOperation) class1.getAllOperations().get(0);
    annot = CodeSyncJavaFactory.eINSTANCE.createJavaAnnotation();
    model.getCommandStack().execute(SetCommand.create(model, annot,
            EcorePackage.eINSTANCE.getEAnnotation_Source(), operationAnnotationName));
    model.getCommandStack().execute(
            AddCommand.create(model, op, EcorePackage.eINSTANCE.getEModelElement_EAnnotations(), annot));
    model.save();
    TestUtils.syncronizeModel(model, "java_src");
    // check if the synchronization was correct for the attribute
    asCompUnit = JavaTestUtils.loadJavaFile("java_src/Class01.java");
    TypeDeclaration masterClass = JavaSyncUtils.getMasterClass(asCompUnit);
    List<FieldDeclaration> fieldList = Arrays.asList(masterClass.getFields());
    annotationList = JavaSyncUtils.getAnnotations(fieldList.get(0));
    assertTrue(annotationList.size() == 1 && ((SimpleName) annotationList.get(0).getAnnotation().getTypeName())
            .getIdentifier().equals(attributeAnnotationName));
    // check if the synchronization was correct for the operation   
    List<MethodDeclaration> methodList = Arrays.asList(masterClass.getMethods());
    annotationList = JavaSyncUtils.getAnnotations(methodList.get(0));
    assertTrue(annotationList.size() == 1 && ((SimpleName) annotationList.get(0).getAnnotation().getTypeName())
            .getIdentifier().equals(operationAnnotationName));

    modelFile = copyFiles(false);
    model = TestUtils.loadModel(modelFile);
    TestUtils.syncronizeModel(model, "java_src");
    model.save();
    class1 = (JavaClass) TestUtils.getNamedElementsFromModel(model, "java_src/Class01").get(0);
    assertNotNull(class1.getEAnnotation(classAnnotationName));
    interface1 = (JavaInterface) TestUtils.getNamedElementsFromModel(model, "java_src/Interface01").get(0);
    assertNotNull(interface1.getEAnnotation(interfaceAnnotationName));
}

From source file:com.crispico.flower.mp.tests.suite.MMCSJ_S_MET_ST.java

License:Open Source License

/**
 * Actions: Copy the "testModelJava.flower1" and the folder TC05 from
 * "(MMCSA-S-ATTR-ST) Elemente statice" to the root test project Open the
 * file "Class01.java" from the copied folder "TC05/TC05_1" Modify "public
 * Class01 oper1()" to "public static Class01 oper1()" (add the "static"
 * modifier) Open the copied "testModelJava.flower1" Open diagram "Diagram2"
 * Synchronize "TC05" srcDir Check "Expected Results 1". Open the
 * "Properties" view, then click on the "oper1" from "Class01" in "TC05_1"
 * package From "Properties" view modify property "Is Static" from "true" to
 * "false" Check "Expected Results 2". Synchronize "TC05" srcDir Check
 * "Expected Results 3".//from   ww w .  j a v a 2  s.c o m
 * 
 * 
 * Expected results 1 - "oper1" from "Class01" from "TC05_1" package will
 * have a "S" decorator in the upper right part of its icon - "oper1" from
 * "Diagram2" is underlined and have a "S" decorator in the upper right part
 * of its icon.
 * 
 * Expected results 2 - "oper1" from "Class01" from "TC05_1" package will
 * have lost the "S" decorator in the upper right part of its icon - "oper1"
 * from "Diagram2" will have lost the underline and the decorator.
 * 
 * Expected results 3 - in the file "TC05/TC05_1/Class01.java" will be
 * "public Class01 oper1()" instead of "public static Class01 oper1()"
 * 
 */
public void testCase01() {
    TestUtils.clearTempProject();
    // copy diagram file
    IFile diagramFile = TestUtils.copyFile(
            "(MMCSA-S-ATTR-ST) Synchronization of Static Attributes/testModelJava.flower1", "", false);
    // copy source folder TC05
    TestUtils.copyFolder("(MMCSA-S-ATTR-ST) Synchronization of Static Attributes/TC05", "");
    // synchronyze model
    TestUtils.syncronizeModel(diagramFile, "TC05");
    // open model file and see if oper1 from TC05/TC05_1/Class01 is static
    EclipseFlowerEditingDomain model = TestUtils.loadModel(diagramFile);
    JavaClass javaClass = (JavaClass) (TestUtils.getNamedElementsFromModel(model, "TC05/TC05_1/Class01")
            .get(0));
    Operation oper = javaClass.getOperation("oper1", null, null);
    assertEquals(true, oper.isStatic());

    // make Oper1 from the model unstatic
    model.getCommandStack()
            .execute(SetCommand.create(model, oper, UMLPackage.eINSTANCE.getFeature_IsStatic(), false));
    // model.save();
    TestUtils.syncronizeModel(diagramFile, "TC05");
    // check that the oper1 method from Class01 from source is no longer
    // static
    CompilationUnit compUnit = JavaTestUtils.loadJavaFile("TC05/TC05_1/Class01.java");
    TypeDeclaration masterClass = JavaSyncUtils.getMasterClass(compUnit);
    MethodDeclaration decl = (MethodDeclaration) (masterClass.getMethods()[0]);
    assertEquals(false, JavaSyncUtils.getFeatureValueFromJavaModifier(decl, JavaSyncUtils.MODIFIER_STATIC));
}

From source file:com.google.dart.java2dart.SyntaxTranslator.java

License:Open Source License

private static int numberOfConstructors(org.eclipse.jdt.core.dom.ASTNode node) {
    int count = 0;
    if (node instanceof org.eclipse.jdt.core.dom.TypeDeclaration) {
        org.eclipse.jdt.core.dom.TypeDeclaration typeDecl = (org.eclipse.jdt.core.dom.TypeDeclaration) node;
        for (org.eclipse.jdt.core.dom.MethodDeclaration methodDecl : typeDecl.getMethods()) {
            if (methodDecl.isConstructor()) {
                count++;//w ww  .ja  v a  2 s  .co m
            }
        }
        return count;
    }
    if (node instanceof EnumDeclaration) {
        EnumDeclaration enumDecl = (EnumDeclaration) node;
        for (Object child : (List<?>) enumDecl.bodyDeclarations()) {
            if (child instanceof org.eclipse.jdt.core.dom.MethodDeclaration) {
                org.eclipse.jdt.core.dom.MethodDeclaration methodDecl = (org.eclipse.jdt.core.dom.MethodDeclaration) child;
                if (methodDecl.isConstructor()) {
                    count++;
                }
            }
        }
        return count;
    }
    throw new UnsupportedOperationException("not implemented: " + node.getClass());
}

From source file:com.google.devtools.j2cpp.gen.CppImplementationGenerator.java

License:Open Source License

@Override
public void generate(TypeDeclaration node) {
    List<IMethodBinding> testMethods = null;
    if (Types.isJUnitTest(Types.getTypeBinding(node))) {
        testMethods = findTestMethods(node);
    }//  w  w  w  .  jav  a  2 s .  c om
    syncLineNumbers(node.getName()); // avoid doc-comment

    fieldHiders = HiddenFieldDetector.getFieldNameConflicts(node);
    if (node.isInterface()) {
        printStaticInterface(node);
    } else {
        String typeName = NameTable.getFullName(node);
        printf("class %s {\n\n", typeName);
        printStaticVars(Lists.newArrayList(node.getFields()));
        printProperties(node.getFields());
        printMethods(node);
        printObjCTypeMethod(node);

        println("}\n");

        // Generate main method, if declared.
        MethodDeclaration main = null;
        for (MethodDeclaration m : node.getMethods()) {
            if (isMainMethod(m)) {
                main = m;
                break;
            }
        }
        newline();
        if (main != null || (testMethods != null && Options.generateTestMain())) {
            printMainMethod(main, typeName, testMethods);
        }
    }
}