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(boolean showResolvedInfo) 

Source Link

Document

Debugging purposes

Usage

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

License:Open Source License

protected void assertElementsEqual(String message, String expected, IJavaElement[] elements,
        boolean showResolvedInfo) {
    StringBuffer buffer = new StringBuffer();
    if (elements != null) {
        for (int i = 0, length = elements.length; i < length; i++) {
            JavaElement element = (JavaElement) elements[i];
            if (element == null) {
                buffer.append("<null>");
            } else {
                buffer.append(element.toStringWithAncestors(showResolvedInfo));
            }/*from  w ww.j  a  v  a 2s. c  om*/
            if (i != length - 1)
                buffer.append("\n");
        }
    } else {
        buffer.append("<null>");
    }
    String actual = buffer.toString();
    if (!expected.equals(actual)) {
        if (this.displayName)
            System.out.println(getName() + " actual result is:");
        System.out.println(displayString(actual, this.tabs) + this.endChar);
    }
    assertEquals(message, expected, actual);
}

From source file:org.eclipse.objectteams.otdt.tests.model.CompletionTestsRequestor2.java

License:Open Source License

public String getContext() {
    if (this.context == null)
        return "";

    StringBuffer buffer = new StringBuffer();

    if (!this.shortContext) {
        buffer.append("completion offset=");
        buffer.append(context.getOffset());
        buffer.append('\n');

        buffer.append("completion range=[");
        buffer.append(context.getTokenStart());
        buffer.append(", ");
        buffer.append(context.getTokenEnd());
        buffer.append("]\n");

        char[] token = context.getToken();
        buffer.append("completion token=");
        if (token == null) {
            buffer.append("null");
        } else {//from   w w w.  ja v  a2 s . co  m
            buffer.append('\"');
            buffer.append(token);
            buffer.append('\"');
        }
        buffer.append('\n');

        buffer.append("completion token kind=");
        int tokenKind = context.getTokenKind();
        if (tokenKind == CompletionContext.TOKEN_KIND_STRING_LITERAL) {
            buffer.append("TOKEN_KIND_STRING_LITERAL");
        } else if (tokenKind == CompletionContext.TOKEN_KIND_NAME) {
            buffer.append("TOKEN_KIND_NAME");
        } else {
            buffer.append("TOKEN_KIND_UNKNOWN");
        }
        buffer.append('\n');
    }
    char[][] expectedTypesSignatures = this.context.getExpectedTypesSignatures();
    buffer.append("expectedTypesSignatures=");
    if (expectedTypesSignatures == null) {
        buffer.append(NULL_LITERAL);
    } else {
        buffer.append('{');
        for (int i = 0; i < expectedTypesSignatures.length; i++) {
            if (i > 0)
                buffer.append(',');
            buffer.append(expectedTypesSignatures[i]);

        }
        buffer.append('}');
    }
    buffer.append('\n');

    char[][] expectedTypesKeys = this.context.getExpectedTypesKeys();
    buffer.append("expectedTypesKeys=");
    if (expectedTypesSignatures == null) {
        buffer.append(NULL_LITERAL);
    } else {
        buffer.append('{');
        for (int i = 0; i < expectedTypesKeys.length; i++) {
            if (i > 0)
                buffer.append(',');
            buffer.append(expectedTypesKeys[i]);

        }
        buffer.append('}');
    }

    if (!this.shortContext) {
        buffer.append('\n');

        int locationType = this.context.getTokenLocation();
        if (locationType == 0) {
            buffer.append("completion token location=UNKNOWN"); //$NON-NLS-1$
        } else {
            buffer.append("completion token location={"); //$NON-NLS-1$
            boolean first = true;
            if ((locationType & CompletionContext.TL_MEMBER_START) != 0) {
                if (!first)
                    buffer.append(',');
                buffer.append("MEMBER_START"); //$NON-NLS-1$
                first = false;
            }
            if ((locationType & CompletionContext.TL_STATEMENT_START) != 0) {
                if (!first)
                    buffer.append(',');
                buffer.append("STATEMENT_START"); //$NON-NLS-1$
                first = false;
            }
            buffer.append('}');
        }
    }

    if (this.computeEnclosingElement) {
        buffer.append('\n');
        buffer.append("enclosingElement="); //$NON-NLS-1$
        JavaElement enclosingElement = (JavaElement) this.context.getEnclosingElement();
        if (enclosingElement == null) {
            buffer.append("null"); //$NON-NLS-1$
        } else {
            buffer.append(enclosingElement.toStringWithAncestors(true /*show resolved info*/));
        }
    }

    if (this.computeVisibleElements) {
        buffer.append('\n');

        IJavaElement[] visibleElements = this.context.getVisibleElements(this.assignableType);
        buffer.append("visibleElements="); //$NON-NLS-1$
        if (visibleElements == null) {
            buffer.append("null"); //$NON-NLS-1$
        } else if (visibleElements.length == 0) {
            buffer.append("{}"); //$NON-NLS-1$
        } else {
            buffer.append('{');
            buffer.append('\n');
            for (int i = 0; i < visibleElements.length; i++) {
                JavaElement element = (JavaElement) visibleElements[i];
                buffer.append('\t');
                buffer.append(element.toStringWithAncestors(true /*show resolved info*/));
                buffer.append(",\n"); //$NON-NLS-1$
            }
            buffer.append('}');
        }
    }

    //buffer.append('\n');

    return buffer.toString();
}