List of usage examples for org.eclipse.jdt.internal.core SourceType getFullyQualifiedParameterizedName
@Override
public String getFullyQualifiedParameterizedName() throws JavaModelException
From source file:org.hibernate.eclipse.console.utils.ProjectUtils.java
License:Open Source License
static public String getParentTypename(IJavaProject proj, String fullyQualifiedName) { String res = null;/* w w w .ja v a2 s .co m*/ ICompilationUnit icu = findCompilationUnit(proj, fullyQualifiedName); if (icu == null) { return res; } org.eclipse.jdt.core.dom.CompilationUnit cu = getCompilationUnit(icu, true); if (cu == null) { return res; } List<?> types = cu.types(); for (int i = 0; i < types.size() && res == null; i++) { Object obj = types.get(i); if (!(obj instanceof TypeDeclaration)) { continue; } TypeDeclaration td = (TypeDeclaration) obj; Type superType = td.getSuperclassType(); if (superType != null) { ITypeBinding tb = superType.resolveBinding(); if (tb != null) { if (tb.getJavaElement() instanceof SourceType) { SourceType sourceT = (SourceType) tb.getJavaElement(); try { res = sourceT.getFullyQualifiedParameterizedName(); } catch (JavaModelException e) { HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ", e); //$NON-NLS-1$ } } } } } return res; }
From source file:org.hibernate.eclipse.jdt.ui.internal.jpa.collect.CollectEntityInfo.java
License:Open Source License
public boolean visit(TypeDeclaration node) { ITypeBinding typeBinding = node.resolveBinding(); String nodeName = typeBinding == null ? null : typeBinding.getBinaryName(); if (fullyQualifiedName == null || !fullyQualifiedName.equalsIgnoreCase(nodeName)) { return false; }//from w ww . j a v a 2 s . c o m boolean isAbstruct = entityInfo.isAbstractFlag() || Modifier.isAbstract(node.getModifiers()) || node.isInterface(); entityInfo.setAbstractFlag(isAbstruct); if (isAbstruct) { entityInfo.setAddEntityFlag(false); entityInfo.setAddMappedSuperclassFlag(true); } entityInfo.setInterfaceFlag(node.isInterface()); Type superType = node.getSuperclassType(); if (superType != null) { ITypeBinding tb = superType.resolveBinding(); if (tb != null) { String entityFullyQualifiedName = ""; //$NON-NLS-1$ if (tb.getJavaElement() instanceof SourceType) { SourceType sourceT = (SourceType) tb.getJavaElement(); try { entityFullyQualifiedName = sourceT.getFullyQualifiedParameterizedName(); } catch (JavaModelException e) { HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ", e); //$NON-NLS-1$ } } entityInfo.addDependency(entityFullyQualifiedName); entityInfo.setFullyQualifiedParentName(entityFullyQualifiedName); } } List<?> superInterfaces = node.superInterfaceTypes(); Iterator<?> it = superInterfaces.iterator(); while (it.hasNext()) { Object obj = it.next(); if (obj instanceof SimpleType) { //TODO process interfaces SimpleType st = (SimpleType) obj; String fullyQualifiedName = st.getName().getFullyQualifiedName(); if (JPAConst.IMPORT_SERIALIZABLE.compareTo(fullyQualifiedName) == 0) { entityInfo.setAddSerializableInterfaceFlag(false); } else if (JPAConst.ANNOTATION_SERIALIZABLE.compareTo(fullyQualifiedName) == 0) { entityInfo.setAddSerializableInterfaceFlag(false); entityInfo.addRequiredImport(JPAConst.IMPORT_SERIALIZABLE); } } } node.resolveBinding(); return true; }
From source file:org.hibernate.eclipse.jdt.ui.internal.jpa.collect.CollectEntityInfo.java
License:Open Source License
public boolean processFieldOrGetter(Type type, List<String> list, boolean fieldFlag) { if (type == null) { return false; }/* ww w .j a va2s.c o m*/ 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) { String entityFullyQualifiedName = ""; //$NON-NLS-1$ 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 componentType = at; while (componentType.isArrayType()) { componentType = ((ArrayType) componentType).getComponentType(); } ITypeBinding tb = componentType.resolveBinding(); if (tb != null) { if (tb.getJavaElement() instanceof SourceType) { String entityFullyQualifiedName = ""; //$NON-NLS-1$ SourceType sourceT = (SourceType) tb.getJavaElement(); try { entityFullyQualifiedName = sourceT.getFullyQualifiedParameterizedName(); } catch (JavaModelException e) { HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ", e); //$NON-NLS-1$ } 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); String fullyQualifiedNameTypeName = ""; //$NON-NLS-1$ if (Utils.isImplementInterface(interfaces, "java.util.Collection")) {//$NON-NLS-1$ fullyQualifiedNameTypeName = "java.util.Collection";//$NON-NLS-1$ } if (Utils.isImplementInterface(interfaces, "java.util.Map")) {//$NON-NLS-1$ fullyQualifiedNameTypeName = "java.util.Map";//$NON-NLS-1$ } /*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(); String entityFullyQualifiedName = ""; //$NON-NLS-1$ if (tb.getJavaElement() instanceof SourceType) { SourceType sourceT = (SourceType) tb.getJavaElement(); try { entityFullyQualifiedName = sourceT.getFullyQualifiedParameterizedName(); } catch (JavaModelException e) { HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ", e); //$NON-NLS-1$ } 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; }