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

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

Introduction

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

Prototype

public SimpleName getName() 

Source Link

Document

Returns the name of the type declared in this type declaration.

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);
    }/*ww w .j  a va 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   w ww.  j a  v  a  2  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:br.uff.ic.mergeguider.javaparser.DepVisitor.java

@Override
public boolean visit(TypeDeclaration node) {

    //Treating class name
    String className;//from   w  w  w  .j ava2 s. co m
    PackageDeclaration aPackage = cu.getPackage();
    if (aPackage != null) {
        String packageName = aPackage.getName().getFullyQualifiedName();
        className = packageName + "." + node.getName().getIdentifier();
    } else {
        className = null;
    }

    classLanguageContructs = new ClassLanguageContructs(className, path);

    classLanguageConstructsList.add(classLanguageContructs);

    simpleNames = new ArrayList<>();
    simpleNamesList.add(simpleNames);

    //Treating location and language construct
    Location location;

    int elementLineBegin = cu.getLineNumber(node.getStartPosition());
    int elementLineEnd = cu.getLineNumber(node.getStartPosition() + node.getLength());
    int elementColumnBegin = cu.getColumnNumber(node.getStartPosition());
    int elementColumnEnd = cu.getColumnNumber(node.getStartPosition() + node.getLength());

    location = new Location(elementLineBegin, elementLineEnd, elementColumnBegin, elementColumnEnd);

    MyTypeDeclaration typeDeclaration = new MyTypeDeclaration(node, location);

    if (!classLanguageConstructsList.isEmpty()) {
        classLanguageConstructsList.get(classLanguageConstructsList.size() - 1).getTypeDeclarations()
                .add(typeDeclaration);
    }

    return true;
}

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

License:Open Source License

@Override
public boolean visit(TypeDeclaration type) {
    if (!Modifier.isPublic(type.getModifiers())) {
        // non-public types cannot be (or have nested) components
        if (errorLevel.isNone())
            return false;

        Annotation annotation = findComponentAnnotation(type);
        if (annotation != null)
            reportProblem(annotation, null, problems,
                    NLS.bind(Messages.AnnotationProcessor_invalidComponentImplementationClass,
                            type.getName().getIdentifier()),
                    type.getName().getIdentifier());

        return true;
    }/*from   w w  w.j  a v a 2s  . c om*/

    Annotation annotation = findComponentAnnotation(type);
    if (annotation != null) {
        if (type.isInterface() || Modifier.isAbstract(type.getModifiers())
                || (!type.isPackageMemberTypeDeclaration() && !isNestedPublicStatic(type))
                || !hasDefaultConstructor(type)) {
            // interfaces, abstract types, non-static/non-public nested types, or types with no default constructor cannot be components
            reportProblem(annotation, null, problems,
                    NLS.bind(Messages.AnnotationProcessor_invalidComponentImplementationClass,
                            type.getName().getIdentifier()),
                    type.getName().getIdentifier());
        } else {
            ITypeBinding typeBinding = type.resolveBinding();
            if (typeBinding == null) {
                if (debug.isDebugging())
                    debug.trace(String.format("Unable to resolve binding for type: %s", type)); //$NON-NLS-1$
            } else {
                IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding();
                if (annotationBinding == null) {
                    if (debug.isDebugging())
                        debug.trace(String.format("Unable to resolve binding for annotation: %s", annotation)); //$NON-NLS-1$
                } else {
                    IDSModel model = processComponent(type, typeBinding, annotation, annotationBinding,
                            problems);
                    models.add(model);
                }
            }
        }
    }

    return true;
}

From source file:ch.acanda.eclipse.pmd.java.resolution.design.UseUtilityClassQuickFix.java

License:Open Source License

@SuppressWarnings("unchecked")
private void addPrivateConstructor(final TypeDeclaration typeDeclaration, final ASTRewrite rewrite) {
    final AST ast = typeDeclaration.getAST();
    final MethodDeclaration constructor = (MethodDeclaration) ast.createInstance(MethodDeclaration.class);
    constructor.setConstructor(true);/*from  w  ww.  j  a  va  2 s .co m*/

    final Modifier modifier = (Modifier) ast.createInstance(Modifier.class);
    modifier.setKeyword(ModifierKeyword.PRIVATE_KEYWORD);
    constructor.modifiers().add(modifier);

    constructor.setName(ASTUtil.copy(typeDeclaration.getName()));

    final Block body = (Block) ast.createInstance(Block.class);
    constructor.setBody(body);

    final ListRewrite statementRewrite = rewrite.getListRewrite(body, Block.STATEMENTS_PROPERTY);
    final ASTNode comment = rewrite.createStringPlaceholder("// hide constructor of utility class",
            ASTNode.EMPTY_STATEMENT);
    statementRewrite.insertFirst(comment, null);

    final int position = findConstructorPosition(typeDeclaration);
    final ListRewrite bodyDeclarationRewrite = rewrite.getListRewrite(typeDeclaration,
            TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
    bodyDeclarationRewrite.insertAt(constructor, position, null);
}

From source file:ch.uzh.ifi.seal.changedistiller.treedifferencing.Node.java

License:Apache License

/**
 * Eq./*from w ww.j  a  v  a2s .  c  om*/
 * 
 * @param node
 *            the node
 * @return true, if successful
 */
public boolean eq(Node node) {
    if (getMethodDeclaration() != null && node.getMethodDeclaration() != null && //
            node.getEntity().getType().isMethod() && getEntity().getType().isMethod()) {
        String myClassName = null;
        String yourClassName = null;
        Object o1 = getMethodDeclaration().getParent();
        Object o2 = node.getMethodDeclaration().getParent();
        while (!(o1 instanceof TypeDeclaration)) {
            o1 = ((ASTNode) o1).getParent();
        }
        while (!(o2 instanceof TypeDeclaration)) {
            o2 = ((ASTNode) o2).getParent();
        }
        if (o1 instanceof TypeDeclaration && o2 instanceof TypeDeclaration) {
            TypeDeclaration myClassDecl = (TypeDeclaration) o1;
            TypeDeclaration yourClassDecl = (TypeDeclaration) o2;
            myClassName = myClassDecl.getName().getFullyQualifiedName();
            yourClassName = yourClassDecl.getName().getFullyQualifiedName();
        }
        String myNode = getMethodDeclaration().getName().getFullyQualifiedName();
        String yourNode = node.getMethodDeclaration().getName().getFullyQualifiedName();
        int bgn17 = getMethodDeclaration().getStartPosition();
        int end17 = getMethodDeclaration().getLength();
        int bgn14 = node.getMethodDeclaration().getStartPosition();
        int end14 = node.getMethodDeclaration().getLength();
        if (bgn17 == bgn14 && end17 == end14 && myNode.equals(yourNode) && myClassName.equals(yourClassName)) {
            return true;
        } else {
            return false;
        }
    }
    if (this.getValue().equals(node.getValue()) && //
            this.getLabel().equals(node.getLabel()) && //
            this.getEntity().getSourceRange().equals(node.getEntity().getSourceRange())) {
        return true;
    }
    return false;
}

From source file:changetypes.ASTVisitorAtomicChange.java

License:Open Source License

public boolean visit(TypeDeclaration node) {
    ITypeBinding itb = node.resolveBinding();
    this.itbStack.push(itb);
    try {/*from w w  w.j  a v  a 2 s.  c o m*/
        this.facts.add(Fact.makeTypeFact(getQualifiedName(itb), getSimpleName(itb), itb.getPackage().getName(),
                itb.isInterface() ? "interface" : "class"));
    } catch (Exception localException1) {
        System.err.println("Cannot resolve bindings for class " + node.getName().toString());
    }
    ITypeBinding localITypeBinding1;
    ITypeBinding i2;
    try {
        ITypeBinding itb2 = itb.getSuperclass();
        if (itb.getSuperclass() != null) {
            this.facts.add(Fact.makeSubtypeFact(getQualifiedName(itb2), getQualifiedName(itb)));
            this.facts.add(Fact.makeExtendsFact(getQualifiedName(itb2), getQualifiedName(itb)));
        }
        ITypeBinding[] arrayOfITypeBinding;
        int i;
        if (node.isInterface()) {
            i = (arrayOfITypeBinding = itb.getInterfaces()).length;
            for (localITypeBinding1 = 0; localITypeBinding1 < i; localITypeBinding1++) {
                ITypeBinding i2 = arrayOfITypeBinding[localITypeBinding1];
                this.facts.add(Fact.makeSubtypeFact(getQualifiedName(i2), getQualifiedName(itb)));
                this.facts.add(Fact.makeExtendsFact(getQualifiedName(i2), getQualifiedName(itb)));
            }
        } else {
            i = (arrayOfITypeBinding = itb.getInterfaces()).length;
            for (localITypeBinding1 = 0; localITypeBinding1 < i; localITypeBinding1++) {
                i2 = arrayOfITypeBinding[localITypeBinding1];
                this.facts.add(Fact.makeSubtypeFact(getQualifiedName(i2), getQualifiedName(itb)));
                this.facts.add(Fact.makeImplementsFact(getQualifiedName(i2), getQualifiedName(itb)));
            }
        }
    } catch (Exception localException2) {
        System.err.println("Cannot resolve super class bindings for class " + node.getName().toString());
    }
    Object localObject;
    try {
        localITypeBinding1 = (localObject = itb.getDeclaredFields()).length;
        for (i2 = 0; i2 < localITypeBinding1; i2++) {
            IVariableBinding ivb = localObject[i2];
            String visibility = getModifier(ivb);
            String fieldStr = ivb.toString();

            String[] tokens = fieldStr.split(" ");
            String[] arrayOfString1;
            int k = (arrayOfString1 = tokens).length;
            for (int j = 0; j < k; j++) {
                String token = arrayOfString1[j];
                if (this.allowedFieldMods_.contains(token)) {
                    this.facts.add(Fact.makeFieldModifierFact(getQualifiedName(ivb), token));
                }
            }
            this.facts.add(Fact.makeFieldFact(getQualifiedName(ivb), ivb.getName(), getQualifiedName(itb),
                    visibility));
            if (!ivb.getType().isParameterizedType()) {
                this.facts.add(Fact.makeFieldTypeFact(getQualifiedName(ivb), getQualifiedName(ivb.getType())));
            } else {
                this.facts.add(Fact.makeFieldTypeFact(getQualifiedName(ivb), makeParameterizedName(ivb)));
            }
        }
    } catch (Exception localException3) {
        System.err.println("Cannot resolve field bindings for class " + node.getName().toString());
    }
    try {
        ITypeBinding localITypeBinding2 = (localObject = node.getTypes()).length;
        for (i2 = 0; i2 < localITypeBinding2; i2++) {
            TypeDeclaration t = localObject[i2];
            ITypeBinding intb = t.resolveBinding();
            this.facts.add(Fact.makeTypeInTypeFact(getQualifiedName(intb), getQualifiedName(itb)));
        }
    } catch (Exception localException4) {
        System.err.println("Cannot resolve inner type bindings for class " + node.getName().toString());
    }
    return true;
}

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from w  ww  .  j  a  va2  s  .  co  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);
    }/*ww w .ja  va2 s  . c  om*/
    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.bsiag.eclipse.jdt.java.formatter.LineBreaksPreparator.java

License:Open Source License

public boolean visit(TypeDeclaration node) {
    handleBodyDeclarations(node.bodyDeclarations());

    if (node.getName().getStartPosition() == -1)
        return true; // this is a fake type created by parsing in class body mode

    breakLineBefore(node);//from ww w. jav  a  2s  .  co m

    handleBracedCode(node, node.getName(), this.options.brace_position_for_type_declaration,
            this.options.indent_body_declarations_compare_to_type_header,
            this.options.insert_new_line_in_empty_type_declaration);

    this.declarationModifierVisited = false;
    return true;
}