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

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

Introduction

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

Prototype

public final int getNodeType() 

Source Link

Document

Returns an integer value identifying the type of this concrete AST node.

Usage

From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java

License:Apache License

/** Visitor method for {@link QualifiedType}s. */
@Override// ww  w .  j av  a 2s.  c o  m
public boolean visit(QualifiedType node) {
    sync(node);
    builder.open(plusFour);
    // Collapse chains of "." operators.
    ArrayDeque<SimpleName> stack = new ArrayDeque<>();
    Type qualifier;
    while (true) {
        stack.add(node.getName());
        qualifier = node.getQualifier();
        if (qualifier.getNodeType() != ASTNode.QUALIFIED_TYPE) {
            break;
        }
        node = (QualifiedType) qualifier;
    }
    qualifier.accept(this);
    do {
        builder.breakOp();
        token(".");
        visit(stack.removeLast());
    } while (!stack.isEmpty());
    builder.close();
    return false;
}

From source file:de.akra.idocit.java.services.ReflectionHelper.java

License:Apache License

/**
 * Returns the identifier from the {@link Type} depending on the containing type.
 * //w  w w.j  a va  2  s.com
 * @param type
 *            [SOURCE]
 * 
 * @return [OBJECT]
 * @see Type
 * @thematicgrid Extracting Operations
 */
public static String extractIdentifierFrom(Type type) {
    switch (type.getNodeType()) {
    case ASTNode.PRIMITIVE_TYPE: {
        PrimitiveType primitiveType = (PrimitiveType) type;
        return primitiveType.getPrimitiveTypeCode().toString();
    }
    case ASTNode.ARRAY_TYPE: {
        ArrayType arrayType = (ArrayType) type;
        String name = extractIdentifierFrom(arrayType.getElementType());
        StringBuffer identifier = new StringBuffer(name);

        for (int i = 0; i < arrayType.getDimensions(); i++) {
            identifier.append("[]");
        }
        return identifier.toString();
    }
    case ASTNode.SIMPLE_TYPE: {
        SimpleType simpleType = (SimpleType) type;
        return simpleType.getName().getFullyQualifiedName();
    }
    case ASTNode.QUALIFIED_TYPE: {
        QualifiedType qType = (QualifiedType) type;
        return extractIdentifierFrom(qType.getQualifier()) + "." + qType.getName().getIdentifier();
    }
    case ASTNode.PARAMETERIZED_TYPE: {
        ParameterizedType paramType = (ParameterizedType) type;
        StringBuffer identifier = new StringBuffer(extractIdentifierFrom(paramType.getType()));
        identifier.append('<');

        @SuppressWarnings("unchecked")
        Iterator<Type> iterTypeArgs = (Iterator<Type>) paramType.typeArguments().iterator();
        while (iterTypeArgs.hasNext()) {
            Type typeArg = iterTypeArgs.next();
            identifier.append(extractIdentifierFrom(typeArg));
            if (iterTypeArgs.hasNext()) {
                identifier.append(',');
            }
        }

        identifier.append('>');
        return identifier.toString();
    }
    case ASTNode.WILDCARD_TYPE: {
        WildcardType wildcard = (WildcardType) type;
        String identifier = "? extends ";
        if (!wildcard.isUpperBound()) {
            identifier = "? super ";
        }
        return identifier + extractIdentifierFrom(wildcard.getBound());
    }
    }
    return SignatureElement.ANONYMOUS_IDENTIFIER;
}

From source file:org.autorefactor.refactoring.ASTBuilder.java

License:Open Source License

private Type copyType(final Type type) {
    switch (type.getNodeType()) {
    case ARRAY_TYPE:
        final ArrayType arrayType = (ArrayType) type;
        return ast.newArrayType(copyType(arrayType.getComponentType()), arrayType.getDimensions());

    case PRIMITIVE_TYPE:
        final Code code = ((PrimitiveType) type).getPrimitiveTypeCode();
        return ast.newPrimitiveType(code);

    case QUALIFIED_TYPE:
        return toType(ast, type.resolveBinding().getQualifiedName());

    case SIMPLE_TYPE:
        final SimpleType sType = (SimpleType) type;
        return ast.newSimpleType(copy(sType.getName()));
    }/*from  w  ww  . j  av a  2 s . c om*/

    throw new NotImplementedException(null, "Unknown type for type " + type);
}

From source file:org.autorefactor.refactoring.rules.UseMultiCatchRefactoring.java

License:Open Source License

private Binding resolveBinding(CatchClause catchClause) {
    SingleVariableDeclaration svd = catchClause.getException();
    Type type = svd.getType();
    switch (type.getNodeType()) {
    case SIMPLE_TYPE:
        return new SingleBinding(type.resolveBinding());

    case UNION_TYPE:
        List<Type> types = types((UnionType) type);
        ITypeBinding[] typeBindings = new ITypeBinding[types.size()];
        for (int j = 0; j < types.size(); j++) {
            typeBindings[j] = types.get(j).resolveBinding();
        }// ww w . j a v  a 2  s. c  o  m
        return new MultiBinding(typeBindings);

    default:
        // TODO JNR throw
        return null;
    }
}

From source file:org.eclipse.jpt.common.core.internal.utility.jdt.PrimitiveTypeStringExpressionConverter.java

License:Open Source License

@Override
protected String convertExpression(Expression expression) {
    if (expression.getNodeType() == ASTNode.TYPE_LITERAL) {
        org.eclipse.jdt.core.dom.Type type = ((TypeLiteral) expression).getType();
        if (type.getNodeType() == ASTNode.PRIMITIVE_TYPE) {
            return ((PrimitiveType) type).getPrimitiveTypeCode().toString();
        }//  ww w .  ja  va 2  s .  c om
    }
    return null;
}

From source file:org.eclipse.jpt.common.core.internal.utility.jdt.SimpleTypeStringExpressionConverter.java

License:Open Source License

@Override
protected String convertExpression(Expression expression) {
    if (expression.getNodeType() == ASTNode.TYPE_LITERAL) {
        org.eclipse.jdt.core.dom.Type type = ((TypeLiteral) expression).getType();
        if (type.getNodeType() == ASTNode.SIMPLE_TYPE) {
            return ((SimpleType) type).getName().getFullyQualifiedName();
        }//from  w ww .ja v a 2  s  .  c o  m
    }
    return null;
}

From source file:org.eclipse.pde.api.tools.internal.util.Signatures.java

License:Open Source License

/**
 * Processes the signature for the given {@link Type}
 * //from  www.ja v  a2 s.c om
 * @param type the type to process
 * @return the signature for the type or <code>null</code> if one could not
 *         be derived
 */
public static String getTypeSignature(Type type) {
    switch (type.getNodeType()) {
    case ASTNode.SIMPLE_TYPE: {
        return Signature.createTypeSignature(((SimpleType) type).getName().getFullyQualifiedName(), false);
    }
    case ASTNode.QUALIFIED_TYPE: {
        return Signature.createTypeSignature(((QualifiedType) type).getName().getFullyQualifiedName(), false);
    }
    case ASTNode.ARRAY_TYPE: {
        ArrayType a = (ArrayType) type;
        return Signature.createArraySignature(getTypeSignature(a.getElementType()), a.getDimensions());
    }
    case ASTNode.PARAMETERIZED_TYPE: {
        // we don't need to care about the other scoping types only the
        // base type
        return getTypeSignature(((ParameterizedType) type).getType());
    }
    case ASTNode.PRIMITIVE_TYPE: {
        return Signature.createTypeSignature(((PrimitiveType) type).getPrimitiveTypeCode().toString(), false);
    }
    default:
        break;
    }
    return null;
}

From source file:org.eclipse.recommenders.rcp.utils.ASTNodeUtils.java

License:Open Source License

/**
 * Returns the simple name of a given class type, for primitive types their source names "int", "long" etc., for
 * arrays it returns the element type of the array, for wildcards their bound type, and for union types something
 * not meaningful.//w  ww.j a  v a 2 s  .  c o  m
 */
private static String toSimpleName(Type type) {
    SimpleName name;
    switch (type.getNodeType()) {
    case ASTNode.SIMPLE_TYPE: {
        SimpleType t = cast(type);
        name = stripQualifier(t.getName());
        break;
    }
    case ASTNode.QUALIFIED_TYPE: {
        QualifiedType t = cast(type);
        name = stripQualifier(t.getName());
        break;
    }
    case ASTNode.PARAMETERIZED_TYPE: {
        ParameterizedType t = cast(type);
        return toSimpleName(t.getType());
    }
    case ASTNode.PRIMITIVE_TYPE: {
        PrimitiveType t = cast(type);
        return t.getPrimitiveTypeCode().toString();
    }
    case ASTNode.WILDCARD_TYPE: {
        WildcardType t = cast(type);
        return toSimpleName(t.getBound());
    }
    case ASTNode.UNION_TYPE: {
        // TODO: that will probably not work with any name matching...
        UnionType t = cast(type);
        return "UnionType" + t.types().toString(); //$NON-NLS-1$
    }
    case ASTNode.ARRAY_TYPE: {
        ArrayType t = cast(type);
        return toSimpleName(t.getElementType()) + repeat("[]", t.getDimensions()); //$NON-NLS-1$
    }
    default:
        throw throwUnreachable("No support for type '%s'", type); //$NON-NLS-1$
    }

    return name.getIdentifier();
}

From source file:org.eclipse.recommenders.utils.rcp.ast.ASTNodeUtils.java

License:Open Source License

/**
 * Returns the simple name of a given class type, for primitive types their source names "int", "long" etc., for
 * arrays it returns the element type of the array, for wildcards their bound type, and for union types something
 * not meaningful.//from  w w  w .j a v  a 2 s  . c  o  m
 */
private static String toSimpleName(Type type) {
    SimpleName name;
    switch (type.getNodeType()) {
    case ASTNode.SIMPLE_TYPE: {
        SimpleType t = cast(type);
        name = stripQualifier(t.getName());
        break;
    }
    case ASTNode.QUALIFIED_TYPE: {
        QualifiedType t = cast(type);
        name = stripQualifier(t.getName());
        break;
    }
    case ASTNode.PARAMETERIZED_TYPE: {
        ParameterizedType t = cast(type);
        return toSimpleName(t.getType());
    }
    case ASTNode.PRIMITIVE_TYPE: {
        PrimitiveType t = cast(type);
        return t.getPrimitiveTypeCode().toString();
    }
    case ASTNode.WILDCARD_TYPE: {
        WildcardType t = cast(type);
        return toSimpleName(t.getBound());
    }
    case ASTNode.UNION_TYPE: {
        // TODO: that will probably not work with any name matching...
        UnionType t = cast(type);
        return "UnionType" + t.types().toString();
    }
    case ASTNode.ARRAY_TYPE: {
        ArrayType t = cast(type);
        return toSimpleName(t.getElementType()) + repeat("[]", t.getDimensions());
    }
    default:
        throw throwUnreachable("no support for type '%s'", type);
    }

    return name.getIdentifier();
}

From source file:sourcecodefilter.ExitCode.java

License:Open Source License

@SuppressWarnings("unchecked")
private static void removeUnsupportedClassHierarchyTypesIn(ConverterRelevantCatroidSource catroidSource) {
    final List<AbstractTypeDeclaration> types = catroidSource.getSourceAst().types();
    List<Type> superInterfaceTypes = null;

    for (AbstractTypeDeclaration abstractTypeDecl : types) {
        if (abstractTypeDecl.getNodeType() == ASTNode.TYPE_DECLARATION) {
            TypeDeclaration typeDecl = (TypeDeclaration) abstractTypeDecl;
            superInterfaceTypes = typeDecl.superInterfaceTypes();
            // Delete inner types
            for (TypeDeclaration innerType : Arrays.asList(typeDecl.getTypes())) {
                innerType.delete();//from  ww w.  j  av a  2 s . co m
            }

        } else if (abstractTypeDecl.getNodeType() == ASTNode.ENUM_DECLARATION) {
            EnumDeclaration enumDecl = (EnumDeclaration) abstractTypeDecl;
            superInterfaceTypes = enumDecl.superInterfaceTypes();

        } else {
            assert false : "Unhandled case: " + abstractTypeDecl.getClass().getName();
        }

        // modify type hierarchy
        for (Iterator<Type> iterator = superInterfaceTypes.iterator(); iterator.hasNext();) {
            Type interfaceType = iterator.next();
            if (interfaceType.getNodeType() == ASTNode.SIMPLE_TYPE) {
                String interfaceName = ((SimpleType) interfaceType).getName().getFullyQualifiedName();
                if (!(PRESERVED_INTERFACES.contains(interfaceName))) {
                    iterator.remove();
                }
            }
        }
    }
}