下面列出了org.eclipse.lsp4j.SymbolInformation#setLocation ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected SymbolInformation createSymbol(EObject object) {
String name = getSymbolName(object);
if (name == null) {
return null;
}
SymbolKind kind = getSymbolKind(object);
if (kind == null) {
return null;
}
Location location = getSymbolLocation(object);
if (location == null) {
return null;
}
SymbolInformation symbol = new SymbolInformation();
symbol.setName(name);
symbol.setKind(kind);
symbol.setLocation(location);
return symbol;
}
private void collectChildren(ITypeRoot unit, IJavaElement[] elements, ArrayList<SymbolInformation> symbols,
IProgressMonitor monitor)
throws JavaModelException {
for (IJavaElement element : elements) {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
if (element instanceof IParent) {
collectChildren(unit, filter(((IParent) element).getChildren()), symbols, monitor);
}
int type = element.getElementType();
if (type != IJavaElement.TYPE && type != IJavaElement.FIELD && type != IJavaElement.METHOD) {
continue;
}
Location location = JDTUtils.toLocation(element);
if (location != null) {
SymbolInformation si = new SymbolInformation();
String name = JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT);
si.setName(name == null ? element.getElementName() : name);
si.setKind(mapKind(element));
if (element.getParent() != null) {
si.setContainerName(element.getParent().getElementName());
}
location.setUri(ResourceUtils.toClientUri(location.getUri()));
si.setLocation(location);
if (!symbols.contains(si)) {
symbols.add(si);
}
}
}
}
/**
* @since 2.16
*/
protected SymbolInformation createSymbol(String uri, DocumentSymbol symbol,
Function1<? super DocumentSymbol, ? extends String> containerNameProvider) {
SymbolInformation symbolInformation = new SymbolInformation();
symbolInformation.setName(symbol.getName());
symbolInformation.setKind(symbol.getKind());
symbolInformation.setDeprecated(symbol.getDeprecated());
Location location = new Location();
location.setUri(uri);
location.setRange(symbol.getSelectionRange());
symbolInformation.setLocation(location);
symbolInformation.setContainerName(containerNameProvider.apply(symbol));
return symbolInformation;
}
public SymbolInformation read(final JsonReader in) throws IOException {
JsonToken nextToken = in.peek();
if (nextToken == JsonToken.NULL) {
return null;
}
SymbolInformation result = new SymbolInformation();
in.beginObject();
while (in.hasNext()) {
String name = in.nextName();
switch (name) {
case "name":
result.setName(readName(in));
break;
case "kind":
result.setKind(readKind(in));
break;
case "deprecated":
result.setDeprecated(readDeprecated(in));
break;
case "location":
result.setLocation(readLocation(in));
break;
case "containerName":
result.setContainerName(readContainerName(in));
break;
default:
in.skipValue();
}
}
in.endObject();
return result;
}
public SymbolInformation definitionToSymbolInformation(IDefinition definition, ILspProject project)
{
String definitionBaseName = definition.getBaseName();
if (definitionBaseName.length() == 0)
{
//vscode expects all items to have a name
return null;
}
Location location = getLocationFromDefinition(definition, project);
if (location == null)
{
//we can't find where the source code for this symbol is located
return null;
}
SymbolInformation symbol = new SymbolInformation();
symbol.setKind(LanguageServerCompilerUtils.getSymbolKindFromDefinition(definition));
if (!definition.getQualifiedName().equals(definitionBaseName))
{
symbol.setContainerName(definition.getPackageName());
}
else if (definition instanceof ITypeDefinition)
{
symbol.setContainerName("No Package");
}
else
{
IDefinition parentDefinition = definition.getParent();
if (parentDefinition != null)
{
symbol.setContainerName(parentDefinition.getQualifiedName());
}
}
symbol.setName(definitionBaseName);
symbol.setLocation(location);
IDeprecationInfo deprecationInfo = definition.getDeprecationInfo();
if (deprecationInfo != null)
{
symbol.setDeprecated(true);
}
return symbol;
}