diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/value/ValueHoverProvider.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/value/ValueHoverProvider.java index 3935e597f..6789ad80c 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/value/ValueHoverProvider.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/value/ValueHoverProvider.java @@ -44,33 +44,43 @@ public class ValueHoverProvider implements HoverProvider { protected static Logger logger = LoggerFactory.getLogger(ValueHoverProvider.class); @Override - public Hover provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset, - TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) { + public Hover provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset, TextDocument doc, + IJavaProject project, SpringBootApp[] runningApps) { try { - ASTNode exactNode = NodeFinder.perform(node, offset, 0); + ASTNode exactNode = getExactNode(node, offset); - // case: @Value("prefix<*>") - if (exactNode != null && exactNode instanceof StringLiteral && exactNode.getParent() instanceof Annotation) { - if (exactNode.toString().startsWith("\"") && exactNode.toString().endsWith("\"")) { - return provideHover(exactNode.toString(), offset - exactNode.getStartPosition(), exactNode.getStartPosition(), doc, runningApps); - } + if (exactNode != null) { + return provideHover(exactNode.toString(), offset - exactNode.getStartPosition(), + exactNode.getStartPosition(), doc, runningApps); } - // case: @Value(value="prefix<*>") - else if (exactNode != null && exactNode instanceof StringLiteral && exactNode.getParent() instanceof MemberValuePair - && "value".equals(((MemberValuePair)exactNode.getParent()).getName().toString())) { - if (exactNode.toString().startsWith("\"") && exactNode.toString().endsWith("\"")) { - return provideHover(exactNode.toString(), offset - exactNode.getStartPosition(), exactNode.getStartPosition(), doc, runningApps); - } - } - } - catch (Exception e) { + } catch (Exception e) { logger.error("Error while generating live hovers for @Value", e); } return null; } + private ASTNode getExactNode(ASTNode node, int offset) { + ASTNode exactNode = NodeFinder.perform(node, offset, 0); + if (exactNode != null) { + // case: @Value("prefix<*>") + if (exactNode instanceof StringLiteral && exactNode.getParent() instanceof Annotation) { + if (exactNode.toString().startsWith("\"") && exactNode.toString().endsWith("\"")) { + return exactNode; + } + } + // case: @Value(value="prefix<*>") + else if (exactNode instanceof StringLiteral && exactNode.getParent() instanceof MemberValuePair + && "value".equals(((MemberValuePair) exactNode.getParent()).getName().toString())) { + if (exactNode.toString().startsWith("\"") && exactNode.toString().endsWith("\"")) { + return exactNode; + } + } + } + return null; + } + private Hover provideHover(String value, int offset, int nodeStartOffset, TextDocument doc, SpringBootApp[] runningApps) { try {