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$
}
}
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;
}
Aggregations