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

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

Introduction

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

Prototype

public Type getSuperclassType() 

Source Link

Document

Returns the superclass declared in this type declaration, or null if there is none (added in JLS3 API).

Usage

From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java

License:Open Source License

@Override
public boolean visit(TypeDeclaration node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }//from   w ww  . j  ava  2  s.  c  o  m
    if (node.getAST().apiLevel() >= JLS3) {
        printModifiers(node.modifiers());
    }
    this.fBuffer.append(node.isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$
    node.getName().accept(this);
    if (node.getAST().apiLevel() >= JLS3) {
        if (!node.typeParameters().isEmpty()) {
            this.fBuffer.append("<");//$NON-NLS-1$
            for (Iterator<TypeParameter> it = node.typeParameters().iterator(); it.hasNext();) {
                TypeParameter t = it.next();
                t.accept(this);
                if (it.hasNext()) {
                    this.fBuffer.append(",");//$NON-NLS-1$
                }
            }
            this.fBuffer.append(">");//$NON-NLS-1$
        }
    }
    this.fBuffer.append(" ");//$NON-NLS-1$
    if (node.getAST().apiLevel() >= JLS3) {
        if (node.getSuperclassType() != null) {
            this.fBuffer.append("extends ");//$NON-NLS-1$
            node.getSuperclassType().accept(this);
            this.fBuffer.append(" ");//$NON-NLS-1$
        }
        if (!node.superInterfaceTypes().isEmpty()) {
            this.fBuffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$NON-NLS-1$
            for (Iterator<Type> it = node.superInterfaceTypes().iterator(); it.hasNext();) {
                Type t = it.next();
                t.accept(this);
                if (it.hasNext()) {
                    this.fBuffer.append(", ");//$NON-NLS-1$
                }
            }
            this.fBuffer.append(" ");//$NON-NLS-1$
        }
    }
    this.fBuffer.append("{");//$NON-NLS-1$
    BodyDeclaration prev = null;
    for (Iterator<BodyDeclaration> it = node.bodyDeclarations().iterator(); it.hasNext();) {
        BodyDeclaration d = it.next();
        if (prev instanceof EnumConstantDeclaration) {
            // enum constant declarations do not include punctuation
            if (d instanceof EnumConstantDeclaration) {
                // enum constant declarations are separated by commas
                this.fBuffer.append(", ");//$NON-NLS-1$
            } else {
                // semicolon separates last enum constant declaration from
                // first class body declarations
                this.fBuffer.append("; ");//$NON-NLS-1$
            }
        }
        d.accept(this);
        prev = d;
    }
    this.fBuffer.append("}");//$NON-NLS-1$
    return false;
}

From source file:boa.datagen.util.Java7Visitor.java

License:Apache License

@Override
public boolean visit(TypeDeclaration node) {
    boa.types.Ast.Declaration.Builder b = boa.types.Ast.Declaration.newBuilder();
    //      b.setPosition(pos.build());
    b.setName(node.getName().getFullyQualifiedName());
    if (node.isInterface())
        b.setKind(boa.types.Ast.TypeKind.INTERFACE);
    else/*from   www  .  j  a  v  a2  s.co  m*/
        b.setKind(boa.types.Ast.TypeKind.CLASS);
    for (Object m : node.modifiers()) {
        if (((IExtendedModifier) m).isAnnotation())
            ((Annotation) m).accept(this);
        else
            ((org.eclipse.jdt.core.dom.Modifier) m).accept(this);
        b.addModifiers(modifiers.pop());
    }
    for (Object t : node.typeParameters()) {
        boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder();
        String name = ((TypeParameter) t).getName().getFullyQualifiedName();
        String bounds = "";
        for (Object o : ((TypeParameter) t).typeBounds()) {
            if (bounds.length() > 0)
                bounds += " & ";
            bounds += typeName((org.eclipse.jdt.core.dom.Type) o);
        }
        if (bounds.length() > 0)
            name = name + " extends " + bounds;
        tb.setName(getIndex(name));
        tb.setKind(boa.types.Ast.TypeKind.GENERIC);
        b.addGenericParameters(tb.build());
    }
    if (node.getSuperclassType() != null) {
        boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder();
        tb.setName(getIndex(typeName(node.getSuperclassType())));
        tb.setKind(boa.types.Ast.TypeKind.CLASS);
        b.addParents(tb.build());
    }
    for (Object t : node.superInterfaceTypes()) {
        boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder();
        tb.setName(getIndex(typeName((org.eclipse.jdt.core.dom.Type) t)));
        tb.setKind(boa.types.Ast.TypeKind.INTERFACE);
        b.addParents(tb.build());
    }
    for (Object d : node.bodyDeclarations()) {
        if (d instanceof FieldDeclaration) {
            fields.push(new ArrayList<boa.types.Ast.Variable>());
            ((FieldDeclaration) d).accept(this);
            for (boa.types.Ast.Variable v : fields.pop())
                b.addFields(v);
        } else if (d instanceof MethodDeclaration) {
            methods.push(new ArrayList<boa.types.Ast.Method>());
            ((MethodDeclaration) d).accept(this);
            for (boa.types.Ast.Method m : methods.pop())
                b.addMethods(m);
        } else if (d instanceof Initializer) {
            methods.push(new ArrayList<boa.types.Ast.Method>());
            ((Initializer) d).accept(this);
            for (boa.types.Ast.Method m : methods.pop())
                b.addMethods(m);
        } else {
            declarations.push(new ArrayList<boa.types.Ast.Declaration>());
            ((BodyDeclaration) d).accept(this);
            for (boa.types.Ast.Declaration nd : declarations.pop())
                b.addNestedDeclarations(nd);
        }
    }
    // TODO initializers
    // TODO enum constants
    // TODO annotation type members
    declarations.peek().add(b.build());
    return false;
}

From source file:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from  w w w .ja v a  2  s  .  c  o m
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:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(TypeDeclaration node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }/*from  w ww  . j  av  a2s .  c o m*/
    if (node.getAST().apiLevel() >= AST.JLS3) {
        printModifiers(node.modifiers());
    }
    this.buffer.append(node.isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$
    node.getName().accept(this);
    if (node.getAST().apiLevel() >= AST.JLS3) {
        if (!node.typeParameters().isEmpty()) {
            this.buffer.append("<");//$NON-NLS-1$
            for (Iterator it = node.typeParameters().iterator(); it.hasNext();) {
                TypeParameter t = (TypeParameter) it.next();
                t.accept(this);
                if (it.hasNext()) {
                    this.buffer.append(",");//$NON-NLS-1$
                }
            }
            this.buffer.append(">");//$NON-NLS-1$
        }
    }
    this.buffer.append(" ");//$NON-NLS-1$
    if (node.getAST().apiLevel() >= AST.JLS3) {
        if (node.getSuperclassType() != null) {
            this.buffer.append("extends ");//$NON-NLS-1$
            node.getSuperclassType().accept(this);
            this.buffer.append(" ");//$NON-NLS-1$
        }
        if (!node.superInterfaceTypes().isEmpty()) {
            this.buffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$NON-NLS-1$
            for (Iterator it = node.superInterfaceTypes().iterator(); it.hasNext();) {
                Type t = (Type) it.next();
                t.accept(this);
                if (it.hasNext()) {
                    this.buffer.append(", ");//$NON-NLS-1$
                }
            }
            this.buffer.append(" ");//$NON-NLS-1$
        }
    }
    this.buffer.append("{\n");//$NON-NLS-1$
    this.indent++;
    BodyDeclaration prev = null;
    for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext();) {
        BodyDeclaration d = (BodyDeclaration) it.next();
        if (prev instanceof EnumConstantDeclaration) {
            // enum constant declarations do not include punctuation
            if (d instanceof EnumConstantDeclaration) {
                // enum constant declarations are separated by commas
                this.buffer.append(", ");//$NON-NLS-1$
            } else {
                // semicolon separates last enum constant declaration from
                // first class body declarations
                this.buffer.append("; ");//$NON-NLS-1$
            }
        }
        d.accept(this);
    }
    this.indent--;
    printIndent();
    this.buffer.append("}\n");//$NON-NLS-1$
    return false;
}

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;//www . j a  v  a2 s .c om
            }
        }
    }

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

    return imported;
}

From source file:com.android.ide.eclipse.adt.internal.refactorings.extractstring.ReplaceStringsVisitor.java

License:Open Source License

/**
 * Walks up the node hierarchy to find the class (aka type) where this statement
 * is used and returns true if this class derives from android.content.Context.
 *//*from  w w  w.j a  v a 2 s  .  c  om*/
private boolean isClassDerivedFromContext(StringLiteral node) {
    TypeDeclaration clazz = findParentClass(node, TypeDeclaration.class);
    if (clazz != null) {
        // This is the class that the user is currently writing, so it can't be
        // a Context by itself, it has to be derived from it.
        return isAndroidContext(clazz.getSuperclassType());
    }
    return false;
}

From source file:com.bsiag.eclipse.jdt.java.formatter.linewrap.WrapPreparator.java

License:Open Source License

@Override
public boolean visit(TypeDeclaration node) {
    Type superclassType = node.getSuperclassType();
    if (superclassType != null) {
        this.wrapParentIndex = this.tm.lastIndexIn(node.getName(), -1);
        this.wrapGroupEnd = this.tm.lastIndexIn(superclassType, -1);
        this.wrapIndexes.add(this.tm.firstIndexBefore(superclassType, TokenNameextends));
        this.wrapIndexes.add(this.tm.firstIndexIn(superclassType, -1));
        handleWrap(this.options.alignment_for_superclass_in_type_declaration, PREFERRED);
    }/*w  w w.j a  v a2  s  .c  om*/

    List<Type> superInterfaceTypes = node.superInterfaceTypes();
    if (!superInterfaceTypes.isEmpty()) {
        int implementsToken = node.isInterface() ? TokenNameextends : TokenNameimplements;
        this.wrapParentIndex = this.tm.lastIndexIn(node.getName(), -1);
        this.wrapGroupEnd = this.tm.lastIndexIn(superInterfaceTypes.get(superInterfaceTypes.size() - 1), -1);
        this.wrapIndexes.add(this.tm.firstIndexBefore(superInterfaceTypes.get(0), implementsToken));
        for (Type type : superInterfaceTypes)
            this.wrapIndexes.add(this.tm.firstIndexIn(type, -1));
        handleWrap(this.options.alignment_for_superinterfaces_in_type_declaration, PREFERRED);
    }

    if (this.options.align_type_members_on_columns)
        this.fieldAligner.prepareAlign(node.bodyDeclarations());

    return true;
}

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

License:Open Source License

@Override
public Object getValueFeatureValue(Object element, Object feature, Object correspondingValue) {
    if (CodeSyncPackage.eINSTANCE.getCodeSyncElement_Name().equals(feature)) {
        return getLabel(element);
    }/*from   w  w  w.  ja va 2  s.  co  m*/
    if (CodeSyncPackage.eINSTANCE.getCodeSyncElement_Type().equals(feature)) {
        if (element instanceof TypeDeclaration) {
            if (((TypeDeclaration) element).isInterface()) {
                return INTERFACE;
            }
            return CLASS;
        }
        if (element instanceof EnumDeclaration) {
            return ENUM;
        }
        return ANNOTATION;
    }
    if (AstCacheCodePackage.eINSTANCE.getClass_SuperClasses().equals(feature)) {
        if (element instanceof TypeDeclaration) {
            TypeDeclaration type = (TypeDeclaration) element;
            if (type.getSuperclassType() != null) {
                return Collections.singletonList(getStringFromType(type.getSuperclassType()));
            } else {
                return Collections.emptyList();
            }
        }
        return Collections.emptyList();
    }
    if (AstCacheCodePackage.eINSTANCE.getClass_SuperInterfaces().equals(feature)) {
        return Collections.emptyList();
    }
    return super.getValueFeatureValue(element, feature, correspondingValue);
}

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from ww w  . j av  a  2  s  .  c  om
protected void setASTFeatureValue(EStructuralFeature feature, CompilationUnit astElement, Object value)
        throws CodeSyncException {
    if (astElement == null)
        throw new IllegalArgumentException("astElement null ");
    AST ast = astElement.getAST();
    TypeDeclaration masterClass = JavaSyncUtils.getMasterClass(astElement);
    switch (feature.getFeatureID()) {
    case UMLPackage.CLASSIFIER__GENERALIZATION:
        List<Generalization> listGeneralization = (List<Generalization>) value;
        if (listGeneralization.size() > 1)
            throw new IllegalArgumentException("setting more than one superclass ");
        else if (listGeneralization.size() == 1) {
            if (listGeneralization.get(0).getGeneral() == null)
                throw new IllegalArgumentException("generalization does not have attached a superclass");
            // This is a little hack until we will support parameterizable types.
            // The algorithm automatically updates every feature which doesn't work here because it will try to create a simpleType from Class<T1,T2...> 
            String newSuperClass = listGeneralization.get(0).getGeneral().getName();
            String oldSuperClass = masterClass.getSuperclassType() == null ? null
                    : masterClass.getSuperclassType().toString();
            if (!newSuperClass.equals(oldSuperClass)) {
                try {
                    parentForwardJavaSrcDir_Files
                            .createImportDeclarationIfNeeded((Type) listGeneralization.get(0).getGeneral());
                } catch (IllegalPathException ex) {
                    ex.customizeIllegalPathException(listGeneralization.get(0));
                    throw ex;
                }
                masterClass.setSuperclassType(JavaSyncUtils.getJavaTypeFromString(ast, newSuperClass, false));
            }
        } else if (listGeneralization.isEmpty())
            masterClass.setSuperclassType(null);
        break;
    default:
        super.setASTFeatureValue(feature, astElement, value);
    }
}

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

License:Open Source License

@Override
public boolean visit(org.eclipse.jdt.core.dom.TypeDeclaration node) {
    ITypeBinding binding = node.resolveBinding();
    // prepare name
    SimpleIdentifier name;/*from   ww  w. j a  v a 2 s .c  o m*/
    {
        name = translateSimpleName(node.getName());
        if (binding != null) {
            ITypeBinding declaringClass = binding.getDeclaringClass();
            if (declaringClass != null) {
                context.putInnerClassName(name);
                name.setToken(token(TokenType.IDENTIFIER, declaringClass.getName() + "_" + name.getName()));
            }
        }
    }
    // interface
    Token abstractToken = null;
    if (node.isInterface() || org.eclipse.jdt.core.dom.Modifier.isAbstract(node.getModifiers())) {
        abstractToken = token(Keyword.ABSTRACT);
    }
    // type parameters
    TypeParameterList typeParams = null;
    {
        List<TypeParameter> typeParameters = Lists.newArrayList();
        List<?> javaTypeParameters = node.typeParameters();
        if (!javaTypeParameters.isEmpty()) {
            for (Iterator<?> I = javaTypeParameters.iterator(); I.hasNext();) {
                org.eclipse.jdt.core.dom.TypeParameter javaTypeParameter = (org.eclipse.jdt.core.dom.TypeParameter) I
                        .next();
                TypeParameter typeParameter = translate(javaTypeParameter);
                typeParameters.add(typeParameter);
            }
            typeParams = typeParameterList(typeParameters);
        }
    }
    // extends
    ExtendsClause extendsClause = null;
    if (node.getSuperclassType() != null) {
        TypeName superType = translate(node.getSuperclassType());
        extendsClause = extendsClause(superType);
    }
    // implements
    ImplementsClause implementsClause = null;
    if (!node.superInterfaceTypes().isEmpty()) {
        List<TypeName> interfaces = Lists.newArrayList();
        for (Object javaInterface : node.superInterfaceTypes()) {
            interfaces.add((TypeName) translate((org.eclipse.jdt.core.dom.ASTNode) javaInterface));
        }
        implementsClause = implementsClause(interfaces);
    }
    // members
    List<ClassMember> members = translateBodyDeclarations(node.bodyDeclarations());
    for (ClassMember member : members) {
        if (member instanceof ConstructorDeclaration) {
            ConstructorDeclaration constructor = (ConstructorDeclaration) member;
            constructor.setReturnType(name);
        }
    }
    //
    ClassDeclaration classDeclaration = new ClassDeclaration(translateJavadoc(node), null, abstractToken, null,
            name, typeParams, extendsClause, null, implementsClause, null, members, null);
    context.putNodeBinding(classDeclaration, binding);
    context.putNodeTypeBinding(classDeclaration, binding);
    context.putNodeTypeBinding(name, binding);
    return done(classDeclaration);
}