List of usage examples for org.eclipse.jdt.internal.core JavaModelManager determineIfOnClasspath
public static IJavaElement determineIfOnClasspath(IResource resource, IJavaProject project)
null if the given resource is not on the classpath of the given project. From source file:org.eclipse.ajdt.core.javaelements.CompilationUnitTools.java
License:Open Source License
public static PackageFragment getParentPackage(IFile ajFile) { IJavaProject jp = JavaCore.create(ajFile.getProject()); IJavaElement elem = JavaModelManager.determineIfOnClasspath(ajFile, jp); if (elem == null) { //not on classpath -> default package IPackageFragmentRoot root = jp.getPackageFragmentRoot(ajFile.getParent()); elem = root.getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME); }/*from ww w . jav a 2s .c o m*/ if (elem instanceof PackageFragment) { return (PackageFragment) elem; } //should never happen return null; }
From source file:org.jboss.tools.common.EclipseUtil.java
License:Open Source License
/** * Returns compilation unit for file, if it exists in Java model, otherwise returns null. * /* ww w . j a v a2 s. c o m*/ * @param f * @return compilation unit for file, if it exists in Java model, otherwise null * @throws CoreException */ public static ICompilationUnit getCompilationUnit(IFile f) { IJavaProject jp = getJavaProject(f.getProject()); if (jp != null) { IPackageFragment pkg = (IPackageFragment) JavaModelManager.determineIfOnClasspath(f, jp); if (pkg != null) { ICompilationUnit result = pkg.getCompilationUnit(f.getName()); return (result.exists()) ? result : null; } } return null; }