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

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

Introduction

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

Prototype

public final boolean isQualifiedType() 

Source Link

Document

Returns whether this type is a qualified type ( QualifiedType ).

Usage

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

License:Apache License

protected String typeName(final org.eclipse.jdt.core.dom.Type t) {
    if (t.isArrayType())
        return typeName((ArrayType) t);
    if (t.isParameterizedType())
        return typeName((ParameterizedType) t);
    if (t.isPrimitiveType())
        return typeName((PrimitiveType) t);
    if (t.isQualifiedType())
        return typeName((QualifiedType) t);
    if (t.isIntersectionType())
        return typeName((IntersectionType) t);
    if (t.isUnionType())
        return typeName((UnionType) t);
    if (t.isWildcardType())
        return typeName((WildcardType) t);
    return typeName((SimpleType) t);
}

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

License:Apache License

private String typeName(org.eclipse.jdt.core.dom.Type t) {
    if (t.isArrayType())
        return typeName(((ArrayType) t).getComponentType()) + "[]";
    if (t.isParameterizedType()) {
        String name = "";
        for (Object o : ((ParameterizedType) t).typeArguments()) {
            if (name.length() > 0)
                name += ", ";
            name += typeName((org.eclipse.jdt.core.dom.Type) o);
        }//  ww w  .j  a  v a 2  s  .  c o m
        return typeName(((ParameterizedType) t).getType()) + "<" + name + ">";
    }
    if (t.isPrimitiveType())
        return ((PrimitiveType) t).getPrimitiveTypeCode().toString();
    if (t.isQualifiedType())
        return typeName(((QualifiedType) t).getQualifier()) + "."
                + ((QualifiedType) t).getName().getFullyQualifiedName();
    if (t.isUnionType()) {
        String name = "";
        for (Object o : ((UnionType) t).types()) {
            if (name.length() > 0)
                name += " | ";
            name += typeName((org.eclipse.jdt.core.dom.Type) o);
        }
        return name;
    }
    if (t.isWildcardType()) {
        String name = "?";
        if (((WildcardType) t).getBound() != null) {
            name += " " + (((WildcardType) t).isUpperBound() ? "extends" : "super");
            name += " " + typeName(((WildcardType) t).getBound());
        }
        return name;
    }
    return ((SimpleType) t).getName().getFullyQualifiedName();
}

From source file:com.halware.nakedide.eclipse.ext.annot.utils.AstUtils.java

License:Open Source License

public static String asString(Type type) {
    if (type.isArrayType()) {
        ArrayType arrayType = (ArrayType) type;
        return asString(arrayType.getComponentType()) + "[]";
    }/* ww  w .ja  v a  2s  .  com*/
    if (type.isParameterizedType()) {
        ParameterizedType parameterizedType = (ParameterizedType) type;
        List<Type> typeArguments = Generics.asT(parameterizedType.typeArguments());
        class TypeToString implements ClosureUtil.IClosure<Type, String> {
            public String eval(Type type) {
                return asString(type);
            }
        }
        return asString(parameterizedType.getType()) + "<"
                + StringUtil.join(ClosureUtil.forEach(typeArguments, new TypeToString()), ", ") + ">";
    }
    if (type.isPrimitiveType()) {
        PrimitiveType primitiveType = (PrimitiveType) type;
        return primitiveType.getPrimitiveTypeCode().toString();
    }
    if (type.isQualifiedType()) {
        QualifiedType qualifiedType = (QualifiedType) type;
        return qualifiedType.getName().getFullyQualifiedName();
    }
    if (type.isSimpleType()) {
        SimpleType simpleType = (SimpleType) type;
        return simpleType.getName().getFullyQualifiedName();
    }
    if (type.isWildcardType()) {
        WildcardType wildcardType = (WildcardType) type;
        Type boundType = wildcardType.getBound();
        if (boundType != null) {
            if (wildcardType.isUpperBound()) {
                return "? extends " + asString(boundType);
            } else {
                return "? super " + asString(boundType);
            }
        } else {
            return "?";
        }
    }
    return "(unknown type)";
}

From source file:com.halware.nakedide.eclipse.ext.annot.utils.AstUtils.java

License:Open Source License

/**
 * Doesn't support {@link SimpleType}s (so isn't much use).
 * /* w w w .jav a 2 s. co m*/
 * @param type
 * @return
 */
public static boolean isValueType(Type type) {
    if (type.isArrayType()) {
        return false;
    }
    if (type.isParameterizedType()) {
        return false;
    }
    if (type.isPrimitiveType()) {
        return true;
    }
    if (type.isSimpleType()) {
        // because we can't tell which package the type is in :-(
        return false;
    }
    if (type.isQualifiedType()) {
        return MethodUtils.isBuiltInValueType(asString(type));
    }
    if (type.isWildcardType()) {
        return false;
    }
    return false;
}

From source file:com.windowtester.eclipse.ui.convert.WTAPIAbstractVisitor.java

License:Open Source License

/**
 * Initialize the variable scope before visiting nodes
 *//*from  w  ww .  ja  v  a2  s .  co m*/
@SuppressWarnings("unchecked")
public boolean visit(Block node) {
    currentScope = new VarScope(currentScope);
    ASTNode parent = node.getParent();
    if (parent instanceof MethodDeclaration) {
        List<SingleVariableDeclaration> parameters = ((MethodDeclaration) parent).parameters();
        for (SingleVariableDeclaration param : parameters) {
            Type type = param.getType();
            String unresolvedTypeName;
            if (type.isSimpleType())
                unresolvedTypeName = ((SimpleType) type).getName().getFullyQualifiedName();
            else if (type.isQualifiedType())
                unresolvedTypeName = ((QualifiedType) type).getName().getFullyQualifiedName();
            else
                unresolvedTypeName = null;
            String typeName = context.resolve(unresolvedTypeName);
            if (typeName == null)
                typeName = unresolvedTypeName;
            String varName = param.getName().getFullyQualifiedName();
            currentScope.setVarType(varName, typeName);
        }
    }
    return true;
}

From source file:edu.umd.cs.findbugs.plugin.eclipse.quickfix.util.ASTUtil.java

License:Open Source License

private static String getPrettyTypeName(Type type) {
    if (type.isArrayType()) {
        return getPrettyTypeName((ArrayType) type);
    } else if (type.isParameterizedType()) {
        return getPrettyTypeName((ParameterizedType) type);
    } else if (type.isPrimitiveType()) {
        return getPrettyTypeName((PrimitiveType) type);
    } else if (type.isQualifiedType()) {
        return getPrettyTypeName((QualifiedType) type);
    } else if (type.isSimpleType()) {
        return getPrettyTypeName((SimpleType) type);
    } else {/*from   w ww .j  av a2 s. c om*/
        return "";
    }
}

From source file:net.atos.optimus.common.tools.jdt.JavaCodeHelper.java

License:Open Source License

/**
 * Return a name instance from a Type instance
 *///from www  .j  a  v  a 2 s.co  m
public static Name getName(Type t) {
    if (t.isArrayType()) {
        return getName(((ArrayType) t).getComponentType());
    } else if (t.isParameterizedType()) {
        return getName(((ParameterizedType) t).getType());
    } else if (t.isPrimitiveType()) {
        return null;
    } else if (t.isQualifiedType()) {
        return ((QualifiedType) t).getName();
    } else if (t.isSimpleType()) {
        return ((SimpleType) t).getName();
    }

    return null;
}

From source file:org.dyno.visual.swing.parser.listener.DelegationModel.java

License:Open Source License

protected boolean parse(WidgetAdapter adapter, EventSetDescriptor esd, MethodDescriptor mListener,
        ClassInstanceCreation instanceExpression) {
    AnonymousClassDeclaration acd = instanceExpression.getAnonymousClassDeclaration();
    List bodys = acd.bodyDeclarations();
    Method[] lMethods = esd.getListenerMethods();
    for (Object element : bodys) {
        if (!(element instanceof MethodDeclaration)) {
            return false;
        }//from w  w  w . j ava  2  s  . co  m
        MethodDeclaration method = (MethodDeclaration) element;
        if (method.isConstructor())
            return false;
        List modifiers = method.modifiers();
        boolean isPublic = false;
        for (Object mod : modifiers) {
            IExtendedModifier exm = (IExtendedModifier) mod;
            if (exm instanceof Modifier) {
                Modifier m = (Modifier) exm;
                if (m.getKeyword().equals(ModifierKeyword.PUBLIC_KEYWORD)) {
                    isPublic = true;
                }
            }
        }
        if (!isPublic)
            return false;
        boolean isLM = false;
        List params = method.parameters();
        for (Method m : lMethods) {
            if (m.getName().equals(method.getName().getFullyQualifiedName())) {
                if (params != null && params.size() == 1) {
                    SingleVariableDeclaration svd = (SingleVariableDeclaration) params.get(0);
                    if (!svd.isVarargs()) {
                        Type type = svd.getType();
                        if (!type.isArrayType() && !type.isParameterizedType() && !type.isPrimitiveType()
                                && !type.isWildcardType()) {
                            Class<?>[] types = m.getParameterTypes();
                            Class evtType = types[0];
                            if (type.isQualifiedType()) {
                                QualifiedType qt = (QualifiedType) type;
                                if (qt.getName().getFullyQualifiedName().equals(evtType.getName())) {
                                    isLM = true;
                                }
                            } else if (type.isSimpleType()) {
                                SimpleType st = (SimpleType) type;
                                String name = st.getName().getFullyQualifiedName();
                                if (evtType.getName().indexOf(name) != -1) {
                                    isLM = true;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (!isLM)
            return false;
    }
    for (Object element : bodys) {
        if (element instanceof MethodDeclaration) {
            if (processListenerMethod(adapter, esd, mListener, (MethodDeclaration) element)) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.ebayopensource.dsf.javatojs.translate.DataTypeTranslator.java

License:Open Source License

public IJstType processType(final Type astType, final BaseJstNode jstNode) {
    boolean processed = false;
    if (astType == null) {
        return null;
    }/* ww w . ja v  a  2s  .  c  o m*/
    IJstType processType = null;
    if (astType.isArrayType()) {
        return processArrayType((ArrayType) astType, jstNode);
    } else if (astType.isParameterizedType()) {
        return processTypeWithArgs((ParameterizedType) astType, jstNode);
    } else if (astType.isQualifiedType()) {
        return processQualifiedType((QualifiedType) astType, jstNode);
    } else if (astType.isWildcardType()) {
        return processWildcardType((WildcardType) astType, jstNode);
    } else if (astType.isSimpleType()) {
        return processName(((SimpleType) astType).getName(), jstNode);
    }

    JstType ownerType = jstNode.getOwnerType();
    String typeName = astType.toString();
    IJstType jstType = findJstType(typeName, jstNode);

    if (jstType == null) {
        jstType = getJstType(astType, typeName, ownerType, true);
    }

    if (processed) {
        return processType;
    }
    getCtx().getTranslateInfo(ownerType).setType(typeName, jstType);

    return jstType;
}

From source file:org.eclipse.emf.codegen.merge.java.facade.ast.ASTFacadeHelper.java

License:Open Source License

/**
 * Converts {@link Type} to string representation, erasing type parameters information.
 * <p>/*from w  w  w.ja  v a2s . c o m*/
 * This method is used to create a method signature, and match methods by signature.
 * 
 * @param type
 * @return string representing the type
 */
public static String getTypeErasure(Type type) {
    if (type != null) {
        if (type.isArrayType()) {
            return getTypeErasure((ArrayType) type);
        } else if (type.isParameterizedType()) {
            return getTypeErasure((ParameterizedType) type);
        } else if (type.isPrimitiveType()) {
            return getTypeErasure((PrimitiveType) type);
        } else if (type.isQualifiedType()) {
            return getTypeErasure((QualifiedType) type);
        } else if (type.isSimpleType()) {
            return getTypeErasure((SimpleType) type);
        } else if (type.isWildcardType()) {
            return "";
        }
    }
    return "";
}