Search in sources :

Example 1 with SourceLanguagePosition

use of org.graalvm.compiler.graph.SourceLanguagePosition in project graal by oracle.

the class BinaryGraphPrinter method methodLocation.

@Override
public Iterable<SourceLanguagePosition> methodLocation(ResolvedJavaMethod method, int bci, NodeSourcePosition pos) {
    StackTraceElement e = methodStackTraceElement(method, bci, pos);
    class JavaSourcePosition implements SourceLanguagePosition {

        @Override
        public String toShortString() {
            return e.toString();
        }

        @Override
        public int getOffsetEnd() {
            return -1;
        }

        @Override
        public int getOffsetStart() {
            return -1;
        }

        @Override
        public int getLineNumber() {
            return e.getLineNumber();
        }

        @Override
        public URI getURI() {
            String path = e.getFileName();
            try {
                return path == null ? null : new URI(null, null, path, null);
            } catch (URISyntaxException ex) {
                throw new IllegalArgumentException(ex);
            }
        }

        @Override
        public String getLanguage() {
            return "Java";
        }
    }
    List<SourceLanguagePosition> arr = new ArrayList<>();
    arr.add(new JavaSourcePosition());
    NodeSourcePosition at = pos;
    while (at != null) {
        SourceLanguagePosition cur = at.getSourceLanguage();
        if (cur != null) {
            arr.add(cur);
        }
        at = at.getCaller();
    }
    return arr;
}
Also used : SourceLanguagePosition(org.graalvm.compiler.graph.SourceLanguagePosition) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition)

Aggregations

URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 NodeSourcePosition (org.graalvm.compiler.graph.NodeSourcePosition)1 SourceLanguagePosition (org.graalvm.compiler.graph.SourceLanguagePosition)1