Search in sources :

Example 1 with Region

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));
}
Also used : Region(org.springframework.ide.vscode.commons.util.text.Region) IRegion(org.springframework.ide.vscode.commons.util.text.IRegion) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException)

Example 2 with Region

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;
}
Also used : Node(org.yaml.snakeyaml.nodes.Node) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) Region(org.springframework.ide.vscode.commons.util.text.Region) IRegion(org.springframework.ide.vscode.commons.util.text.IRegion)

Example 3 with Region

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;
}
Also used : Region(org.springframework.ide.vscode.commons.util.text.Region)

Example 4 with Region

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]);
}
Also used : AnnotationTypeDeclaration(org.eclipse.jdt.core.dom.AnnotationTypeDeclaration) Region(org.springframework.ide.vscode.commons.util.text.Region) AnnotationTypeDeclaration(org.eclipse.jdt.core.dom.AnnotationTypeDeclaration) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) Stack(java.util.Stack) ASTVisitor(org.eclipse.jdt.core.dom.ASTVisitor) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration)

Example 5 with Region

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;
}
Also used : Region(org.springframework.ide.vscode.commons.util.text.Region)

Aggregations

Region (org.springframework.ide.vscode.commons.util.text.Region)7 PlaceHolder (org.springframework.ide.vscode.commons.languageserver.util.PlaceHolderString.PlaceHolder)2 IRegion (org.springframework.ide.vscode.commons.util.text.IRegion)2 Stack (java.util.Stack)1 ASTVisitor (org.eclipse.jdt.core.dom.ASTVisitor)1 AbstractTypeDeclaration (org.eclipse.jdt.core.dom.AbstractTypeDeclaration)1 AnnotationTypeDeclaration (org.eclipse.jdt.core.dom.AnnotationTypeDeclaration)1 TypeDeclaration (org.eclipse.jdt.core.dom.TypeDeclaration)1 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)1 DocumentRegion (org.springframework.ide.vscode.commons.util.text.DocumentRegion)1 Node (org.yaml.snakeyaml.nodes.Node)1