Java 类org.eclipse.lsp4j.Location 实例源码

项目:vscode-javac    文件:FindSymbols.java   
private static Optional<Location> findPath(TreePath path, Trees trees) {
    CompilationUnitTree compilationUnit = path.getCompilationUnit();
    long start = trees.getSourcePositions().getStartPosition(compilationUnit, path.getLeaf());
    long end = trees.getSourcePositions().getEndPosition(compilationUnit, path.getLeaf());

    if (start == Diagnostic.NOPOS) return Optional.empty();

    if (end == Diagnostic.NOPOS) end = start;

    int startLine = (int) compilationUnit.getLineMap().getLineNumber(start);
    int startColumn = (int) compilationUnit.getLineMap().getColumnNumber(start);
    int endLine = (int) compilationUnit.getLineMap().getLineNumber(end);
    int endColumn = (int) compilationUnit.getLineMap().getColumnNumber(end);

    return Optional.of(
            new Location(
                    compilationUnit.getSourceFile().toUri().toString(),
                    new Range(
                            new Position(startLine - 1, startColumn - 1),
                            new Position(endLine - 1, endColumn - 1))));
}
项目:eclipse.jdt.ls    文件:JDTUtils.java   
/**
 * Creates a location for a given java element.
 * Element can be a {@link ICompilationUnit} or {@link IClassFile}
 *
 * @param element
 * @return location or null
 * @throws JavaModelException
 */
public static Location toLocation(IJavaElement element) throws JavaModelException{
    ICompilationUnit unit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
    IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE);
    if (unit == null && cf == null) {
        return null;
    }
    if (element instanceof ISourceReference) {
        ISourceRange nameRange = getNameRange(element);
        if (SourceRange.isAvailable(nameRange)) {
            if (cf == null) {
                return toLocation(unit, nameRange.getOffset(), nameRange.getLength());
            } else {
                return toLocation(cf, nameRange.getOffset(), nameRange.getLength());
            }
        }
    }
    return null;
}
项目:eclipse.jdt.ls    文件:JDTLanguageServer.java   
@Override
public CompletableFuture<List<? extends Location>> definition(TextDocumentPositionParams position) {
    logInfo(">> document/definition");
    NavigateToDefinitionHandler handler = new NavigateToDefinitionHandler(this.preferenceManager);
    return computeAsync((cc) -> {
        IProgressMonitor monitor = toMonitor(cc);
        try {
            Job.getJobManager().join(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, monitor);
        } catch (OperationCanceledException ignorable) {
            // No need to pollute logs when query is cancelled
        } catch (InterruptedException e) {
            JavaLanguageServerPlugin.logException(e.getMessage(), e);
        }
        return handler.definition(position, toMonitor(cc));
    });
}
项目:eclipse.jdt.ls    文件:NavigateToDefinitionHandler.java   
private Location computeDefinitionNavigation(ITypeRoot unit, int line, int column, IProgressMonitor monitor) {
    try {
        IJavaElement element = JDTUtils.findElementAtSelection(unit, line, column, this.preferenceManager, monitor);
        if (element == null) {
            return null;
        }
        ICompilationUnit compilationUnit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
        IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE);
        if (compilationUnit != null || (cf != null && cf.getSourceRange() != null)  ) {
            return JDTUtils.toLocation(element);
        }
        if (element instanceof IMember && ((IMember) element).getClassFile() != null) {
            return JDTUtils.toLocation(((IMember) element).getClassFile());
        }
    } catch (JavaModelException e) {
        JavaLanguageServerPlugin.logException("Problem computing definition for" +  unit.getElementName(), e);
    }
    return null;
}
项目:eclipse.jdt.ls    文件:ReferencesHandlerTest.java   
@Test
public void testReference(){
    URI uri = project.getFile("src/java/Foo2.java").getRawLocationURI();
    String fileURI = ResourceUtils.fixURI(uri);

    ReferenceParams param = new ReferenceParams();
    param.setPosition(new Position(5,16));
    param.setContext(new ReferenceContext(true));
    param.setTextDocument( new TextDocumentIdentifier(fileURI));
    List<Location> references =  handler.findReferences(param, monitor);
    assertNotNull("findReferences should not return null",references);
    assertEquals(1, references.size());
    Location l = references.get(0);
    String refereeUri = ResourceUtils.fixURI(project.getFile("src/java/Foo3.java").getRawLocationURI());
    assertEquals(refereeUri, l.getUri());
}
项目:eclipse.jdt.ls    文件:WorkspaceSymbolHandlerTest.java   
@Test
public void testWorkspaceSearch() {
    String query = "Abstract";
    List<SymbolInformation> results = handler.search(query, monitor);
    assertNotNull(results);
    assertEquals("Found " + results.size() + " results", 33, results.size());
    Range defaultRange = JDTUtils.newRange();
    for (SymbolInformation symbol : results) {
        assertNotNull("Kind is missing", symbol.getKind());
        assertNotNull("ContainerName is missing", symbol.getContainerName());
        assertTrue(symbol.getName().startsWith(query));
        Location location = symbol.getLocation();
        assertEquals(defaultRange, location.getRange());
        //No class in the workspace project starts with Abstract, so everything comes from the JDK
        assertTrue("Unexpected uri "+ location.getUri(), location.getUri().startsWith("jdt://"));
    }
}
项目:eclipse.jdt.ls    文件:DocumentSymbolHandlerTest.java   
@Test
public void testSyntheticMember() throws Exception {
    String className = "org.apache.commons.lang3.text.StrTokenizer";
    List<? extends SymbolInformation> symbols = getSymbols(className);
    boolean overloadedMethod1Found = false;
    boolean overloadedMethod2Found = false;
    String overloadedMethod1 = "getCSVInstance(String)";
    String overloadedMethod2 = "reset()";
    for (SymbolInformation symbol : symbols) {
        Location loc = symbol.getLocation();
        assertTrue("Class: " + className + ", Symbol:" + symbol.getName() + " - invalid location.",
                loc != null && isValid(loc.getRange()));
        assertFalse("Class: " + className + ", Symbol:" + symbol.getName() + " - invalid name",
                symbol.getName().startsWith("access$"));
        assertFalse("Class: " + className + ", Symbol:" + symbol.getName() + "- invalid name",
                symbol.getName().equals("<clinit>"));
        if (overloadedMethod1.equals(symbol.getName())) {
            overloadedMethod1Found = true;
        }
        if (overloadedMethod2.equals(symbol.getName())) {
            overloadedMethod2Found = true;
        }
    }
    assertTrue("The " + overloadedMethod1 + " method hasn't been found", overloadedMethod1Found);
    assertTrue("The " + overloadedMethod2 + " method hasn't been found", overloadedMethod2Found);
}
项目:eclipse.jdt.ls    文件:CodeLensHandlerTest.java   
@SuppressWarnings("unchecked")
@Test
public void testResolveImplementationsCodeLense() {
    String source = "src/java/IFoo.java";
    String payload = createCodeLensImplementationsRequest(source, 5, 17, 21);

    CodeLens lens = getParams(payload);
    Range range = lens.getRange();
    assertRange(5, 17, 21, range);

    CodeLens result = handler.resolve(lens, monitor);
    assertNotNull(result);

    //Check if command found
    Command command = result.getCommand();
    assertNotNull(command);
    assertEquals("2 implementations", command.getTitle());
    assertEquals("java.show.implementations", command.getCommand());

    //Check codelens args
    List<Object> args = command.getArguments();
    assertEquals(3, args.size());

    //Check we point to the Bar class
    String sourceUri = args.get(0).toString();
    assertTrue(sourceUri.endsWith("IFoo.java"));

    //CodeLens position
    Map<String, Object> map = (Map<String, Object>) args.get(1);
    assertEquals(5.0, map.get("line"));
    assertEquals(17.0, map.get("character"));

    //Reference location
    List<Location> locations = (List<Location>) args.get(2);
    assertEquals(2, locations.size());
    Location loc = locations.get(0);
    assertTrue(loc.getUri().endsWith("src/java/Foo2.java"));
    assertRange(5, 13, 17, loc.getRange());
}
项目:xtext-core    文件:LanguageServerImpl.java   
protected List<? extends Location> definition(final CancelIndicator cancelIndicator, final TextDocumentPositionParams params) {
  final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri());
  final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri);
  DocumentSymbolService _get = null;
  if (resourceServiceProvider!=null) {
    _get=resourceServiceProvider.<DocumentSymbolService>get(DocumentSymbolService.class);
  }
  final DocumentSymbolService documentSymbolService = _get;
  if ((documentSymbolService == null)) {
    return CollectionLiterals.<Location>emptyList();
  }
  final Function2<Document, XtextResource, List<? extends Location>> _function = (Document document, XtextResource resource) -> {
    return documentSymbolService.getDefinitions(document, resource, params, this.resourceAccess, cancelIndicator);
  };
  return this.workspaceManager.<List<? extends Location>>doRead(uri, _function);
}
项目:xtext-core    文件:LanguageServerImpl.java   
@Override
public CompletableFuture<List<? extends Location>> references(final ReferenceParams params) {
  final Function1<CancelIndicator, List<? extends Location>> _function = (CancelIndicator cancelIndicator) -> {
    final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri());
    final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri);
    DocumentSymbolService _get = null;
    if (resourceServiceProvider!=null) {
      _get=resourceServiceProvider.<DocumentSymbolService>get(DocumentSymbolService.class);
    }
    final DocumentSymbolService documentSymbolService = _get;
    if ((documentSymbolService == null)) {
      return CollectionLiterals.<Location>emptyList();
    }
    final Function2<Document, XtextResource, List<? extends Location>> _function_1 = (Document document, XtextResource resource) -> {
      return documentSymbolService.getReferences(document, resource, params, this.resourceAccess, this.workspaceManager.getIndex(), cancelIndicator);
    };
    return this.workspaceManager.<List<? extends Location>>doRead(uri, _function_1);
  };
  return this.requestManager.<List<? extends Location>>runRead(_function);
}
项目:xtext-core    文件:DocumentSymbolService.java   
public List<? extends Location> getDefinitions(final XtextResource resource, final int offset, final IReferenceFinder.IResourceAccess resourceAccess, final CancelIndicator cancelIndicator) {
  final EObject element = this._eObjectAtOffsetHelper.resolveElementAt(resource, offset);
  if ((element == null)) {
    return CollectionLiterals.<Location>emptyList();
  }
  final ArrayList<Location> locations = CollectionLiterals.<Location>newArrayList();
  final TargetURIs targetURIs = this.collectTargetURIs(element);
  for (final URI targetURI : targetURIs) {
    {
      this.operationCanceledManager.checkCanceled(cancelIndicator);
      final Procedure1<EObject> _function = (EObject obj) -> {
        final Location location = this._documentExtensions.newLocation(obj);
        if ((location != null)) {
          locations.add(location);
        }
      };
      this.doRead(resourceAccess, targetURI, _function);
    }
  }
  return locations;
}
项目:xtext-core    文件:DocumentSymbolService.java   
public List<? extends Location> getReferences(final XtextResource resource, final int offset, final IReferenceFinder.IResourceAccess resourceAccess, final IResourceDescriptions indexData, final CancelIndicator cancelIndicator) {
  final EObject element = this._eObjectAtOffsetHelper.resolveElementAt(resource, offset);
  if ((element == null)) {
    return CollectionLiterals.<Location>emptyList();
  }
  final ArrayList<Location> locations = CollectionLiterals.<Location>newArrayList();
  final TargetURIs targetURIs = this.collectTargetURIs(element);
  final IAcceptor<IReferenceDescription> _function = (IReferenceDescription reference) -> {
    final Procedure1<EObject> _function_1 = (EObject obj) -> {
      final Location location = this._documentExtensions.newLocation(obj, reference.getEReference(), reference.getIndexInList());
      if ((location != null)) {
        locations.add(location);
      }
    };
    this.doRead(resourceAccess, reference.getSourceEObjectUri(), _function_1);
  };
  ReferenceAcceptor _referenceAcceptor = new ReferenceAcceptor(this.resourceServiceProviderRegistry, _function);
  CancelIndicatorProgressMonitor _cancelIndicatorProgressMonitor = new CancelIndicatorProgressMonitor(cancelIndicator);
  this.referenceFinder.findAllReferences(targetURIs, resourceAccess, indexData, _referenceAcceptor, _cancelIndicatorProgressMonitor);
  return locations;
}
项目:xtext-core    文件:DocumentSymbolService.java   
protected SymbolInformation createSymbol(final EObject object) {
  final String name = this.getSymbolName(object);
  if ((name == null)) {
    return null;
  }
  final SymbolKind kind = this.getSymbolKind(object);
  if ((kind == null)) {
    return null;
  }
  final Location location = this.getSymbolLocation(object);
  if ((location == null)) {
    return null;
  }
  final SymbolInformation symbol = new SymbolInformation();
  symbol.setName(name);
  symbol.setKind(kind);
  symbol.setLocation(location);
  return symbol;
}
项目:che    文件:FindDefinitionAction.java   
@Override
public void actionPerformed(ActionEvent e) {
  EditorPartPresenter activeEditor = editorAgent.getActiveEditor();

  TextEditor textEditor = ((TextEditor) activeEditor);
  TextDocumentPositionParams paramsDTO =
      dtoBuildHelper.createTDPP(textEditor.getDocument(), textEditor.getCursorPosition());

  final Promise<List<Location>> promise = client.definition(paramsDTO);
  promise
      .then(
          arg -> {
            if (arg.size() == 1) {
              presenter.onLocationSelected(arg.get(0));
            } else {
              presenter.openLocation(promise);
            }
          })
      .catchError(
          arg -> {
            presenter.showError(arg);
          });
}
项目:vscode-javac    文件:References.java   
private Stream<Location> doFindReferences(TreePath cursor) {
    Trees trees = Trees.instance(task);
    Element symbol = trees.getElement(cursor);

    if (symbol == null) return Stream.empty();
    else return find.references(symbol);
}
项目:vscode-javac    文件:FindSymbols.java   
private Optional<Location> findIn(Element symbol, URI file) {
    List<Location> result = new ArrayList<>();

    visitElements(
            file,
            (task, found) -> {
                if (sameSymbol(symbol, found)) {
                    findElementName(found, Trees.instance(task)).ifPresent(result::add);
                }
            });

    if (!result.isEmpty()) return Optional.of(result.get(0));
    else return Optional.empty();
}
项目:vscode-javac    文件:FindSymbols.java   
/** Find a more accurate position for symbol by searching for its name. */
private static Optional<Location> findElementName(Element symbol, Trees trees) {
    TreePath path = trees.getPath(symbol);
    Name name =
            symbol.getKind() == ElementKind.CONSTRUCTOR
                    ? symbol.getEnclosingElement().getSimpleName()
                    : symbol.getSimpleName();

    return SymbolIndex.findTreeName(name, path, trees);
}
项目:SOMns-vscode    文件:SomLanguageServer.java   
@Override
public CompletableFuture<List<? extends Location>> definition(
    final TextDocumentPositionParams position) {
  List<? extends Location> result = som.getDefinitions(
      position.getTextDocument().getUri(), position.getPosition().getLine(),
      position.getPosition().getCharacter());
  return CompletableFuture.completedFuture(result);
}
项目:SOMns-vscode    文件:SomAdapter.java   
public List<? extends Location> getDefinitions(final String docUri,
    final int line, final int character) {
  ArrayList<Location> result = new ArrayList<>();
  SomStructures probe = getProbe(docUri);
  if (probe == null) {
    return result;
  }

  // +1 to get to one based index
  ExpressionNode node = probe.getElementAt(line + 1, character);

  if (node == null) {
    return result;
  }

  if (ServerLauncher.DEBUG) {
    reportError(
        "Node at " + (line + 1) + ":" + character + " " + node.getClass().getSimpleName());
  }

  if (node instanceof Send) {
    SSymbol name = ((Send) node).getSelector();
    addAllDefinitions(result, name);
  } else if (node instanceof NonLocalVariableNode) {
    result.add(SomAdapter.getLocation(((NonLocalVariableNode) node).getLocal().source));
  } else if (node instanceof LocalVariableNode) {
    result.add(SomAdapter.getLocation(((LocalVariableNode) node).getLocal().source));
  } else if (node instanceof LocalArgumentReadNode) {
    result.add(SomAdapter.getLocation(((LocalArgumentReadNode) node).getArg().source));
  } else if (node instanceof NonLocalArgumentReadNode) {
    result.add(SomAdapter.getLocation(((NonLocalArgumentReadNode) node).getArg().source));
  } else {
    if (ServerLauncher.DEBUG) {
      reportError("GET DEFINITION, unsupported node: " + node.getClass().getSimpleName());
    }
  }
  return result;
}
项目:SOMns-vscode    文件:SomAdapter.java   
private void addAllDefinitions(final ArrayList<Location> result, final SSymbol name) {
  synchronized (structuralProbes) {
    for (SomStructures s : structuralProbes.values()) {
      s.getDefinitionsFor(name, result);
    }
  }
}
项目:eclipse.jdt.ls    文件:DocumentSymbolHandler.java   
private void collectChildren(ITypeRoot unit, IJavaElement[] elements, ArrayList<SymbolInformation> symbols,
        IProgressMonitor monitor)
        throws JavaModelException {
    for(IJavaElement element : elements ){
        if (monitor.isCanceled()) {
            return;
        }
        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);
            }
        }
    }
}
项目:eclipse.jdt.ls    文件:CodeLensHandler.java   
private List<Location> findImplementations(IType type, IProgressMonitor monitor) throws JavaModelException {
    IType[] results = type.newTypeHierarchy(monitor).getAllSubtypes(type);
    final List<Location> result = new ArrayList<>();
    for (IType t : results) {
        ICompilationUnit compilationUnit = (ICompilationUnit) t.getAncestor(IJavaElement.COMPILATION_UNIT);
        if (compilationUnit == null) {
            continue;
        }
        Location location = JDTUtils.toLocation(t);
        result.add(location);
    }
    return result;
}
项目:eclipse.jdt.ls    文件:ReferencesHandlerTest.java   
@Test
public void testEmpty(){
    ReferenceParams param = new ReferenceParams();
    param.setPosition(new Position(1, 1));
    param.setContext(new ReferenceContext(false));
    param.setTextDocument( new TextDocumentIdentifier("/foo/bar"));
    List<Location> references =  handler.findReferences(param, monitor);
    assertNotNull(references);
    assertTrue("references are not empty", references.isEmpty());
}
项目:eclipse.jdt.ls    文件:WorkspaceSymbolHandlerTest.java   
@Test
public void testProjectSearch() {
    String query = "IFoo";
    List<SymbolInformation> results = handler.search(query, monitor);
    assertNotNull(results);
    assertEquals("Found "+ results.size() + " results", 1, results.size());
    SymbolInformation symbol = results.get(0);
    assertEquals(SymbolKind.Interface, symbol.getKind());
    assertEquals("java", symbol.getContainerName());
    assertEquals(query, symbol.getName());
    Location location = symbol.getLocation();
    assertEquals(JDTUtils.newRange(), location.getRange());
    assertTrue("Unexpected uri "+ location.getUri(), location.getUri().endsWith("Foo.java"));
}
项目:eclipse.jdt.ls    文件:NavigateToDefinitionHandlerTest.java   
@Test
public void testGetEmptyDefinition() throws Exception {
    List<? extends Location> definitions = handler.definition(
            new TextDocumentPositionParams(new TextDocumentIdentifier("/foo/bar"), new Position(1, 1)), monitor);
    assertNotNull(definitions);
    assertEquals(1, definitions.size());
    assertNotNull("Location has no Range", definitions.get(0).getRange());
}
项目:eclipse.jdt.ls    文件:NavigateToDefinitionHandlerTest.java   
private void testClass(String className, int line, int column) throws JavaModelException {
    String uri = ClassFileUtil.getURI(project, className);
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(uri);
    List<? extends Location> definitions = handler
            .definition(new TextDocumentPositionParams(identifier, new Position(line, column)), monitor);
    assertNotNull(definitions);
    assertEquals(1, definitions.size());
    assertNotNull(definitions.get(0).getUri());
    assertTrue(definitions.get(0).getRange().getStart().getLine() >= 0);
}
项目:eclipse.jdt.ls    文件:DocumentSymbolHandlerTest.java   
private void testClass(String className)
        throws JavaModelException, UnsupportedEncodingException, InterruptedException, ExecutionException {
    List<? extends SymbolInformation> symbols = getSymbols(className);
    for (SymbolInformation symbol : symbols) {
        Location loc = symbol.getLocation();
        assertTrue("Class: " + className + ", Symbol:" + symbol.getName() + " - invalid location.",
                loc != null && isValid(loc.getRange()));
    }
}
项目:eclipse.jdt.ls    文件:CodeLensHandlerTest.java   
@SuppressWarnings("unchecked")
@Test
public void testResolveCodeLense() {
    String source = "src/java/Foo.java";
    String payload = createCodeLensRequest(source, 5, 13, 16);

    CodeLens lens = getParams(payload);
    Range range = lens.getRange();
    assertRange(5, 13, 16, range);

    CodeLens result = handler.resolve(lens, monitor);
    assertNotNull(result);

    //Check if command found
    Command command = result.getCommand();
    assertNotNull(command);
    assertEquals("1 reference", command.getTitle());
    assertEquals("java.show.references",command.getCommand());

    //Check codelens args
    List<Object> args = command.getArguments();
    assertEquals(3,args.size());

    //Check we point to the Bar class
    String sourceUri = args.get(0).toString();
    assertTrue(sourceUri.endsWith(source));

    //CodeLens position
    Map<String, Object> map = (Map<String, Object>)args.get(1);
    assertEquals(5.0, map.get("line"));
    assertEquals(13.0, map.get("character"));

    //Reference location
    List<Location> locations = (List<Location>)args.get(2);
    assertEquals(1, locations.size());
    Location loc = locations.get(0);
    assertTrue(loc.getUri().endsWith("src/java/Bar.java"));
    assertRange(5, 25, 28, loc.getRange());
}
项目:eclipse.jdt.ls    文件:ClassFileUtil.java   
@Override
public void acceptTypeNameMatch(TypeNameMatch match) {
    try {
        if (match.getType().isBinary()) {
            Location location = JDTUtils.toLocation(match.getType().getClassFile());
            if (location != null) {
                uri = location.getUri();
            }
        }  else {
            uri = match.getType().getResource().getLocationURI().toString();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:xtext-core    文件:AbstractLanguageServerTest.java   
protected String _toExpectation(final Location it) {
  StringConcatenation _builder = new StringConcatenation();
  Path _relativize = this.relativize(it.getUri());
  _builder.append(_relativize);
  _builder.append(" ");
  String _expectation = this.toExpectation(it.getRange());
  _builder.append(_expectation);
  return _builder.toString();
}
项目:xtext-core    文件:AbstractLanguageServerTest.java   
protected void testDefinition(final Procedure1<? super DefinitionTestConfiguration> configurator) {
  try {
    @Extension
    final DefinitionTestConfiguration configuration = new DefinitionTestConfiguration();
    configuration.setFilePath(("MyModel." + this.fileExtension));
    configurator.apply(configuration);
    final String fileUri = this.initializeContext(configuration).getUri();
    TextDocumentPositionParams _textDocumentPositionParams = new TextDocumentPositionParams();
    final Procedure1<TextDocumentPositionParams> _function = (TextDocumentPositionParams it) -> {
      TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
      it.setTextDocument(_textDocumentIdentifier);
      int _line = configuration.getLine();
      int _column = configuration.getColumn();
      Position _position = new Position(_line, _column);
      it.setPosition(_position);
    };
    TextDocumentPositionParams _doubleArrow = ObjectExtensions.<TextDocumentPositionParams>operator_doubleArrow(_textDocumentPositionParams, _function);
    final CompletableFuture<List<? extends Location>> definitionsFuture = this.languageServer.definition(_doubleArrow);
    final List<? extends Location> definitions = definitionsFuture.get();
    Procedure1<? super List<? extends Location>> _assertDefinitions = configuration.getAssertDefinitions();
    boolean _tripleNotEquals = (_assertDefinitions != null);
    if (_tripleNotEquals) {
      configuration.getAssertDefinitions().apply(definitions);
    } else {
      final String actualDefinitions = this.toExpectation(definitions);
      this.assertEquals(configuration.getExpectedDefinitions(), actualDefinitions);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-core    文件:LanguageServerImpl.java   
@Override
public CompletableFuture<List<? extends Location>> definition(final TextDocumentPositionParams params) {
  final Function1<CancelIndicator, List<? extends Location>> _function = (CancelIndicator cancelIndicator) -> {
    return this.definition(cancelIndicator, params);
  };
  return this.requestManager.<List<? extends Location>>runRead(_function);
}
项目:xtext-core    文件:DocumentSymbolService.java   
public List<? extends Location> getReferences(final Document document, final XtextResource resource, final ReferenceParams params, final IReferenceFinder.IResourceAccess resourceAccess, final IResourceDescriptions indexData, final CancelIndicator cancelIndicator) {
  final int offset = document.getOffSet(params.getPosition());
  List<? extends Location> _xifexpression = null;
  boolean _isIncludeDeclaration = params.getContext().isIncludeDeclaration();
  if (_isIncludeDeclaration) {
    _xifexpression = this.getDefinitions(resource, offset, resourceAccess, cancelIndicator);
  } else {
    _xifexpression = CollectionLiterals.emptyList();
  }
  final List<? extends Location> definitions = _xifexpression;
  final List<? extends Location> references = this.getReferences(resource, offset, resourceAccess, indexData, cancelIndicator);
  final Iterable<Location> result = Iterables.<Location>concat(definitions, references);
  return IterableExtensions.<Location>toList(result);
}
项目:xtext-core    文件:DocumentSymbolService.java   
protected void createSymbol(final IEObjectDescription description, final IReferenceFinder.IResourceAccess resourceAccess, final Procedure1<? super SymbolInformation> acceptor) {
  final String name = this.getSymbolName(description);
  if ((name == null)) {
    return;
  }
  final SymbolKind kind = this.getSymbolKind(description);
  if ((kind == null)) {
    return;
  }
  final Procedure1<Location> _function = (Location location) -> {
    final SymbolInformation symbol = new SymbolInformation(name, kind, location);
    acceptor.apply(symbol);
  };
  this.getSymbolLocation(description, resourceAccess, _function);
}
项目:xtext-core    文件:DocumentSymbolService.java   
protected void getSymbolLocation(final IEObjectDescription description, final IReferenceFinder.IResourceAccess resourceAccess, final Procedure1<? super Location> acceptor) {
  final Procedure1<EObject> _function = (EObject obj) -> {
    final Location location = this.getSymbolLocation(obj);
    if ((location != null)) {
      acceptor.apply(location);
    }
  };
  this.doRead(resourceAccess, description.getEObjectURI(), _function);
}
项目:xtext-core    文件:DocumentExtensions.java   
public Location newLocation(final Resource resource, final ITextRegion textRegion) {
  final Range range = this.newRange(resource, textRegion);
  if ((range == null)) {
    return null;
  }
  final String uri = this._uriExtensions.toUriString(resource.getURI());
  return new Location(uri, range);
}
项目:che    文件:FindReferencesAction.java   
@Override
public void actionPerformed(ActionEvent e) {
  EditorPartPresenter activeEditor = editorAgent.getActiveEditor();

  // TODO replace this
  if (!(activeEditor instanceof TextEditor)) {
    return;
  }
  TextEditor textEditor = ((TextEditor) activeEditor);
  String path = activeEditor.getEditorInput().getFile().getLocation().toString();
  ReferenceParams paramsDTO = dtoFactory.createDto(ReferenceParams.class);

  Position Position = dtoFactory.createDto(Position.class);
  Position.setLine(textEditor.getCursorPosition().getLine());
  Position.setCharacter(textEditor.getCursorPosition().getCharacter());

  TextDocumentIdentifier identifierDTO = dtoFactory.createDto(TextDocumentIdentifier.class);
  identifierDTO.setUri(path);

  ReferenceContext contextDTO = dtoFactory.createDto(ReferenceContext.class);
  contextDTO.setIncludeDeclaration(true);

  paramsDTO.setUri(path);
  paramsDTO.setPosition(Position);
  paramsDTO.setTextDocument(identifierDTO);
  paramsDTO.setContext(contextDTO);
  Promise<List<Location>> promise = client.references(paramsDTO);
  presenter.openLocation(promise);
}
项目:che    文件:FindSymbolAction.java   
private List<SymbolEntry> toSymbolEntries(List<SymbolInformation> types, String value) {
  List<SymbolEntry> result = new ArrayList<>();
  for (SymbolInformation element : types) {
    if (!SUPPORTED_OPEN_TYPES.contains(symbolKindHelper.from(element.getKind()))) {
      continue;
    }
    List<Match> matches = fuzzyMatches.fuzzyMatch(value, element.getName());
    if (matches != null) {
      Location location = element.getLocation();
      if (location != null && location.getUri() != null) {
        String filePath = location.getUri();
        Range locationRange = location.getRange();

        TextRange range = null;
        if (locationRange != null) {
          range =
              new TextRange(
                  new TextPosition(
                      locationRange.getStart().getLine(),
                      locationRange.getStart().getCharacter()),
                  new TextPosition(
                      locationRange.getEnd().getLine(), locationRange.getEnd().getCharacter()));
        }
        result.add(
            new SymbolEntry(
                element.getName(),
                "",
                filePath,
                filePath,
                symbolKindHelper.from(element.getKind()),
                range,
                symbolKindHelper.getIcon(element.getKind()),
                editorHelper,
                matches));
      }
    }
  }
  // TODO add sorting
  return result;
}
项目:che    文件:OpenLocationViewImpl.java   
@Override
public void setLocations(List<Location> locations) {
  tree.getNodeStorage().clear();
  // TODO workaround, tree has bug with adding list of nodes
  for (Location location : locations) {
    tree.getNodeStorage().add(new LocationNode(location));
  }

  tree.expandAll();

  if (!tree.getRootNodes().isEmpty()) {
    tree.getSelectionModel().select(tree.getRootNodes().get(0), false);
  }
}
项目:che    文件:OpenLocationPresenter.java   
@Override
public void onLocationSelected(Location location) {
  Range range = location.getRange();
  helper.openFile(
      location.getUri(),
      new TextRange(
          new TextPosition(range.getStart().getLine(), range.getStart().getCharacter()),
          new TextPosition(range.getEnd().getLine(), range.getEnd().getCharacter())));
}