Search in sources :

Example 1 with File

use of org.eclipse.core.internal.resources.File 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 File

use of org.eclipse.core.internal.resources.File in project jbosstools-hibernate by jbosstools.

the class ProjectUtils method exists.

/**
 * Checks is file, folder or project exist.
 * @param file
 * @return true if a resource exist
 */
public static boolean exists(IFile f) {
    if (!(f instanceof File)) {
        return false;
    }
    File file = (File) f;
    ResourceInfo info = file.getResourceInfo(false, false);
    int flags = file.getFlags(info);
    if (flags != ICoreConstants.NULL_FLAG) {
        int type = ResourceInfo.getType(flags);
        if (type == IResource.FILE || type == IResource.FOLDER || type == IResource.PROJECT) {
            return true;
        }
    }
    return false;
}
Also used : ResourceInfo(org.eclipse.core.internal.resources.ResourceInfo) File(org.eclipse.core.internal.resources.File) IFile(org.eclipse.core.resources.IFile)

Aggregations

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