Search in sources :

Example 1 with FieldGetterType

use of org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo.FieldGetterType 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

Iterator (java.util.Iterator)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 ArrayType (org.eclipse.jdt.core.dom.ArrayType)1 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)1 ParameterizedType (org.eclipse.jdt.core.dom.ParameterizedType)1 PrimitiveType (org.eclipse.jdt.core.dom.PrimitiveType)1 QualifiedType (org.eclipse.jdt.core.dom.QualifiedType)1 SimpleType (org.eclipse.jdt.core.dom.SimpleType)1 Type (org.eclipse.jdt.core.dom.Type)1 WildcardType (org.eclipse.jdt.core.dom.WildcardType)1 BinaryType (org.eclipse.jdt.internal.core.BinaryType)1 SourceType (org.eclipse.jdt.internal.core.SourceType)1 FieldGetterType (org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo.FieldGetterType)1 RefType (org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefType)1