Sha256: 61a1793f966e5016bd5c6cb7dfac43f9da24cfe7fa9a74e4ee0bec3b7015f3c3
Contents?: true
Size: 1.74 KB
Versions: 12
Compression:
Stored size: 1.74 KB
Contents
package org.cx4a.rsense.util; import org.jrubyparser.ast.Node; import org.jrubyparser.SourcePosition; import org.cx4a.rsense.typing.vertex.Vertex; public class SourceLocation { private String file; private int line; public SourceLocation(String file, int line) { this.file = file; this.line = line; } public String getFile() { return file; } public int getLine() { return line; } @Override public int hashCode() { return line ^ (file != null ? file.hashCode() : 0); } @Override public boolean equals(Object other) { if (this == other) return true; else if (!(other instanceof SourceLocation)) return false; SourceLocation o = (SourceLocation) other; return line == o.line && ((file == null && o.file == null) || (file != null && file.equals(o.file))); } @Override public String toString() { return file + ":" + line; } public static SourceLocation of(Node node) { SourcePosition pos = node.getPosition(); //TODO : find out about SourcePosition.INVALID_POSITION // if (pos != null && pos != SourcePosition.INVALID_POSITION) { // return new SourceLocation(pos.getFile(), pos.getStartLine() + 1); // } else { // return null; // } if (pos != null) { return new SourceLocation(pos.getFile(), pos.getStartLine() + 1); } else { return null; } } public static SourceLocation of(Vertex vertex) { if (vertex != null && vertex.getNode() != null) { return of(vertex.getNode()); } else { return null; } } }
Version data entries
12 entries across 12 versions & 1 rubygems