Search in sources :

Example 16 with DocumentRegion

use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.

the class FunctionUtils method getFunctionBean.

private static Tuple3<String, String, DocumentRegion> getFunctionBean(TypeDeclaration typeDeclaration, TextDocument doc, ITypeBinding resolvedType) {
    ITypeBinding[] interfaces = resolvedType.getInterfaces();
    for (ITypeBinding resolvedInterface : interfaces) {
        String simplifiedType = null;
        if (resolvedInterface.isParameterizedType()) {
            simplifiedType = resolvedInterface.getBinaryName();
        } else {
            simplifiedType = resolvedType.getQualifiedName();
        }
        if (FUNCTION_FUNCTION_TYPE.equals(simplifiedType) || FUNCTION_CONSUMER_TYPE.equals(simplifiedType) || FUNCTION_SUPPLIER_TYPE.equals(simplifiedType)) {
            String beanName = getBeanName(typeDeclaration);
            String beanType = resolvedInterface.getName();
            DocumentRegion region = ASTUtils.nodeRegion(doc, typeDeclaration.getName());
            return Tuples.of(beanName, beanType, region);
        } else {
            Tuple3<String, String, DocumentRegion> result = getFunctionBean(typeDeclaration, doc, resolvedInterface);
            if (result != null) {
                return result;
            }
        }
    }
    ITypeBinding superclass = resolvedType.getSuperclass();
    if (superclass != null) {
        return getFunctionBean(typeDeclaration, doc, superclass);
    } else {
        return null;
    }
}
Also used : ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion)

Example 17 with DocumentRegion

use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.

the class DataRepositorySymbolProvider method getRepositoryBean.

private static Tuple4<String, String, String, DocumentRegion> getRepositoryBean(TypeDeclaration typeDeclaration, TextDocument doc, ITypeBinding resolvedType) {
    ITypeBinding[] interfaces = resolvedType.getInterfaces();
    for (ITypeBinding resolvedInterface : interfaces) {
        String simplifiedType = null;
        if (resolvedInterface.isParameterizedType()) {
            simplifiedType = resolvedInterface.getBinaryName();
        } else {
            simplifiedType = resolvedType.getQualifiedName();
        }
        if (REPOSITORY_TYPE.equals(simplifiedType)) {
            String beanName = getBeanName(typeDeclaration);
            String beanType = resolvedInterface.getName();
            String domainType = null;
            if (resolvedInterface.isParameterizedType()) {
                ITypeBinding[] typeParameters = resolvedInterface.getTypeArguments();
                if (typeParameters != null && typeParameters.length > 0) {
                    domainType = typeParameters[0].getName();
                }
            }
            DocumentRegion region = ASTUtils.nodeRegion(doc, typeDeclaration.getName());
            return Tuples.of(beanName, beanType, domainType, region);
        } else {
            Tuple4<String, String, String, DocumentRegion> result = getRepositoryBean(typeDeclaration, doc, resolvedInterface);
            if (result != null) {
                return result;
            }
        }
    }
    ITypeBinding superclass = resolvedType.getSuperclass();
    if (superclass != null) {
        return getRepositoryBean(typeDeclaration, doc, superclass);
    } else {
        return null;
    }
}
Also used : ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion)

Example 18 with DocumentRegion

use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.

the class BeansSymbolProvider method getSymbols.

@Override
public Collection<EnhancedSymbolInformation> getSymbols(Annotation node, ITypeBinding annotationType, Collection<ITypeBinding> metaAnnotations, TextDocument doc) {
    if (isMethodAbstract(node))
        return null;
    ImmutableList.Builder<EnhancedSymbolInformation> symbols = ImmutableList.builder();
    boolean isFunction = isFunctionBean(node);
    String beanType = getBeanType(node);
    for (Tuple2<String, DocumentRegion> nameAndRegion : getBeanNames(node, doc)) {
        try {
            symbols.add(new EnhancedSymbolInformation(new SymbolInformation(beanLabel(isFunction, nameAndRegion.getT1(), beanType, "@Bean"), SymbolKind.Interface, new Location(doc.getUri(), doc.toRange(nameAndRegion.getT2()))), null));
        } catch (BadLocationException e) {
            Log.log(e);
        }
    }
    return symbols.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) EnhancedSymbolInformation(org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation) EnhancedSymbolInformation(org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException) Location(org.eclipse.lsp4j.Location)

Example 19 with DocumentRegion

use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.

the class YamlCompletionEngine method dedented.

public ScoreableProposal dedented(ICompletionProposal proposal, int numSpacesToRemove, IDocument doc) {
    Assert.isLegal(numSpacesToRemove > 0);
    int spacesEnd = proposal.getTextEdit().getFirstEditStart();
    int spacesStart = spacesEnd - numSpacesToRemove;
    int numArrows = numSpacesToRemove / YamlIndentUtil.INDENT_BY;
    String spaces = new DocumentRegion(doc, spacesStart, spacesEnd).toString();
    YamlIndentUtil indenter = new YamlIndentUtil(doc);
    if (spaces.length() == numSpacesToRemove && SPACES.matcher(spaces).matches()) {
        ScoreableProposal transformed = new TransformedCompletion(proposal) {

            @Override
            public String tranformLabel(String originalLabel) {
                return Strings.repeat(Unicodes.LEFT_ARROW + " ", numArrows) + originalLabel;
            }

            @Override
            public DocumentEdits transformEdit(DocumentEdits originalEdit) {
                originalEdit.firstDelete(spacesStart, spacesEnd);
                originalEdit.transformFirstNonWhitespaceEdit((offset, insertText) -> {
                    String prefix = insertText.substring(0, offset);
                    String dedented = indenter.applyIndentation(insertText.substring(offset), -numSpacesToRemove);
                    return prefix + dedented;
                });
                return originalEdit;
            }

            @Override
            public String getFilterText() {
                // to replace. Since we are replacing these removed spaces, they must be part of the filtertext
                return spaces + super.getFilterText();
            }
        };
        transformed.deemphasize(DEEMP_DEDENTED_PROPOSAL * numArrows);
        return transformed;
    }
    // in our attempt to de-dent.)
    return null;
}
Also used : DocumentEdits(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits) YamlIndentUtil(org.springframework.ide.vscode.commons.yaml.util.YamlIndentUtil) ScoreableProposal(org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion)

Example 20 with DocumentRegion

use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.

the class YamlHoverInfoProvider method getHoverInfo.

@Override
public Tuple2<Renderable, IRegion> getHoverInfo(IDocument doc, int offset) throws Exception {
    YamlFileAST ast = getAst(doc);
    if (ast != null) {
        IRegion region = getHoverRegion(ast, offset);
        if (region != null) {
            YamlDocument ymlDoc = new YamlDocument(doc, structureProvider);
            YamlAssistContext assistContext = assistContextProvider.getGlobalAssistContext(ymlDoc);
            if (assistContext != null) {
                List<NodeRef<?>> astPath = ast.findPath(offset);
                final YamlPath path = YamlPath.fromASTPath(astPath);
                if (path != null) {
                    YamlPath assistPath = path;
                    if (assistPath.pointsAtKey()) {
                        // When a path points at a key we must tramsform it to a
                        // 'value-terminating path'
                        // to be able to reuse the 'getHoverInfo' method on
                        // YamlAssistContext (as navigation
                        // into 'key' is not defined for YamlAssistContext.
                        String key = path.getLastSegment().toPropString();
                        assistPath = path.dropLast().append(YamlPathSegment.valueAt(key));
                    }
                    assistContext = assistPath.traverse(assistContext);
                    if (assistContext != null) {
                        Renderable info = path.pointsAtValue() ? assistContext.getValueHoverInfo(ymlDoc, new DocumentRegion(doc, region)) : assistContext.getHoverInfo();
                        // Fix for: PT 134914895. If assist context cannot provide an info, then don't return a Tuple.
                        if (info != null) {
                            return Tuples.of(info, region);
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : NodeRef(org.springframework.ide.vscode.commons.yaml.ast.NodeRef) YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) Renderable(org.springframework.ide.vscode.commons.util.Renderable) YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST) YamlDocument(org.springframework.ide.vscode.commons.yaml.structure.YamlDocument) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) YamlAssistContext(org.springframework.ide.vscode.commons.yaml.completion.YamlAssistContext) IRegion(org.springframework.ide.vscode.commons.util.text.IRegion)

Aggregations

DocumentRegion (org.springframework.ide.vscode.commons.util.text.DocumentRegion)25 ICompletionProposal (org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal)6 PropertyInfo (org.springframework.ide.vscode.boot.metadata.PropertyInfo)5 ArrayList (java.util.ArrayList)4 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)4 ValueParseException (org.springframework.ide.vscode.commons.util.ValueParseException)4 StsValueHint (org.springframework.ide.vscode.boot.metadata.hints.StsValueHint)3 Type (org.springframework.ide.vscode.boot.metadata.types.Type)3 DocumentEdits (org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits)3 Renderable (org.springframework.ide.vscode.commons.util.Renderable)3 IRegion (org.springframework.ide.vscode.commons.util.text.IRegion)3 ImmutableList (com.google.common.collect.ImmutableList)2 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)2 Location (org.eclipse.lsp4j.Location)2 SymbolInformation (org.eclipse.lsp4j.SymbolInformation)2 CommonLanguageTools.getValueType (org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType)2 EnumCaseMode (org.springframework.ide.vscode.boot.metadata.types.TypeUtil.EnumCaseMode)2 PropertyNavigator (org.springframework.ide.vscode.boot.properties.reconcile.PropertyNavigator)2 ReconcileException (org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileException)2 IDocument (org.springframework.ide.vscode.commons.util.text.IDocument)2