Example usage for org.eclipse.jdt.internal.core JavaElement toStringWithAncestors

List of usage examples for org.eclipse.jdt.internal.core JavaElement toStringWithAncestors

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core JavaElement toStringWithAncestors.

Prototype

public String toStringWithAncestors() 

Source Link

Document

Debugging purposes

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.search.JavaSearchScope.java

License:Open Source License

public String toString() {
    StringBuffer result = new StringBuffer("JavaSearchScope on "); //$NON-NLS-1$
    if (this.elements != null) {
        result.append("["); //$NON-NLS-1$
        for (int i = 0, length = this.elements.size(); i < length; i++) {
            JavaElement element = (JavaElement) this.elements.get(i);
            result.append("\n\t"); //$NON-NLS-1$
            result.append(element.toStringWithAncestors());
        }/*from www .j  a  va  2  s .  c o m*/
        result.append("\n]"); //$NON-NLS-1$
    } else {
        if (this.pathsCount == 0) {
            result.append("[empty scope]"); //$NON-NLS-1$
        } else {
            result.append("["); //$NON-NLS-1$
            String[] paths = new String[this.relativePaths.length];
            int index = 0;
            for (int i = 0; i < this.relativePaths.length; i++) {
                String path = this.relativePaths[i];
                if (path == null)
                    continue;
                String containerPath;
                if (ExternalFoldersManager.isInternalPathForExternalFolder(new Path(this.containerPaths[i]))) {
                    Object target = JavaModel.getWorkspaceTarget(new Path(this.containerPaths[i]));
                    containerPath = ((IFolder) target).getLocation().toOSString();
                } else {
                    containerPath = this.containerPaths[i];
                }
                if (path.length() > 0) {
                    paths[index++] = containerPath + '/' + path;
                } else {
                    paths[index++] = containerPath;
                }
            }
            System.arraycopy(paths, 0, paths = new String[index], 0, index);
            Util.sort(paths);
            for (int i = 0; i < index; i++) {
                result.append("\n\t"); //$NON-NLS-1$
                result.append(paths[i]);
            }
            result.append("\n]"); //$NON-NLS-1$
        }
    }
    return result.toString();
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java

License:Open Source License

protected void report(SearchMatch match) throws CoreException {
    if (match == null) {
        if (BasicSearchEngine.VERBOSE) {
            System.out.println("Cannot report a null match!!!"); //$NON-NLS-1$
        }// w  ww . j  av a  2s .  c om
        return;
    }
    if (filterEnum(match)) {
        if (BasicSearchEngine.VERBOSE) {
            System.out.println("Filtered package with name enum"); //$NON-NLS-1$
        }
        return;
    }
    long start = -1;
    if (BasicSearchEngine.VERBOSE) {
        start = System.currentTimeMillis();
        System.out.println("Reporting match"); //$NON-NLS-1$
        System.out.println("\tResource: " + match.getResource());//$NON-NLS-1$
        System.out.println("\tPositions: [offset=" + match.getOffset() + ", length=" + match.getLength() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        try {
            if (this.parser != null && match.getOffset() > 0 && match.getLength() > 0
                    && !(match.getElement() instanceof BinaryMember)) {
                String selection = new String(this.parser.scanner.source, match.getOffset(), match.getLength());
                System.out.println("\tSelection: -->" + selection + "<--"); //$NON-NLS-1$ //$NON-NLS-2$
            }
        } catch (Exception e) {
            // it's just for debug purposes... ignore all exceptions in this area
        }
        try {
            JavaElement javaElement = (JavaElement) match.getElement();
            System.out.println("\tJava element: " + javaElement.toStringWithAncestors()); //$NON-NLS-1$
            if (!javaElement.exists()) {
                System.out.println("\t\tWARNING: this element does NOT exist!"); //$NON-NLS-1$
            }
        } catch (Exception e) {
            // it's just for debug purposes... ignore all exceptions in this area
        }
        if (match instanceof ReferenceMatch) {
            try {
                ReferenceMatch refMatch = (ReferenceMatch) match;
                JavaElement local = (JavaElement) refMatch.getLocalElement();
                if (local != null) {
                    System.out.println("\tLocal element: " + local.toStringWithAncestors()); //$NON-NLS-1$
                }
                if (match instanceof TypeReferenceMatch) {
                    IJavaElement[] others = ((TypeReferenceMatch) refMatch).getOtherElements();
                    if (others != null) {
                        int length = others.length;
                        if (length > 0) {
                            System.out.println("\tOther elements:"); //$NON-NLS-1$
                            for (int i = 0; i < length; i++) {
                                JavaElement other = (JavaElement) others[i];
                                System.out.println("\t\t- " + other.toStringWithAncestors()); //$NON-NLS-1$
                            }
                        }
                    }
                }
            } catch (Exception e) {
                // it's just for debug purposes... ignore all exceptions in this area
            }
        }
        System.out.println(match.getAccuracy() == SearchMatch.A_ACCURATE ? "\tAccuracy: EXACT_MATCH" //$NON-NLS-1$
                : "\tAccuracy: POTENTIAL_MATCH"); //$NON-NLS-1$
        System.out.print("\tRule: "); //$NON-NLS-1$
        if (match.isExact()) {
            System.out.print("EXACT"); //$NON-NLS-1$
        } else if (match.isEquivalent()) {
            System.out.print("EQUIVALENT"); //$NON-NLS-1$
        } else if (match.isErasure()) {
            System.out.print("ERASURE"); //$NON-NLS-1$
        } else {
            System.out.print("INVALID RULE"); //$NON-NLS-1$
        }
        if (match instanceof MethodReferenceMatch) {
            MethodReferenceMatch methodReferenceMatch = (MethodReferenceMatch) match;
            if (methodReferenceMatch.isSuperInvocation()) {
                System.out.print("+SUPER INVOCATION"); //$NON-NLS-1$
            }
            if (methodReferenceMatch.isImplicit()) {
                System.out.print("+IMPLICIT"); //$NON-NLS-1$
            }
            if (methodReferenceMatch.isSynthetic()) {
                System.out.print("+SYNTHETIC"); //$NON-NLS-1$
            }
        }
        System.out.println("\n\tRaw: " + match.isRaw()); //$NON-NLS-1$
    }
    this.requestor.acceptSearchMatch(match);
    if (BasicSearchEngine.VERBOSE)
        this.resultCollectorTime += System.currentTimeMillis() - start;
}

From source file:org.eclipse.che.jdt.internal.core.JavaModelManager.java

License:Open Source License

public synchronized Object removeInfoAndChildren(JavaElement element) throws JavaModelException {
    Object info = this.cache.peekAtInfo(element);
    if (info != null) {
        boolean wasVerbose = false;
        try {//from  w ww.j  av a  2 s.  c o m
            if (JavaModelCache.VERBOSE) {
                String elementType;
                switch (element.getElementType()) {
                case IJavaElement.JAVA_PROJECT:
                    elementType = "project"; //$NON-NLS-1$
                    break;
                case IJavaElement.PACKAGE_FRAGMENT_ROOT:
                    elementType = "root"; //$NON-NLS-1$
                    break;
                case IJavaElement.PACKAGE_FRAGMENT:
                    elementType = "package"; //$NON-NLS-1$
                    break;
                case IJavaElement.CLASS_FILE:
                    elementType = "class file"; //$NON-NLS-1$
                    break;
                case IJavaElement.COMPILATION_UNIT:
                    elementType = "compilation unit"; //$NON-NLS-1$
                    break;
                default:
                    elementType = "element"; //$NON-NLS-1$
                }
                System.out.println(Thread.currentThread() + " CLOSING " + elementType + " "
                        + element.toStringWithAncestors()); //$NON-NLS-1$//$NON-NLS-2$
                wasVerbose = true;
                JavaModelCache.VERBOSE = false;
            }
            element.closing(info);
            if (element instanceof IParent) {
                closeChildren(info);
            }
            this.cache.removeInfo(element);
            if (wasVerbose) {
                System.out.println(this.cache.toStringFillingRation("-> ")); //$NON-NLS-1$
            }
        } finally {
            JavaModelCache.VERBOSE = wasVerbose;
        }
        return info;
    }
    return null;
}

From source file:org.eclipse.jdt.internal.core.JavaModelManager.java

License:Open Source License

public synchronized Object removeInfoAndChildren(JavaElement element) throws JavaModelException {
    Object info = this.cache.peekAtInfo(element);
    if (info != null) {
        boolean wasVerbose = false;
        try {/* w  w w  .  jav a 2  s.c  o m*/
            if (JavaModelCache.VERBOSE) {
                String elementType;
                switch (element.getElementType()) {
                case IJavaElement.JAVA_PROJECT:
                    elementType = "project"; //$NON-NLS-1$
                    break;
                case IJavaElement.PACKAGE_FRAGMENT_ROOT:
                    elementType = "root"; //$NON-NLS-1$
                    break;
                case IJavaElement.PACKAGE_FRAGMENT:
                    elementType = "package"; //$NON-NLS-1$
                    break;
                case IJavaElement.CLASS_FILE:
                    elementType = "class file"; //$NON-NLS-1$
                    break;
                case IJavaElement.COMPILATION_UNIT:
                    elementType = "compilation unit"; //$NON-NLS-1$
                    break;
                default:
                    elementType = "element"; //$NON-NLS-1$
                }
                System.out.println(Thread.currentThread() + " CLOSING " + elementType + " " //$NON-NLS-1$//$NON-NLS-2$
                        + element.toStringWithAncestors());
                wasVerbose = true;
                JavaModelCache.VERBOSE = false;
            }
            element.closing(info);
            if (element instanceof IParent) {
                closeChildren(info);
            }
            this.cache.removeInfo(element);
            if (wasVerbose) {
                System.out.println(this.cache.toStringFillingRation("-> ")); //$NON-NLS-1$
            }
        } finally {
            JavaModelCache.VERBOSE = wasVerbose;
        }
        return info;
    }
    return null;
}

From source file:org.eclipse.objectteams.otdt.tests.AbstractJavaModelTests.java

License:Open Source License

protected void sortElements(IJavaElement[] elements) {
    Util.Comparer comparer = new Util.Comparer() {
        public int compare(Object a, Object b) {
            JavaElement elementA = (JavaElement) a;
            JavaElement elementB = (JavaElement) b;
            char[] tempJCLPath = "<externalJCLPath>".toCharArray();
            String idA = new String(CharOperation.replace(elementA.toStringWithAncestors().toCharArray(),
                    getExternalJCLPathString().toCharArray(), tempJCLPath));
            String idB = new String(CharOperation.replace(elementB.toStringWithAncestors().toCharArray(),
                    getExternalJCLPathString().toCharArray(), tempJCLPath));
            return idA.compareTo(idB);
        }/* w w w .  jav  a  2s .c  o  m*/
    };
    Util.sort(elements, comparer);
}