• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Location类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.lsp4j.Location的典型用法代码示例。如果您正苦于以下问题:Java Location类的具体用法?Java Location怎么用?Java Location使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Location类属于org.eclipse.lsp4j包,在下文中一共展示了Location类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: findPath

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
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))));
}
 
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:22,代码来源:FindSymbols.java


示例2: toLocation

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:27,代码来源:JDTUtils.java


示例3: definition

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
@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));
	});
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:17,代码来源:JDTLanguageServer.java


示例4: computeDefinitionNavigation

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
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;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:NavigateToDefinitionHandler.java


示例5: testReference

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
@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());
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:17,代码来源:ReferencesHandlerTest.java


示例6: testWorkspaceSearch

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
@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://"));
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:18,代码来源:WorkspaceSymbolHandlerTest.java


示例7: testSyntheticMember

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
@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);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:27,代码来源:DocumentSymbolHandlerTest.java


示例8: testResolveImplementationsCodeLense

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
@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());
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:40,代码来源:CodeLensHandlerTest.java


示例9: definition

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
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);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:17,代码来源:LanguageServerImpl.java


示例10: references

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
@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);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:21,代码来源:LanguageServerImpl.java


示例11: getDefinitions

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
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;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:22,代码来源:DocumentSymbolService.java


示例12: getReferences

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
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;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:22,代码来源:DocumentSymbolService.java


示例13: createSymbol

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
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;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:20,代码来源:DocumentSymbolService.java


示例14: actionPerformed

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
@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);
          });
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:FindDefinitionAction.java


示例15: doFindReferences

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
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);
}
 
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:8,代码来源:References.java


示例16: findIn

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
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();
}
 
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:15,代码来源:FindSymbols.java


示例17: findElementName

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
/** 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);
}
 
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:11,代码来源:FindSymbols.java


示例18: definition

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
@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);
}
 
开发者ID:smarr,项目名称:SOMns-vscode,代码行数:9,代码来源:SomLanguageServer.java


示例19: getDefinitions

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
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;
}
 
开发者ID:smarr,项目名称:SOMns-vscode,代码行数:39,代码来源:SomAdapter.java


示例20: addAllDefinitions

import org.eclipse.lsp4j.Location; //导入依赖的package包/类
private void addAllDefinitions(final ArrayList<Location> result, final SSymbol name) {
  synchronized (structuralProbes) {
    for (SomStructures s : structuralProbes.values()) {
      s.getDefinitionsFor(name, result);
    }
  }
}
 
开发者ID:smarr,项目名称:SOMns-vscode,代码行数:8,代码来源:SomAdapter.java



注:本文中的org.eclipse.lsp4j.Location类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ItemWandCasting类代码示例发布时间:2022-05-23
下一篇:
Java DatabaseFunction类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap