Search in sources :

Example 1 with SpringBootApp

use of org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp in project sts4 by spring-projects.

the class SpringLiveHoverWatchdog method update.

public void update(String docURI, SpringBootApp[] runningBootApps) {
    if (highlightsEnabled) {
        try {
            if (runningBootApps == null) {
                runningBootApps = runningAppProvider.getAllRunningSpringApps().toArray(new SpringBootApp[0]);
            }
            if (runningBootApps != null && runningBootApps.length > 0) {
                TextDocument doc = this.server.getTextDocumentService().get(docURI);
                if (doc != null) {
                    Range[] ranges = this.hoverProvider.getLiveHoverHints(doc, runningBootApps);
                    publishLiveHints(docURI, ranges);
                }
            } else {
                cleanupLiveHints(docURI);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) Range(org.eclipse.lsp4j.Range)

Example 2 with SpringBootApp

use of org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp in project sts4 by spring-projects.

the class ValueHoverProvider method provideHover.

private Hover provideHover(String value, int offset, int nodeStartOffset, TextDocument doc, SpringBootApp[] runningApps) {
    try {
        LocalRange range = getPropertyRange(value, offset);
        if (range != null) {
            String propertyKey = value.substring(range.getStart(), range.getEnd());
            if (propertyKey != null) {
                Map<SpringBootApp, JSONObject> allProperties = getPropertiesFromProcesses(runningApps);
                StringBuilder hover = new StringBuilder();
                for (SpringBootApp app : allProperties.keySet()) {
                    JSONObject properties = allProperties.get(app);
                    Iterator<?> keys = properties.keys();
                    while (keys.hasNext()) {
                        String key = (String) keys.next();
                        if (properties.get(key) instanceof JSONObject) {
                            JSONObject props = properties.getJSONObject(key);
                            if (props.has(propertyKey)) {
                                String propertyValue = props.getString(propertyKey);
                                hover.append(propertyKey + " : " + propertyValue);
                                hover.append(" (from: " + key + ")\n\n");
                                hover.append(LiveHoverUtils.niceAppName(app));
                                hover.append("\n\n");
                            }
                        }
                    }
                }
                if (hover.length() > 0) {
                    Range hoverRange = doc.toRange(nodeStartOffset + range.getStart(), range.getEnd() - range.getStart());
                    Hover result = new Hover(ImmutableList.of(Either.forLeft(hover.toString())));
                    result.setRange(hoverRange);
                    return result;
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) JSONObject(org.json.JSONObject) Hover(org.eclipse.lsp4j.Hover) Range(org.eclipse.lsp4j.Range)

Example 3 with SpringBootApp

use of org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp in project sts4 by spring-projects.

the class AbstractInjectedIntoHoverProvider method provideHover.

@Override
public Hover provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset, TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) {
    if (runningApps.length > 0) {
        LiveBean definedBean = getDefinedBean(annotation);
        if (definedBean != null) {
            StringBuilder hover = new StringBuilder();
            hover.append("**Injection report for " + LiveHoverUtils.showBean(definedBean) + "**\n\n");
            boolean hasInterestingApp = false;
            for (SpringBootApp app : runningApps) {
                LiveBeansModel beans = app.getBeans();
                List<LiveBean> relevantBeans = LiveHoverUtils.findRelevantBeans(app, definedBean).collect(Collectors.toList());
                if (!relevantBeans.isEmpty()) {
                    if (!hasInterestingApp) {
                        hasInterestingApp = true;
                    } else {
                        hover.append("\n\n");
                    }
                    hover.append(LiveHoverUtils.niceAppName(app) + ":");
                    for (LiveBean bean : relevantBeans) {
                        addInjectedInto(definedBean, hover, beans, bean, project);
                        addAutomaticallyWiredContructor(hover, annotation, beans, bean, project);
                    }
                }
            }
            if (hasInterestingApp) {
                return new Hover(ImmutableList.of(Either.forLeft(hover.toString())));
            }
        }
    }
    return null;
}
Also used : SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Hover(org.eclipse.lsp4j.Hover) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) LiveBean(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean)

Example 4 with SpringBootApp

use of org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp in project sts4 by spring-projects.

the class ComponentInjectionsHoverProvider method provideHover.

@Override
public Hover provideHover(ASTNode node, TypeDeclaration typeDeclaration, ITypeBinding type, int offset, TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) {
    if (runningApps.length > 0 && !isComponentAnnotatedType(typeDeclaration)) {
        LiveBean definedBean = getDefinedBeanForType(typeDeclaration, null);
        if (definedBean != null) {
            StringBuilder hover = new StringBuilder();
            hover.append("**Injection report for " + LiveHoverUtils.showBean(definedBean) + "**\n\n");
            boolean hasInterestingApp = false;
            for (SpringBootApp app : runningApps) {
                LiveBeansModel beans = app.getBeans();
                List<LiveBean> relevantBeans = LiveHoverUtils.findRelevantBeans(app, definedBean).collect(Collectors.toList());
                if (!relevantBeans.isEmpty()) {
                    if (!hasInterestingApp) {
                        hasInterestingApp = true;
                    } else {
                        hover.append("\n\n");
                    }
                    hover.append(LiveHoverUtils.niceAppName(app) + ":");
                    for (LiveBean bean : relevantBeans) {
                        addInjectedInto(definedBean, hover, beans, bean, project);
                    }
                }
            }
            if (hasInterestingApp) {
                return new Hover(ImmutableList.of(Either.forLeft(hover.toString())));
            }
        }
    }
    return null;
}
Also used : SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Hover(org.eclipse.lsp4j.Hover) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) LiveBean(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean)

Example 5 with SpringBootApp

use of org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp in project sts4 by spring-projects.

the class AutowiredHoverProvider method provideHover.

@Override
public Hover provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset, TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) {
    if (runningApps.length > 0) {
        StringBuilder hover = new StringBuilder();
        LiveBean definedBean = getDefinedBean(annotation);
        if (definedBean != null) {
            hover.append("**Injection report for " + LiveHoverUtils.showBean(definedBean) + "**\n\n");
            boolean hasInterestingApp = false;
            boolean hasAutowiring = false;
            for (SpringBootApp app : runningApps) {
                LiveBeansModel beans = app.getBeans();
                List<LiveBean> relevantBeans = LiveHoverUtils.findRelevantBeans(app, definedBean).collect(Collectors.toList());
                if (!relevantBeans.isEmpty()) {
                    if (!hasInterestingApp) {
                        hasInterestingApp = true;
                    } else {
                        hover.append("\n\n");
                    }
                    hover.append(LiveHoverUtils.niceAppName(app) + ":");
                    for (LiveBean bean : relevantBeans) {
                        hover.append("\n\n");
                        hasAutowiring |= addAutomaticallyWired(hover, annotation, beans, bean, project);
                    }
                }
            }
            if (hasInterestingApp && hasAutowiring) {
                return new Hover(ImmutableList.of(Either.forLeft(hover.toString())));
            }
        }
    }
    return null;
}
Also used : SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Hover(org.eclipse.lsp4j.Hover) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) LiveBean(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean)

Aggregations

SpringBootApp (org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp)9 Hover (org.eclipse.lsp4j.Hover)6 Range (org.eclipse.lsp4j.Range)4 LiveBean (org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean)4 LiveBeansModel (org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel)4 Stream (java.util.stream.Stream)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 IJavaProject (org.springframework.ide.vscode.commons.java.IJavaProject)2 Log (org.springframework.ide.vscode.commons.util.Log)2 Renderables (org.springframework.ide.vscode.commons.util.Renderables)2 ImmutableList (com.google.common.collect.ImmutableList)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 ASTNode (org.eclipse.jdt.core.dom.ASTNode)1 Annotation (org.eclipse.jdt.core.dom.Annotation)1 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)1 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)1