use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class JavaElementUtil method getReferencingProjects.
/**
* @param root the package fragment root
* @return array of projects that have the specified root on their classpath
* @throws JavaModelException if getting the raw classpath or all Java projects fails
*/
public static IJavaProject[] getReferencingProjects(IPackageFragmentRoot root) throws JavaModelException {
IClasspathEntry cpe = root.getRawClasspathEntry();
if (cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
cpe = root.getResolvedClasspathEntry();
IJavaProject[] allJavaProjects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects();
List<IJavaProject> result = new ArrayList<IJavaProject>(allJavaProjects.length);
for (int i = 0; i < allJavaProjects.length; i++) {
IJavaProject project = allJavaProjects[i];
IPackageFragmentRoot[] roots = project.findPackageFragmentRoots(cpe);
if (roots.length > 0)
result.add(project);
}
return result.toArray(new IJavaProject[result.size()]);
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class JavaElementUtil method getPackageAndSubpackages.
/**
* @param pack a package fragment
* @return an array containing the given package and all subpackages
* @throws JavaModelException if getting the all sibling packages fails
*/
public static IPackageFragment[] getPackageAndSubpackages(IPackageFragment pack) throws JavaModelException {
if (pack.isDefaultPackage())
return new IPackageFragment[] { pack };
IPackageFragmentRoot root = (IPackageFragmentRoot) pack.getParent();
IJavaElement[] allPackages = root.getChildren();
ArrayList<IPackageFragment> subpackages = new ArrayList<IPackageFragment>();
subpackages.add(pack);
String prefix = pack.getElementName() + '.';
for (int i = 0; i < allPackages.length; i++) {
IPackageFragment currentPackage = (IPackageFragment) allPackages[i];
if (currentPackage.getElementName().startsWith(prefix))
subpackages.add(currentPackage);
}
return subpackages.toArray(new IPackageFragment[subpackages.size()]);
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project generator by mybatis.
the class EclipseShellCallback method getSpecificSourceFolder.
private IPackageFragmentRoot getSpecificSourceFolder(IJavaProject javaProject, String targetProject) throws ShellException {
try {
Path path = new Path("/" + targetProject);
IPackageFragmentRoot pfr = javaProject.findPackageFragmentRoot(path);
if (pfr == null) {
StringBuffer sb = new StringBuffer();
sb.append("Cannot find source folder ");
sb.append(targetProject);
throw new ShellException(sb.toString());
}
return pfr;
} catch (CoreException e) {
throw new ShellException(e.getStatus().getMessage(), e);
}
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project generator by mybatis.
the class EclipseShellCallback method getSourceFolder.
private IPackageFragmentRoot getSourceFolder(String targetProject) throws ShellException {
IPackageFragmentRoot answer = sourceFolders.get(targetProject);
if (answer == null) {
// first parse the targetProject into project and source folder
// values
int index = targetProject.indexOf('/');
if (index == -1) {
index = targetProject.indexOf('\\');
}
if (index == -1) {
// no source folder specified
IJavaProject javaProject = getJavaProject(targetProject);
answer = getFirstSourceFolder(javaProject);
} else {
IJavaProject javaProject = getJavaProject(targetProject.substring(0, index));
answer = getSpecificSourceFolder(javaProject, targetProject);
}
sourceFolders.put(targetProject, answer);
}
return answer;
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class IndexSelector method getFocusedElementsAndTypes.
/*
* Create the list of focused jars or projects.
*/
private static IJavaElement[] getFocusedElementsAndTypes(SearchPattern pattern, IJavaElement focusElement, ObjectVector superTypes) throws JavaModelException {
if (pattern instanceof MethodPattern) {
// For method pattern, it needs to walk along the focus type super hierarchy
// and add jars/projects of all the encountered types.
IType type = (IType) pattern.focus.getAncestor(IJavaElement.TYPE);
MethodPattern methodPattern = (MethodPattern) pattern;
String selector = new String(methodPattern.selector);
int parameterCount = methodPattern.parameterCount;
ITypeHierarchy superHierarchy = type.newSupertypeHierarchy(null);
IType[] allTypes = superHierarchy.getAllSupertypes(type);
int length = allTypes.length;
SimpleSet focusSet = new SimpleSet(length + 1);
if (focusElement != null)
focusSet.add(focusElement);
for (int i = 0; i < length; i++) {
IMethod[] methods = allTypes[i].getMethods();
int mLength = methods.length;
for (int m = 0; m < mLength; m++) {
if (parameterCount == methods[m].getNumberOfParameters() && methods[m].getElementName().equals(selector)) {
IPackageFragmentRoot root = (IPackageFragmentRoot) allTypes[i].getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
IJavaElement element = root.isArchive() ? root : root.getParent();
focusSet.add(element);
if (superTypes != null)
superTypes.add(allTypes[i]);
break;
}
}
}
// Rebuilt a contiguous array
IJavaElement[] focuses = new IJavaElement[focusSet.elementSize];
Object[] values = focusSet.values;
int count = 0;
for (int i = values.length; --i >= 0; ) {
if (values[i] != null) {
focuses[count++] = (IJavaElement) values[i];
}
}
return focuses;
}
if (focusElement == null)
return new IJavaElement[0];
return new IJavaElement[] { focusElement };
}
Aggregations