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();
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations