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