use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class DeletePackageFragmentRootChange method doDelete.
@Override
protected Change doDelete(IProgressMonitor pm) throws CoreException {
if (!confirmDeleteIfReferenced())
return new NullChange();
int resourceUpdateFlags = IResource.KEEP_HISTORY;
int jCoreUpdateFlags = IPackageFragmentRoot.ORIGINATING_PROJECT_CLASSPATH | IPackageFragmentRoot.OTHER_REFERRING_PROJECTS_CLASSPATH;
//$NON-NLS-1$
pm.beginTask("", 2);
IPackageFragmentRoot root = getRoot();
IResource rootResource = root.getResource();
CompositeChange result = new CompositeChange(getName());
ResourceDescription rootDescription = ResourceDescription.fromResource(rootResource);
IJavaProject[] referencingProjects = JavaElementUtil.getReferencingProjects(root);
HashMap<IFile, String> classpathFilesContents = new HashMap<IFile, String>();
for (int i = 0; i < referencingProjects.length; i++) {
IJavaProject javaProject = referencingProjects[i];
//$NON-NLS-1$
IFile classpathFile = javaProject.getProject().getFile(".classpath");
if (classpathFile.exists()) {
classpathFilesContents.put(classpathFile, getFileContents(classpathFile));
}
}
root.delete(resourceUpdateFlags, jCoreUpdateFlags, new SubProgressMonitor(pm, 1));
rootDescription.recordStateFromHistory(rootResource, new SubProgressMonitor(pm, 1));
for (Iterator<Entry<IFile, String>> iterator = classpathFilesContents.entrySet().iterator(); iterator.hasNext(); ) {
Entry<IFile, String> entry = iterator.next();
IFile file = entry.getKey();
String contents = entry.getValue();
//Restore time stamps? This should probably be some sort of UndoTextFileChange.
TextFileChange classpathUndo = new TextFileChange(Messages.format(RefactoringCoreMessages.DeletePackageFragmentRootChange_restore_file, BasicElementLabels.getPathLabel(file.getFullPath(), true)), file);
classpathUndo.setEdit(new ReplaceEdit(0, getFileLength(file), contents));
result.add(classpathUndo);
}
result.add(new UndoDeleteResourceChange(rootDescription));
pm.done();
return result;
}
use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class RefactoringScopeFactory method addReferencingProjects.
/*
* Adds to <code> projects </code> IJavaProject objects for all projects directly or indirectly referencing focus. @param projects IJavaProjects will be added to this set
*/
private static void addReferencingProjects(IJavaProject focus, Set<IJavaProject> projects) throws JavaModelException {
IProject[] referencingProjects = focus.getProject().getReferencingProjects();
for (int i = 0; i < referencingProjects.length; i++) {
IJavaProject candidate = JavaCore.create(referencingProjects[i]);
if (candidate == null || projects.contains(candidate) || !candidate.exists())
// break cycle
continue;
IClasspathEntry entry = getReferencingClassPathEntry(candidate, focus);
if (entry != null) {
projects.add(candidate);
if (entry.isExported())
addReferencingProjects(candidate, projects);
}
}
}
use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class RefactoringASTParser method getCompilerOptions.
/**
* Returns the compiler options used for creating the refactoring AST.
* <p>
* Turns all errors and warnings into ignore and disables task tags. The customizable set of
* compiler options only contains additional Eclipse options. The standard JDK compiler options
* can't be changed anyway.
*
* @param element an element (not the Java model)
* @return compiler options
*/
public static Map<String, String> getCompilerOptions(IJavaElement element) {
IJavaProject project = element.getJavaProject();
Map<String, String> options = project.getOptions(true);
for (Iterator<String> iter = options.keySet().iterator(); iter.hasNext(); ) {
String key = iter.next();
String value = options.get(key);
if (JavaCore.ERROR.equals(value) || JavaCore.WARNING.equals(value)) {
// System.out.println("Ignoring - " + key);
options.put(key, JavaCore.IGNORE);
}
}
//$NON-NLS-1$
options.put(JavaCore.COMPILER_PB_MAX_PER_UNIT, "0");
//$NON-NLS-1$
options.put(JavaCore.COMPILER_TASK_TAGS, "");
return options;
}
use of org.eclipse.jdt.core.IJavaProject 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.IJavaProject in project che by eclipse.
the class TypeEnvironment method createParameterizedType.
private ParameterizedType createParameterizedType(ITypeBinding binding) {
IJavaProject javaProject = binding.getJavaElement().getJavaProject();
String bindingKey = binding.getKey();
ProjectKeyPair pair = new ProjectKeyPair(javaProject, bindingKey);
ParameterizedType result = fParameterizedTypes.get(pair);
if (result != null)
return result;
result = new ParameterizedType(this);
fParameterizedTypes.put(pair, result);
result.initialize(binding, (IType) binding.getJavaElement());
cacheSubType(result.getSuperclass(), result);
cacheSubTypes(result.getInterfaces(), result);
return result;
}
Aggregations