@Override @Pure public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; DiagnosticRelatedInformation other = (DiagnosticRelatedInformation) obj; if (this.location == null) { if (other.location != null) return false; } else if (!this.location.equals(other.location)) return false; if (this.message == null) { if (other.message != null) return false; } else if (!this.message.equals(other.message)) return false; return true; }
@Override public Optional<Location> gotoDefinition(URI uri, Position position) { List<Location> possibleLocations = indexer.getGotoReferenced().keySet().stream() .filter(loc -> uri.equals(URI.create(loc.getUri())) && Ranges.contains(loc.getRange(), position)) // If there is more than one result, we want the symbol whose range starts the latest, with a secondary // sort of earliest end range. .sorted((l1, l2) -> Ranges.POSITION_COMPARATOR.compare(l1.getRange().getEnd(), l2.getRange().getEnd())) .sorted((l1, l2) -> Ranges.POSITION_COMPARATOR.reversed().compare(l1.getRange().getStart(), l2.getRange().getStart())) .collect(Collectors.toList()); if (possibleLocations.isEmpty()) { return Optional.absent(); } return indexer.gotoReferenced(possibleLocations.get(0)); }
/** * Creates a location from the given URI with an undefined range. */ public static Location createLocation(URI uri) { return new Location(uri.toString(), Ranges.UNDEFINED_RANGE); }
/** * @since 2.16 */ protected SymbolInformation createSymbol(final String uri, final DocumentSymbol symbol, final Function1<? super DocumentSymbol, ? extends String> containerNameProvider) { SymbolInformation _symbolInformation = new SymbolInformation(); final Procedure1<SymbolInformation> _function = (SymbolInformation it) -> { it.setName(symbol.getName()); it.setKind(symbol.getKind()); it.setDeprecated(symbol.getDeprecated()); Location _location = new Location(); final Procedure1<Location> _function_1 = (Location it_1) -> { it_1.setUri(uri); it_1.setRange(symbol.getSelectionRange()); }; Location _doubleArrow = ObjectExtensions.<Location>operator_doubleArrow(_location, _function_1); it.setLocation(_doubleArrow); it.setContainerName(containerNameProvider.apply(symbol)); }; return ObjectExtensions.<SymbolInformation>operator_doubleArrow(_symbolInformation, _function); }
/** * The range enclosing this symbol not including leading/trailing whitespace but everything else * like comments. */ public Range getRange(final EObject object) { Location _newFullLocation = this._documentExtensions.newFullLocation(object); Range _range = null; if (_newFullLocation!=null) { _range=_newFullLocation.getRange(); } return _range; }
.filter(symbol -> Ranges.isValid(symbol.getLocation().getRange())).collect(Collectors.toSet()); "Coordinates", SymbolKind.Class, new Location(fileUri, Ranges.createRange(0, 0, 1, 0))), new SymbolInformation( "getAt", SymbolKind.Method, new Location(fileUri, Ranges.createRange(4, 3, 10, 4)), "Coordinates"), new SymbolInformation( "latitude", SymbolKind.Field, new Location(fileUri, Ranges.createRange(1, 3, 1, 18)), "Coordinates"), new SymbolInformation( "longitude", SymbolKind.Field, new Location(fileUri, Ranges.createRange(2, 3, 2, 19)), "Coordinates"), new SymbolInformation( "name", SymbolKind.Field, new Location(fileUri, Ranges.createRange(3, 3, 3, 23)), "Coordinates"), new SymbolInformation( "idx1", SymbolKind.Variable, new Location(fileUri, Ranges.createRange(4, 16, 4, 24)), "getAt"), new SymbolInformation(
private SpanElement createTitleOfElement(SymbolInformation symbolInformation) { String path = symbolInformation.getLocation().getUri(); SpanElement texElement = Elements.createSpanElement(); SpanElement highlightElement = Elements.createSpanElement(javaResources.css().presentableTextContainer()); highlightElement.setInnerText(" - (" + path + ')'); texElement.setInnerText(symbolInformation.getName()); texElement.appendChild(highlightElement); return texElement; }
/** * Creates a default location for the uri. * * @param classFile * @return location * @throws JavaModelException */ public static Location toLocation(String uri) { return new Location(ResourceUtils.toClientUri(uri), newRange()); }
Location l = new Location(); TextDocumentPositionParams position = definitionContext.get(DocumentServiceKeys.POSITION_KEY); String parentPath = new LSDocument(position.getTextDocument().getUri()).getSourceRoot(); .name.getValue(), parentPath, definitionContext .get(NodeContextKeys.PACKAGE_OF_NODE_KEY).name.getValue()), fileName); l.setUri(filePath.toUri().toString()); Range r = new Range(); r.setEnd(new Position(bLangNode.getPosition().getEndLine() - 1, bLangNode.getPosition().getEndColumn() - 1)); l.setRange(r); contents.add(l);
public LocationDto(org.eclipse.lsp4j.Location o) { if (o.getUri() == null) { setUri((java.lang.String)null); } else { java.lang.String uriVal = (java.lang.String)makeDto(o.getUri());; setUri((java.lang.String)uriVal); } if (o.getRange() == null) { setRange((org.eclipse.lsp4j.Range)null); } else { org.eclipse.lsp4j.Range rangeVal = new RangeDto(o.getRange()); setRange((org.eclipse.lsp4j.Range)rangeVal); } }
private Range getRange(IJavaElement element) throws JavaModelException { Location location = JDTUtils.toLocation(element, FULL_RANGE); return location == null ? DEFAULT_RANGE : location.getRange(); }
@Override public void visitPropertyExpression(PropertyExpression expression) { if (expression.getObjectExpression() instanceof VariableExpression) { // This means it's a non static reference to a class variable VariableExpression var = (VariableExpression) expression.getObjectExpression(); FieldNode field = var.getType().getField(expression.getProperty().getText()); if (classes.containsKey(var.getType().getName())) { indexer.addReference(createLocation(URI.create(classes.get(var.getType().getName()).getUri()), field), createLocation(expression.getProperty())); } } else if (expression.getObjectExpression() instanceof ClassExpression) { // This means it's a static reference to a class variable ClassExpression classExpression = (ClassExpression) expression.getObjectExpression(); FieldNode field = classExpression.getType().getField(expression.getProperty().getText()); if (classes.containsKey(classExpression.getType().getName())) { indexer.addReference( createLocation(URI.create(classes.get(classExpression.getType().getName()).getUri()), field), createLocation(expression.getProperty())); } } super.visitPropertyExpression(expression); }
private Collection<? extends SymbolInformationDto> convertDocumentSymbol( DocumentSymbol symbol, String uri) { ArrayList<SymbolInformationDto> result = new ArrayList<>(); result.add( new SymbolInformationDto( new SymbolInformation( symbol.getName(), symbol.getKind(), new Location(uri, symbol.getRange())))); for (DocumentSymbol child : symbol.getChildren()) { result.addAll(convertDocumentSymbol(child, uri)); } return result; } },
/** * Get the physical source location of the given package. * * @param bLangNode ballerina language node references are requested for * @param ownerPackageName list of name compositions of the node's package name * @param currentPackageName list of name compositions of the current package * @return location of the package of the given node */ private Location getLocation(BLangNode bLangNode, String ownerPackageName, String currentPackageName) { Location l = new Location(); Range r = new Range(); TextDocumentPositionParams position = this.context.get(DocumentServiceKeys.POSITION_KEY); String parentPath = new LSDocument(position.getTextDocument().getUri()).getSourceRoot(); if (parentPath != null) { String fileName = bLangNode.getPosition().getSource().getCompilationUnitName(); Path filePath = Paths.get(CommonUtil.getPackageURI(currentPackageName, parentPath, ownerPackageName), fileName); l.setUri(filePath.toUri().toString()); // Subtract 1 to convert the token lines and char positions to zero based indexing r.setStart(new Position(bLangNode.getPosition().getStartLine() - 1, bLangNode.getPosition().getStartColumn() - 1)); r.setEnd(new Position(bLangNode.getPosition().getEndLine() - 1, bLangNode.getPosition().getEndColumn() - 1)); l.setRange(r); } return l; }
private Range getSelectionRange(IJavaElement element) throws JavaModelException { Location location = JDTUtils.toLocation(element); return location == null ? DEFAULT_RANGE : location.getRange(); }