Example usage for org.eclipse.jdt.core.dom Type toString

List of usage examples for org.eclipse.jdt.core.dom Type toString

Introduction

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

Prototype

@Override
public final String toString() 

Source Link

Document

Returns a string representation of this node suitable for debugging purposes only.

Usage

From source file:com.android.icu4j.srcgen.RunWithAnnotator.java

License:Apache License

private boolean annotateTypeDeclaration(CompilationUnit cu, ASTRewrite rewrite, TypeDeclaration typeDeclaration,
        boolean topLevelClass, boolean imported) {

    int modifiers = typeDeclaration.getModifiers();
    if ((topLevelClass || Modifier.isStatic(modifiers)) && Modifier.isPublic(modifiers)
            && !Modifier.isAbstract(modifiers)) {
        Type superClassType = typeDeclaration.getSuperclassType();
        if (superClassType != null) {
            String name = superClassType.toString();
            String runnerClass = BASE_CLASS_2_RUNNER_CLASS.get(name);
            if (runnerClass != null) {
                addRunWithAnnotation(cu, rewrite, typeDeclaration, runnerClass, imported);
                imported = true;//w ww .  j  a  v a2s.  co m
            }
        }
    }

    for (TypeDeclaration innerClass : typeDeclaration.getTypes()) {
        imported = annotateTypeDeclaration(cu, rewrite, innerClass, false, imported);
    }

    return imported;
}

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

License:Open Source License

protected void verifySameSuperClassFor(Class classUml, CompilationUnit classJava) {
    Assert.assertNotNull(classUml);/* w  ww  . ja  v a2  s .  c o m*/
    Assert.assertNotNull(classJava);

    Assert.assertFalse("model class has more than one superclass", classUml.getGeneralizations().size() > 1);

    Type tempType = JavaSyncUtils.getMasterClass(classJava).getSuperclassType();
    String javaSuperClass = (tempType != null) ? tempType.toString() : null;
    String umlSuperClass = null;
    if (classUml.getGeneralizations().size() == 1) {
        Generalization generalization = classUml.getGeneralizations().get(0);
        Assert.assertNotNull("generalization does not have attached a superclass", generalization.getGeneral());
        umlSuperClass = generalization.getGeneral().getName();
    }

    Assert.assertTrue(umlSuperClass + " different superclass from " + javaSuperClass,
            safeEquals(umlSuperClass, javaSuperClass));
}

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

License:Open Source License

protected void printMessageForSuperClass(CompilationUnit classJava, Class classUml) {
    Type tempType = JavaSyncUtils.getMasterClass(classJava).getSuperclassType();
    String javaSuperClass = (tempType != null) ? tempType.toString() : null;
    String umlSuperClass = null;//from  w  w w .j  av  a2 s.c om
    Generalization gen = null;
    if (classUml.getGeneralizations().size() == 1) {
        gen = classUml.getGeneralizations().get(0);
        if (gen.getGeneral() != null)
            umlSuperClass = gen.getGeneral().getName();
    }
    print("  superclass [" + umlSuperClass + "] = [" + javaSuperClass);
}

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

License:Open Source License

protected void printMessageForSuperInterface(Type interfaceJava, Interface interfaceUml) {
    print("  superinterface [" + interfaceUml.getName() + "] = [" + interfaceJava.toString());
}

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

License:Open Source License

@Override
protected HashMap<String, Type> getInterfacesFor(CompilationUnit classJava) {
    HashMap<String, Type> hashMapJava = new HashMap<String, Type>();
    for (Type type : (List<Type>) JavaSyncUtils.getMasterClass(classJava).superInterfaceTypes())
        hashMapJava.put(type.toString(), type);
    return hashMapJava;
}

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

License:Open Source License

public SimpleType getInterfaceType(TypeDeclaration class_, String interfaceName) {
    for (Type interfaceType : (List<Type>) class_.superInterfaceTypes())
        if (interfaceName.equals(interfaceType.toString()))
            return (SimpleType) interfaceType;
    throw new IllegalArgumentException(
            "Could not find interface " + interfaceName + " in class " + class_.getName());
}

From source file:com.crispico.flower.mp.codesync.code.java.adapter.JavaAbstractAstNodeModelAdapter.java

License:Open Source License

protected String getStringFromType(Type type) {
    if (type == null) {
        return null;
    }/*from  ww  w.  j  a  v a  2  s  . c  o  m*/
    return type.toString();
}

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

License:Open Source License

/**
 * @flowerModelElementId _zVs8jZiOEd6aNMdNFvR5WQ
 *///from ww w  .j  a  va2 s  . co m
public static String getReturnTypeAsString(BodyDeclaration bd) {
    if (bd instanceof FieldDeclaration)
        return ((FieldDeclaration) bd).getType().toString();
    else if (bd instanceof MethodDeclaration) {
        //constructors in java have null returning type
        Type returnType = ((MethodDeclaration) bd).getReturnType2();
        return returnType == null ? null : returnType.toString();
    } else {
        throw new IllegalArgumentException("Expecting method or field declaration: " + bd);
    }
}

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

License:Open Source License

@Override
protected Object getFeatureValueFromAST(EStructuralFeature feature, CompilationUnit astElement) {
    if (astElement == null)
        throw new IllegalArgumentException("astElement is null");
    String typeName = null;/*from  w ww. ja v a2  s  .c om*/
    ReversePackage_JavaTypes reversePackage_JavaTypes = parentReverse;

    switch (feature.getFeatureID()) {
    case UMLPackage.CLASSIFIER__GENERALIZATION:
        List<Generalization> listGeneralizations = new ArrayList<Generalization>();
        Type superType = JavaSyncUtils.getMasterClass(astElement).getSuperclassType();
        typeName = superType == null ? null : superType.toString();
        if (typeName != null) {
            JavaTypeCreation typeCreation = new JavaTypeCreation(JavaTypeCreation.CLASS_ONLY);
            Class superClass = (Class) SyncUtils.getTypeOrCreateInUnknownTypes(typeName, typeCreation,
                    reversePackage_JavaTypes, currentElement);
            Generalization generalization = CodeSyncJavaFactory.eINSTANCE.createJavaGeneralization();
            generalization.setGeneral(superClass);
            listGeneralizations.add(generalization);
        }
        return listGeneralizations;
    case UMLPackage.CLASSIFIER__IS_ABSTRACT:
        return JavaSyncUtils.getFeatureValueFromJavaModifier(astElement, JavaSyncUtils.MODIFIER_ABSTRACT);
    default:
        return super.getFeatureValueFromAST(feature, astElement);
    }
}

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

License:Open Source License

@Override
protected Object getLookupKeyForAstElement(Type e) throws CodeSyncException {
    if (e == null)
        return null;
    // We give the reversePackage_Types parameter because the signature includes the f.q. type name, and this can be computed 
    // from the imports of the CompilationUnit or from sibling files in the current package
    @SuppressWarnings("unchecked")
    ReversePackage_Type reversePackage_Types = parentReverse.parentReverse;
    return SyncUtils.getFullyQualifiedNameForAstType(e.toString(), reversePackage_Types);
}