Search in sources :

Example 1 with JavaElementInfo

use of org.eclipse.jdt.internal.core.JavaElementInfo in project jbosstools-hibernate by jbosstools.

the class CompilationUnitCollector method processJavaElements.

/**
 * Process object - java element to collect all it's children CompilationUnits
 * @param obj
 * @param bCollect
 */
public void processJavaElements(Object obj, boolean bCollect) {
    if (obj instanceof ICompilationUnit) {
        ICompilationUnit cu = (ICompilationUnit) obj;
        addCompilationUnit(cu, bCollect);
    } else if (obj instanceof File) {
        File file = (File) obj;
        if (file.getProject() != null) {
            IJavaProject javaProject = JavaCore.create(file.getProject());
            ICompilationUnit[] cus = Utils.findCompilationUnits(javaProject, file.getFullPath());
            if (cus != null) {
                for (int i = 0; i < cus.length; i++) {
                    addCompilationUnit(cus[i], bCollect);
                }
            }
        }
    } else if (obj instanceof JavaProject) {
        JavaProject javaProject = (JavaProject) obj;
        IPackageFragmentRoot[] pfr = null;
        try {
            pfr = javaProject.getAllPackageFragmentRoots();
        } catch (JavaModelException e) {
        // just ignore it!
        // HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ", e); //$NON-NLS-1$
        }
        if (pfr != null) {
            for (int i = 0; i < pfr.length; i++) {
                processJavaElements(pfr[i], bCollect);
            }
        }
    } else if (obj instanceof PackageFragment) {
        PackageFragment packageFragment = (PackageFragment) obj;
        ICompilationUnit[] cus = null;
        try {
            cus = packageFragment.getCompilationUnits();
        } catch (JavaModelException e) {
        // just ignore it!
        // HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ", e); //$NON-NLS-1$
        }
        if (cus != null && cus.length > 0) {
            if (bCollect) {
                selection2UpdateList.add(obj);
                bCollect = false;
            }
            for (int i = 0; i < cus.length; i++) {
                addCompilationUnit(cus[i], bCollect);
            }
        }
    } else if (obj instanceof PackageFragmentRoot) {
        JavaElement javaElement = (JavaElement) obj;
        JavaElementInfo javaElementInfo = null;
        try {
            javaElementInfo = (JavaElementInfo) javaElement.getElementInfo();
        } catch (JavaModelException e) {
        // just ignore it!
        // HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ", e); //$NON-NLS-1$
        }
        if (javaElementInfo != null) {
            IJavaElement[] je = javaElementInfo.getChildren();
            for (int i = 0; i < je.length; i++) {
                processJavaElements(je[i], true);
            }
        }
    } else if (obj instanceof JavaElement) {
        JavaElement javaElement = (JavaElement) obj;
        ICompilationUnit cu = javaElement.getCompilationUnit();
        addCompilationUnit(cu, bCollect);
    } else if (obj instanceof SourceType) {
        if (bCollect) {
            selection2UpdateList.add(obj);
            bCollect = false;
        }
        SourceType sourceType = (SourceType) obj;
        processJavaElements(sourceType.getJavaModel(), bCollect);
    } else {
    // ignore
    // System.out.println("1 Blah! " + selection); //$NON-NLS-1$
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) PackageFragment(org.eclipse.jdt.internal.core.PackageFragment) IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaProject(org.eclipse.jdt.internal.core.JavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaModelException(org.eclipse.jdt.core.JavaModelException) PackageFragmentRoot(org.eclipse.jdt.internal.core.PackageFragmentRoot) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) SourceType(org.eclipse.jdt.internal.core.SourceType) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaElement(org.eclipse.jdt.internal.core.JavaElement) JavaElementInfo(org.eclipse.jdt.internal.core.JavaElementInfo) IJavaProject(org.eclipse.jdt.core.IJavaProject) File(org.eclipse.core.internal.resources.File)

Example 2 with JavaElementInfo

use of org.eclipse.jdt.internal.core.JavaElementInfo in project jbosstools-hibernate by jbosstools.

the class NewHibernateMappingFileWizard method processJavaElements.

protected void processJavaElements(Object obj, int depth) {
    if (depth < 0) {
        return;
    }
    try {
        if (obj instanceof ICompilationUnit) {
            ICompilationUnit cu = (ICompilationUnit) obj;
            selectionCU.add(cu);
        } else if (obj instanceof JavaProject && depth > 0) {
            JavaProject javaProject = (JavaProject) obj;
            IPackageFragmentRoot[] pfr = javaProject.getAllPackageFragmentRoots();
            for (IPackageFragmentRoot element : pfr) {
                processJavaElements(element, depth - 1);
            }
        } else if (obj instanceof PackageFragment) {
            PackageFragment packageFragment = (PackageFragment) obj;
            ICompilationUnit[] cus = packageFragment.getCompilationUnits();
            for (ICompilationUnit cu : cus) {
                selectionCU.add(cu);
            }
        } else if (obj instanceof PackageFragmentRoot && depth > 0) {
            JavaElement javaElement = (JavaElement) obj;
            JavaElementInfo javaElementInfo = (JavaElementInfo) javaElement.getElementInfo();
            IJavaElement[] je = javaElementInfo.getChildren();
            for (IJavaElement element : je) {
                processJavaElements(element, depth - 1);
            }
        } else if (obj instanceof JavaElement) {
            JavaElement javaElement = (JavaElement) obj;
            ICompilationUnit cu = javaElement.getCompilationUnit();
            selectionCU.add(cu);
        }
    } catch (JavaModelException e) {
    // just ignore it!
    // HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ", e); //$NON-NLS-1$
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) PackageFragment(org.eclipse.jdt.internal.core.PackageFragment) IJavaElement(org.eclipse.jdt.core.IJavaElement) IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaProject(org.eclipse.jdt.internal.core.JavaProject) PackageFragmentRoot(org.eclipse.jdt.internal.core.PackageFragmentRoot) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) JavaElement(org.eclipse.jdt.internal.core.JavaElement) IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaElementInfo(org.eclipse.jdt.internal.core.JavaElementInfo) JavaModelException(org.eclipse.jdt.core.JavaModelException) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Aggregations

ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 IJavaElement (org.eclipse.jdt.core.IJavaElement)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 JavaElement (org.eclipse.jdt.internal.core.JavaElement)2 JavaElementInfo (org.eclipse.jdt.internal.core.JavaElementInfo)2 JavaProject (org.eclipse.jdt.internal.core.JavaProject)2 PackageFragment (org.eclipse.jdt.internal.core.PackageFragment)2 PackageFragmentRoot (org.eclipse.jdt.internal.core.PackageFragmentRoot)2 File (org.eclipse.core.internal.resources.File)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 SourceType (org.eclipse.jdt.internal.core.SourceType)1