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