Search in sources :

Example 56 with ParameterizedType

use of org.eclipse.jdt.core.dom.ParameterizedType in project sts4 by spring-projects.

the class BeansSymbolProvider method isFunctionBean.

private boolean isFunctionBean(Annotation node) {
    ASTNode parent = node.getParent();
    if (parent instanceof MethodDeclaration) {
        MethodDeclaration method = (MethodDeclaration) parent;
        String returnType = null;
        if (method.getReturnType2().isParameterizedType()) {
            ParameterizedType paramType = (ParameterizedType) method.getReturnType2();
            Type type = paramType.getType();
            ITypeBinding typeBinding = type.resolveBinding();
            returnType = typeBinding.getBinaryName();
        } else {
            returnType = method.getReturnType2().resolveBinding().getQualifiedName();
        }
        return FunctionUtils.FUNCTION_FUNCTION_TYPE.equals(returnType) || FunctionUtils.FUNCTION_CONSUMER_TYPE.equals(returnType) || FunctionUtils.FUNCTION_SUPPLIER_TYPE.equals(returnType);
    }
    return false;
}
Also used : ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) Type(org.eclipse.jdt.core.dom.Type) ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ASTNode(org.eclipse.jdt.core.dom.ASTNode)

Example 57 with ParameterizedType

use of org.eclipse.jdt.core.dom.ParameterizedType in project jbosstools-hibernate by jbosstools.

the class CollectEntityInfo method processFieldOrGetter.

public boolean processFieldOrGetter(Type type, List<String> list, boolean fieldFlag) {
    if (type == null) {
        return false;
    }
    if (type.isPrimitiveType()) {
        PrimitiveType pt = (PrimitiveType) type;
        if (!pt.getPrimitiveTypeCode().equals(PrimitiveType.BOOLEAN)) {
            // this is candidate for primary id
            Iterator<String> itVarNames = list.iterator();
            while (itVarNames.hasNext()) {
                String name = itVarNames.next();
                if ("version".equalsIgnoreCase(name)) {
                    // $NON-NLS-1$
                    FieldGetterType versionFieldGetter = updateFieldGetter(entityInfo.getVersionFieldGetter(), fieldFlag);
                    entityInfo.setVersionFieldGetter(versionFieldGetter);
                } else {
                    entityInfo.addPrimaryIdCandidate(name);
                }
            }
        }
    } else if (type.isSimpleType()) {
        SimpleType st = (SimpleType) type;
        ITypeBinding tb = st.resolveBinding();
        if (tb != null) {
            // $NON-NLS-1$
            String entityFullyQualifiedName = "";
            if (tb.getJavaElement() instanceof SourceType) {
                SourceType sourceT = (SourceType) tb.getJavaElement();
                entityFullyQualifiedName = sourceT.getFullyQualifiedName();
                entityInfo.addDependency(entityFullyQualifiedName);
                RefType refType2Use = tb.isEnum() ? RefType.ENUMERATED : RefType.MANY2ONE;
                Iterator<String> itVarNames = list.iterator();
                while (itVarNames.hasNext()) {
                    String name = itVarNames.next();
                    entityInfo.addReference(name, entityFullyQualifiedName, refType2Use);
                }
            } else if (tb.getJavaElement() instanceof BinaryType) {
                ITypeBinding tbParent = tb.getTypeDeclaration().getSuperclass();
                if (tbParent != null) {
                    if ("java.lang.Number".equals(tbParent.getBinaryName())) {
                        // $NON-NLS-1$
                        // this is candidate for primary id
                        Iterator<String> itVarNames = list.iterator();
                        while (itVarNames.hasNext()) {
                            String name = itVarNames.next();
                            if ("version".equalsIgnoreCase(name)) {
                                // $NON-NLS-1$
                                FieldGetterType versionFieldGetter = updateFieldGetter(entityInfo.getVersionFieldGetter(), fieldFlag);
                                entityInfo.setVersionFieldGetter(versionFieldGetter);
                            } else {
                                entityInfo.addPrimaryIdCandidate(name);
                            }
                        }
                    } else if ("java.util.Date".equals(tbParent.getBinaryName())) {
                        // $NON-NLS-1$
                        // this is candidate for version
                        Iterator<String> itVarNames = list.iterator();
                        while (itVarNames.hasNext()) {
                            String name = itVarNames.next();
                            if ("version".equalsIgnoreCase(name)) {
                                // $NON-NLS-1$
                                FieldGetterType versionFieldGetter = updateFieldGetter(entityInfo.getVersionFieldGetter(), fieldFlag);
                                entityInfo.setVersionFieldGetter(versionFieldGetter);
                            }
                        }
                    }
                }
                if ("java.lang.String".equals(tb.getBinaryName())) {
                    // $NON-NLS-1$
                    Iterator<String> itVarNames = list.iterator();
                    while (itVarNames.hasNext()) {
                        String name = itVarNames.next();
                        entityInfo.updateAnnotationColumn(name, null, false);
                        entityInfo.addPrimaryIdCandidate(name);
                    }
                }
            }
        }
    } else if (type.isArrayType()) {
        ArrayType at = (ArrayType) type;
        Type elementType = at.getElementType();
        ITypeBinding tb = elementType.resolveBinding();
        if (tb != null) {
            if (tb.getJavaElement() instanceof SourceType) {
                // $NON-NLS-1$
                String entityFullyQualifiedName = "";
                SourceType sourceT = (SourceType) tb.getJavaElement();
                try {
                    entityFullyQualifiedName = sourceT.getFullyQualifiedParameterizedName();
                } catch (JavaModelException e) {
                    // $NON-NLS-1$
                    HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ", e);
                }
                entityInfo.addDependency(entityFullyQualifiedName);
                Iterator<String> itVarNames = list.iterator();
                while (itVarNames.hasNext()) {
                    String name = itVarNames.next();
                    entityInfo.addReference(name, entityFullyQualifiedName, RefType.ONE2MANY);
                }
            }
        }
    } else if (type.isParameterizedType()) {
        ParameterizedType pt = (ParameterizedType) type;
        Type typeP = pt.getType();
        ITypeBinding tb = typeP.resolveBinding();
        if (tb != null) {
            ITypeBinding[] interfaces = Utils.getAllInterfaces(tb);
            // $NON-NLS-1$
            String fullyQualifiedNameTypeName = "";
            if (Utils.isImplementInterface(interfaces, "java.util.Collection")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                fullyQualifiedNameTypeName = "java.util.Collection";
            }
            if (Utils.isImplementInterface(interfaces, "java.util.Map")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                fullyQualifiedNameTypeName = "java.util.Map";
            }
            /*for (int i = 0; i < interfaces.length; i++) {
					if (interfaces[i].getJavaElement() instanceof BinaryType) {
						BinaryType binaryT = (BinaryType)interfaces[i].getJavaElement();
						String tmp = binaryT.getFullyQualifiedName('.');
						if (0 == "java.util.Collection".compareTo(tmp)) { //$NON-NLS-1$
							fullyQualifiedNameTypeName = tmp;
							break;
						}
					}
				}*/
            if (fullyQualifiedNameTypeName.length() > 0) {
                Iterator<Type> typeArgsIt = pt.typeArguments().iterator();
                while (typeArgsIt.hasNext()) {
                    typeP = typeArgsIt.next();
                    tb = typeP.resolveBinding();
                    // $NON-NLS-1$
                    String entityFullyQualifiedName = "";
                    if (tb.getJavaElement() instanceof SourceType) {
                        SourceType sourceT = (SourceType) tb.getJavaElement();
                        try {
                            entityFullyQualifiedName = sourceT.getFullyQualifiedParameterizedName();
                        } catch (JavaModelException e) {
                            // $NON-NLS-1$
                            HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ", e);
                        }
                        entityInfo.addDependency(entityFullyQualifiedName);
                        Iterator<String> itVarNames = list.iterator();
                        while (itVarNames.hasNext()) {
                            String name = itVarNames.next();
                            entityInfo.addReference(name, entityFullyQualifiedName, RefType.ONE2MANY);
                        }
                    }
                }
            }
        }
    } else if (type.isQualifiedType()) {
        QualifiedType qt = (QualifiedType) type;
        @SuppressWarnings("unused") ITypeBinding tb = qt.resolveBinding();
    } else if (type.isWildcardType()) {
        WildcardType wt = (WildcardType) type;
        @SuppressWarnings("unused") ITypeBinding tb = wt.resolveBinding();
    }
    return true;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) BinaryType(org.eclipse.jdt.internal.core.BinaryType) SourceType(org.eclipse.jdt.internal.core.SourceType) FieldGetterType(org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo.FieldGetterType) RefType(org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefType) ArrayType(org.eclipse.jdt.core.dom.ArrayType) ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) SimpleType(org.eclipse.jdt.core.dom.SimpleType) BinaryType(org.eclipse.jdt.internal.core.BinaryType) SimpleType(org.eclipse.jdt.core.dom.SimpleType) Type(org.eclipse.jdt.core.dom.Type) RefType(org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefType) WildcardType(org.eclipse.jdt.core.dom.WildcardType) FieldGetterType(org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo.FieldGetterType) SourceType(org.eclipse.jdt.internal.core.SourceType) QualifiedType(org.eclipse.jdt.core.dom.QualifiedType) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType) ArrayType(org.eclipse.jdt.core.dom.ArrayType) ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) WildcardType(org.eclipse.jdt.core.dom.WildcardType) QualifiedType(org.eclipse.jdt.core.dom.QualifiedType) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) Iterator(java.util.Iterator) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType)

Aggregations

ParameterizedType (org.eclipse.jdt.core.dom.ParameterizedType)57 Type (org.eclipse.jdt.core.dom.Type)38 SimpleType (org.eclipse.jdt.core.dom.SimpleType)23 ArrayType (org.eclipse.jdt.core.dom.ArrayType)22 PrimitiveType (org.eclipse.jdt.core.dom.PrimitiveType)18 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)14 ASTNode (org.eclipse.jdt.core.dom.ASTNode)13 IType (org.eclipse.jdt.core.IType)12 ClassInstanceCreation (org.eclipse.jdt.core.dom.ClassInstanceCreation)10 NameQualifiedType (org.eclipse.jdt.core.dom.NameQualifiedType)10 QualifiedType (org.eclipse.jdt.core.dom.QualifiedType)10 SimpleName (org.eclipse.jdt.core.dom.SimpleName)9 WildcardType (java.lang.reflect.WildcardType)8 org.eclipse.jdt.core.dom (org.eclipse.jdt.core.dom)8 WildcardType (org.eclipse.jdt.core.dom.WildcardType)8 Name (org.eclipse.jdt.core.dom.Name)7 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)7 AbstractTypeDeclaration (org.eclipse.jdt.core.dom.AbstractTypeDeclaration)6 UnionType (org.eclipse.jdt.core.dom.UnionType)6 AST (org.eclipse.jdt.core.dom.AST)5