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

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

Introduction

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

Prototype

boolean isInterface

To view the source code for org.eclipse.jdt.core.dom TypeDeclaration isInterface.

Click Source Link

Document

true for an interface, false for a class.

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);
    }/* w w w  . java2s . 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  .ja va 2  s  . c  om*/
        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.gems.resources.ast.Visitor.java

@Override
public boolean visit(TypeDeclaration node) {
    int beginLine = beginLine(node);
    int endLine = cu.getLineNumber(node.getStartPosition() + node.getLength());
    int beginColumn = beginColunm(node);
    int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength());

    isInterface = node.isInterface();

    if (isInterface) {
        languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName() + INTERFACE, beginLine,
                endLine, beginColumn, endColumn));
    } else {/* w ww.  ja v  a2 s .com*/
        languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName() + CLASS, beginLine,
                endLine, beginColumn, endColumn));
    }

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

    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:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

/**
 * Generated the DECLARES relations between a type and and nested types, the
 * EXTENDS relations, and the IMPLEMENTS relation
 *//*w  w w.j a v  a  2 s.  c o  m*/
@Override
public boolean visit(final TypeDeclaration pNode) {
    final ITypeBinding lBinding = pNode.resolveBinding();

    if (ASTCrawler.checkForNull(lBinding))
        return false;

    try {
        this.saveTypeRelation(lBinding);

        // Add Declaration relations if this is a local or nested class
        if (lBinding.isLocal() || lBinding.isAnonymous())
            this.aDB.addRelation(this.aCurrMethod, Relation.DECLARES_TYPE, this.aCurrType);
        else if (lBinding.isNested())
            this.aDB.addRelation(this.aCurrTypeReminder.peek(), Relation.DECLARES_TYPE, this.aCurrType);

        // Find superclass
        if (!pNode.isInterface()) {
            final ITypeBinding lSuperBinding = lBinding.getSuperclass();
            if (lSuperBinding != null) {
                final IElement lSuperClass = ASTCrawler.convertBinding(lSuperBinding);
                this.aDB.addElement(lSuperClass, lSuperBinding.getModifiers());
                this.aDB.addRelationAndTranspose(this.aCurrType, Relation.EXTENDS_CLASS, lSuperClass);
            }
        }

        // Find interfaces.
        final ITypeBinding lInterfaceBindings[] = lBinding.getInterfaces();
        for (final ITypeBinding element : lInterfaceBindings) {
            final IElement lInterface = ASTCrawler.convertBinding(element);
            this.aDB.addElement(lInterface, element.getModifiers() | ASTCrawler.ABSTRACT_FLAG);
            if (pNode.isInterface())
                this.aDB.addRelationAndTranspose(this.aCurrType, Relation.EXTENDS_INTERFACES, lInterface);
            else
                this.aDB.addRelationAndTranspose(this.aCurrType, Relation.IMPLEMENTS_INTERFACE, lInterface);
        }
    } catch (final Exception pException) {
        ProblemManager.reportException(pException);
    }

    return true;
}

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  .jav  a2  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:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(TypeDeclaration node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }// www .ja  v a  2 s .co  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.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 .  co  m*/

    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.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java

License:Open Source License

@Override
public boolean visit(TypeDeclaration node) {
    if (node.getName().getStartPosition() == -1)
        return true; // this is a fake type created by parsing in class body mode

    handleToken(node.getName(), TokenNameIdentifier, true, false);

    List<TypeParameter> typeParameters = node.typeParameters();
    handleTypeParameters(typeParameters);

    if (!node.isInterface() && !node.superInterfaceTypes().isEmpty()) {
        // fix for: class A<E> extends ArrayList<String>implements Callable<String>
        handleToken(node.getName(), TokenNameimplements, true, false);
    }//w  w w .  java 2 s . c o m

    handleToken(node.getName(), TokenNameLBRACE,
            this.options.insert_space_before_opening_brace_in_type_declaration, false);
    handleCommas(node.superInterfaceTypes(), this.options.insert_space_before_comma_in_superinterfaces,
            this.options.insert_space_after_comma_in_superinterfaces);
    return true;
}

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

License:Open Source License

@Override
protected Type createAndAddNewModelElement(Collection<Type> modelElementCollection,
        FileAndAST<CompilationUnit> astElement) {
    Package unknownTypesPackage = getParent().getUnknownTypesPackage();
    if (unknownTypesPackage == null)
        throw new IllegalArgumentException("unknownTypesPackage is null");

    if (astElement.getAstElement().types().size() > 0) {
        JavaTypeCreation typeCreation = null;
        TypeDeclaration typeDeclaration = JavaSyncUtils.getMasterClass(astElement.getAstElement());
        String typeName = typeDeclaration.getName().toString();
        String fullyQualifiedPackageName = "";
        if (astElement.getAstElement().getPackage() != null)
            fullyQualifiedPackageName = ((PackageDeclaration) astElement.getAstElement().getPackage()).getName()
                    .toString();/*from w  ww. j  a v  a  2 s  . c o  m*/

        if (typeDeclaration.isInterface())
            typeCreation = new JavaTypeCreation(JavaTypeCreation.INTERFACE_ONLY);
        else
            typeCreation = new JavaTypeCreation(JavaTypeCreation.CLASS_ONLY);
        return SyncUtils.getTypeFromUnknownTypesOrCreateInSrcDir(typeName, fullyQualifiedPackageName,
                typeCreation, unknownTypesPackage, modelElementCollection);
    } else {
        // if there are no types, create class element with file name
        // this will be a Class instance of no Interface with the same path would be recovered for UT 
        String typeName = astElement.getFileName();
        String fullyQualifiedPackageName = SyncUtils
                .getFullyQualifiedPackageName(this.getParent().getSrcDirPackage(), astElement.getFile());
        JavaTypeCreation typeCreation = new JavaTypeCreation(JavaTypeCreation.NO_DATA_TYPE);
        return SyncUtils.getTypeFromUnknownTypesOrCreateInSrcDir(typeName, fullyQualifiedPackageName,
                typeCreation, unknownTypesPackage, modelElementCollection);
    }
}