Search in sources :

Example 46 with IJavaProject

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Entry(java.util.Map.Entry) IJavaProject(org.eclipse.jdt.core.IJavaProject) NullChange(org.eclipse.ltk.core.refactoring.NullChange) ResourceDescription(org.eclipse.ui.ide.undo.ResourceDescription) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) IResource(org.eclipse.core.resources.IResource)

Example 47 with IJavaProject

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);
        }
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IProject(org.eclipse.core.resources.IProject)

Example 48 with IJavaProject

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;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject)

Example 49 with IJavaProject

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()]);
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 50 with IJavaProject

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;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject)

Aggregations

IJavaProject (org.eclipse.jdt.core.IJavaProject)743 IProject (org.eclipse.core.resources.IProject)178 IFile (org.eclipse.core.resources.IFile)149 Test (org.junit.Test)146 CoreException (org.eclipse.core.runtime.CoreException)127 JavaModelException (org.eclipse.jdt.core.JavaModelException)124 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)123 IPath (org.eclipse.core.runtime.IPath)110 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)103 ArrayList (java.util.ArrayList)87 IFolder (org.eclipse.core.resources.IFolder)78 IResource (org.eclipse.core.resources.IResource)75 IJavaElement (org.eclipse.jdt.core.IJavaElement)63 IType (org.eclipse.jdt.core.IType)63 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)62 Path (org.eclipse.core.runtime.Path)57 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)56 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)47 StringInputStream (org.eclipse.xtext.util.StringInputStream)39 HashMap (java.util.HashMap)38