use of org.springframework.ide.vscode.commons.util.text.Region in project sts4 by spring-projects.
the class ListLineTracker method getLineInformationOfOffset.
@Override
public final IRegion getLineInformationOfOffset(int position) throws BadLocationException {
if (position > fTextLength)
throw new BadLocationException();
if (position == fTextLength) {
int size = fLines.size();
if (size == 0)
return new Region(0, 0);
Line l = fLines.get(size - 1);
return (l.delimiter != null ? new Line(fTextLength, 0) : new Line(fTextLength - l.length, l.length));
}
return getLineInformation(findLine(position));
}
use of org.springframework.ide.vscode.commons.util.text.Region in project sts4 by spring-projects.
the class YamlHoverInfoProvider method getHoverRegion.
private IRegion getHoverRegion(YamlFileAST ast, int offset) {
if (ast != null) {
Node n = ast.findNode(offset);
if (n != null && n.getNodeId() == NodeId.scalar) {
int start = n.getStartMark().getIndex();
int end = n.getEndMark().getIndex();
return new Region(start, end - start);
}
}
return null;
}
use of org.springframework.ide.vscode.commons.util.text.Region in project sts4 by spring-projects.
the class VSCodeSourceLinks method positionLink.
@Override
protected String positionLink(CompilationUnit cu, String fqName) {
if (cu != null) {
Region region = findTypeRegion(cu, fqName);
if (region != null) {
int column = cu.getColumnNumber(region.getOffset());
int line = cu.getLineNumber(region.getOffset());
StringBuilder sb = new StringBuilder();
sb.append('#');
sb.append(line);
sb.append(',');
// 1-based columns?
sb.append(column + 1);
return sb.toString();
}
}
return null;
}
use of org.springframework.ide.vscode.commons.util.text.Region in project sts4 by spring-projects.
the class AbstractSourceLinks method findTypeRegion.
protected Region findTypeRegion(CompilationUnit cu, String fqName) {
if (cu == null) {
return null;
}
int[] values = new int[] { 0, -1 };
int lastDotIndex = fqName.lastIndexOf('.');
String packageName = fqName.substring(0, lastDotIndex);
String typeName = fqName.substring(lastDotIndex + 1);
if (packageName.equals(cu.getPackage().getName().getFullyQualifiedName())) {
Stack<String> visitedType = new Stack<>();
cu.accept(new ASTVisitor() {
private boolean visitDeclaration(AbstractTypeDeclaration node) {
visitedType.push(node.getName().getIdentifier());
if (values[1] < 0) {
if (String.join("$", visitedType.toArray(new String[visitedType.size()])).equals(typeName)) {
values[0] = node.getName().getStartPosition();
values[1] = node.getName().getLength();
}
}
return values[1] < 0;
}
@Override
public boolean visit(TypeDeclaration node) {
return visitDeclaration(node);
}
@Override
public boolean visit(AnnotationTypeDeclaration node) {
return visitDeclaration(node);
}
@Override
public void endVisit(AnnotationTypeDeclaration node) {
visitedType.pop();
super.endVisit(node);
}
@Override
public void endVisit(TypeDeclaration node) {
visitedType.pop();
super.endVisit(node);
}
});
}
return values[1] < 0 ? null : new Region(values[0], values[1]);
}
use of org.springframework.ide.vscode.commons.util.text.Region in project sts4 by spring-projects.
the class AtomSourceLinks method positionLink.
@Override
protected String positionLink(CompilationUnit cu, String fqName) {
if (cu != null) {
Region region = findTypeRegion(cu, fqName);
if (region != null) {
int column = cu.getColumnNumber(region.getOffset());
int line = cu.getLineNumber(region.getOffset());
StringBuilder sb = new StringBuilder();
sb.append("&line=");
sb.append(line);
sb.append("&column=");
// 1-based columns?
sb.append(column + 1);
return sb.toString();
}
}
return null;
}
Aggregations