use of org.eclipse.jdt.core.IPackageFragmentRoot in project AutoRefactor by JnRouvignac.
the class PrepareApplyRefactoringsJob method addAll.
private void addAll(Queue<RefactoringUnit> results, List<IJavaElement> javaElements, IProgressMonitor monitor) throws JavaModelException {
final SubMonitor subMonitor = SubMonitor.convert(monitor, javaElements.size());
for (IJavaElement javaElement : javaElements) {
final SubMonitor child = subMonitor.newChild(1);
final JavaProjectOptions options = getJavaProjectOptions(javaElement);
if (javaElement instanceof ICompilationUnit) {
add(results, (ICompilationUnit) javaElement, options);
} else if (javaElement instanceof IPackageFragment) {
final IPackageFragment pf = (IPackageFragment) javaElement;
addAll(results, getSubPackages(pf), child);
addAll(results, pf.getCompilationUnits(), options);
} else if (javaElement instanceof IPackageFragmentRoot) {
final IPackageFragmentRoot pfr = (IPackageFragmentRoot) javaElement;
addAll(results, Arrays.asList(pfr.getChildren()), child);
} else if (javaElement instanceof IJavaProject) {
IJavaProject javaProject = (IJavaProject) javaElement;
for (IPackageFragment pf : javaProject.getPackageFragments()) {
addAll(results, pf.getCompilationUnits(), options);
}
}
}
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project AutoRefactor by JnRouvignac.
the class PrepareApplyRefactoringsJob method getSubPackages.
private List<IJavaElement> getSubPackages(IPackageFragment motherPackage) throws JavaModelException {
List<IJavaElement> subPackages = new ArrayList<IJavaElement>();
String packageName = motherPackage.getElementName();
IJavaElement[] packages = ((IPackageFragmentRoot) motherPackage.getParent()).getChildren();
for (IJavaElement onePackage : packages) {
if (onePackage instanceof IPackageFragment && onePackage.getElementName().startsWith(packageName + ".")) {
subPackages.add(onePackage);
}
}
return subPackages;
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project xtext-xtend by eclipse.
the class XtendUIValidator method getExpectedPackageName.
protected String getExpectedPackageName(XtendFile xtendFile) {
URI fileURI = xtendFile.eResource().getURI();
for (Pair<IStorage, IProject> storage : storage2UriMapper.getStorages(fileURI)) {
if (storage.getFirst() instanceof IFile) {
IPath fileWorkspacePath = storage.getFirst().getFullPath();
IJavaProject javaProject = JavaCore.create(storage.getSecond());
if (javaProject != null && javaProject.exists() && javaProject.isOpen()) {
try {
for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
if (!root.isArchive() && !root.isExternal()) {
IResource resource = root.getResource();
if (resource != null) {
IPath sourceFolderPath = resource.getFullPath();
if (sourceFolderPath.isPrefixOf(fileWorkspacePath)) {
IPath claspathRelativePath = fileWorkspacePath.makeRelativeTo(sourceFolderPath);
return claspathRelativePath.removeLastSegments(1).toString().replace("/", ".");
}
}
}
}
} catch (JavaModelException e) {
LOG.error("Error resolving expected path for XtendFile", e);
}
}
}
}
return null;
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project xtext-xtend by eclipse.
the class XbaseEditorOpenClassFileTest method testOpenFileFromSmapJarWithIncludedSource.
@Test
public void testOpenFileFromSmapJarWithIncludedSource() {
try {
boolean _supportsEditorOverride = this.supportsEditorOverride();
boolean _not = (!_supportsEditorOverride);
if (_not) {
return;
}
final IJavaProject jp = JavaCore.create(this.project);
final IPackageFragmentRoot root = this.addJarToClassPath(jp, "smap-all.jar", null);
Assert.assertNotNull(root);
final IType type = jp.findType("de.itemis.HelloXtend");
Assert.assertNotNull(type);
final String result = this.getEditorContents(type);
this.assertContains("println(\'Hello Xtend!\')", result);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project xtext-xtend by eclipse.
the class XbaseEditorOpenClassFileTest method testOpenFileFromJarWithNameConflictingLocalFile.
@Test
public void testOpenFileFromJarWithNameConflictingLocalFile() {
try {
boolean _supportsEditorOverride = this.supportsEditorOverride();
boolean _not = (!_supportsEditorOverride);
if (_not) {
return;
}
final IJavaProject jp = JavaCore.create(this.project);
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.append("class HelloXtend {");
_builder.newLine();
_builder.append("\t");
_builder.append("// wrong class");
_builder.newLine();
_builder.append("}");
_builder.newLine();
this.helper.createFile("foo/HelloXtend.xtend", _builder.toString());
final IPackageFragmentRoot root = this.addJarToClassPath(jp, "primary-debug-binary.jar", "primary-debug-sources.jar");
Assert.assertNotNull(root);
final IType type = jp.findType("de.itemis.HelloXtend");
Assert.assertNotNull(type);
final String result = this.getEditorContents(type);
this.assertContains("println(\'Hello Xtend!\')", result);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations