Search in sources :

Example 31 with IJavaElement

use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.

the class ReorgPolicyFactory method processReorgExecutionRecord.

private static void processReorgExecutionRecord(ReorgExecutionLog log, JavaRefactoringArguments arguments, String token) {
    final StringTokenizer tokenizer = new StringTokenizer(token, DELIMITER_ELEMENT, false);
    String value = null;
    if (tokenizer.hasMoreTokens()) {
        value = tokenizer.nextToken();
        Object element = JavaRefactoringDescriptorUtil.handleToElement(arguments.getProject(), value);
        if (element == null)
            element = JavaRefactoringDescriptorUtil.handleToResource(arguments.getProject(), value);
        if (tokenizer.hasMoreTokens()) {
            final boolean processed = Boolean.valueOf(tokenizer.nextToken()).booleanValue();
            if (processed) {
                log.markAsProcessed(element);
                if (element instanceof IJavaElement)
                    log.markAsProcessed(JavaElementResourceMapping.create((IJavaElement) element));
            }
            if (tokenizer.hasMoreTokens()) {
                final boolean renamed = Boolean.valueOf(tokenizer.nextToken()).booleanValue();
                if (renamed && tokenizer.hasMoreTokens()) {
                    final String name = tokenizer.nextToken();
                    log.setNewName(element, name);
                    if (element instanceof IJavaElement)
                        log.setNewName(JavaElementResourceMapping.create((IJavaElement) element), name);
                }
            }
        }
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) StringTokenizer(java.util.StringTokenizer)

Example 32 with IJavaElement

use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.

the class ReorgUtils method isParentInWorkspaceOrOnDisk.

public static boolean isParentInWorkspaceOrOnDisk(IPackageFragmentRoot root, IJavaProject javaProject) {
    if (root == null)
        return false;
    IJavaElement rootParent = root.getParent();
    if (rootParent == null)
        return false;
    if (rootParent.equals(root))
        return true;
    IResource packageResource = ResourceUtil.getResource(root);
    IResource packageRootResource = ResourceUtil.getResource(javaProject);
    return isParentInWorkspaceOrOnDisk(packageResource, packageRootResource);
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IResource(org.eclipse.core.resources.IResource)

Example 33 with IJavaElement

use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.

the class ReorgUtils method containsElementOrParent.

public static boolean containsElementOrParent(Set<IAdaptable> elements, IResource element) {
    IResource curr = element;
    do {
        if (elements.contains(curr))
            return true;
        IJavaElement jElement = JavaCore.create(curr);
        if (jElement != null && jElement.exists()) {
            return containsElementOrParent(elements, jElement);
        }
        curr = curr.getParent();
    } while (curr != null);
    return false;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IResource(org.eclipse.core.resources.IResource)

Example 34 with IJavaElement

use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.

the class ReorgUtils method groupByCompilationUnit.

/* List<IJavaElement> javaElements
	 * return ICompilationUnit -> List<IJavaElement>
	 */
public static Map<ICompilationUnit, List<IJavaElement>> groupByCompilationUnit(List<IJavaElement> javaElements) {
    Map<ICompilationUnit, List<IJavaElement>> result = new HashMap<ICompilationUnit, List<IJavaElement>>();
    for (Iterator<IJavaElement> iter = javaElements.iterator(); iter.hasNext(); ) {
        IJavaElement element = iter.next();
        ICompilationUnit cu = ReorgUtils.getCompilationUnit(element);
        if (cu != null) {
            if (!result.containsKey(cu))
                result.put(cu, new ArrayList<IJavaElement>(1));
            result.get(cu).add(element);
        }
    }
    return result;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 35 with IJavaElement

use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.

the class ReorgUtils method isArchiveOrExternalMember.

public static boolean isArchiveOrExternalMember(IJavaElement[] elements) {
    for (int i = 0; i < elements.length; i++) {
        IJavaElement element = elements[i];
        IPackageFragmentRoot root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
        if (root != null && (root.isArchive() || root.isExternal()))
            return true;
    }
    return false;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Aggregations

IJavaElement (org.eclipse.jdt.core.IJavaElement)226 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)49 IType (org.eclipse.jdt.core.IType)44 ArrayList (java.util.ArrayList)35 IJavaProject (org.eclipse.jdt.core.IJavaProject)35 IMethod (org.eclipse.jdt.core.IMethod)34 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)32 JavaModelException (org.eclipse.jdt.core.JavaModelException)32 IResource (org.eclipse.core.resources.IResource)30 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)28 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)23 IField (org.eclipse.jdt.core.IField)16 IMember (org.eclipse.jdt.core.IMember)14 Test (org.junit.Test)14 CoreException (org.eclipse.core.runtime.CoreException)13 StringTokenizer (java.util.StringTokenizer)11 ISourceRange (org.eclipse.jdt.core.ISourceRange)11 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)11 IPath (org.eclipse.core.runtime.IPath)10 HashMap (java.util.HashMap)9