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

Java TargetElementUtil类代码示例

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

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



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

示例1: createHighlightUsagesHandler

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
@Nullable
@Override
@RequiredReadAction
public HighlightUsagesHandlerBase createHighlightUsagesHandler(Editor editor, PsiFile file)
{
	int offset = TargetElementUtil.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset());
	PsiElement target = file.findElementAt(offset);
	if(target != null && target.getNode().getElementType() == CSharpDocTokenType.XML_NAME)
	{
		CSharpDocTagImpl docTag = PsiTreeUtil.getParentOfType(target, CSharpDocTagImpl.class);
		if(docTag == null)
		{
			return null;
		}
		return new CSharpDocTagHighlightUsagesHandler(editor, file, docTag);
	}
	return null;
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:19,代码来源:CSharpDocHighlightUsagesHandlerFactory.java


示例2: createHighlightUsagesHandler

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
@Nullable
@Override
@RequiredReadAction
public HighlightUsagesHandlerBase createHighlightUsagesHandler(Editor editor, PsiFile file)
{
	int offset = TargetElementUtil.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset());
	PsiElement target = file.findElementAt(offset);
	if(target != null && target.getNode().getElementType() == CSharpTokens.USING_KEYWORD)
	{
		CSharpUsingListChild listChild = PsiTreeUtil.getParentOfType(target, CSharpUsingListChild.class);
		if(listChild == null)
		{
			return null;
		}
		return new CSharpUsingHighlightUsagesHandler(editor, file, listChild);
	}
	return null;
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:19,代码来源:CSharpHighlightUsagesHandlerFactory.java


示例3: elementToFqn

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
@Nullable
public static String elementToFqn(final PsiElement element, @Nullable Editor editor) {
  String result = QualifiedNameProviders.getQualifiedNameFromProviders(element);
  if (result != null) return result;

  if (editor != null) { //IDEA-70346
    PsiReference reference = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset());
    if (reference != null) {
      result = QualifiedNameProviders.getQualifiedNameFromProviders(reference.resolve());
      if (result != null) return result;
    }
  }

  String fqn = null;
  if (element instanceof PsiFile) {
    final PsiFile file = (PsiFile)element;
    fqn = FileUtil.toSystemIndependentName(getFileFqn(file));
  }
  return fqn;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:21,代码来源:QualifiedNameProviders.java


示例4: searchImplementations

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
@Nullable
PsiElement[] searchImplementations(Editor editor, PsiElement element, int offset) {
  boolean onRef = ApplicationManager.getApplication().runReadAction((Computable<Boolean>)() -> {
    Set<String> flags = ContainerUtil.newHashSet(getFlags());
    flags.remove(TargetElementUtilEx.REFERENCED_ELEMENT_ACCEPTED);
    flags.remove(TargetElementUtilEx.LOOKUP_ITEM_ACCEPTED);

    return TargetElementUtil.findTargetElement(editor, flags, offset) == null;
  });
  return searchImplementations(element, editor, onRef &&
                                                ApplicationManager.getApplication().runReadAction((Computable<Boolean>)() -> element == null ||
                                                                                                                             TargetElementUtil
                                                                                                                                     .includeSelfInGotoImplementation(
                                                                                                                                             element)),
                               onRef);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:17,代码来源:ImplementationSearcher.java


示例5: elementToFqn

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
@Nullable
private static String elementToFqn(@Nullable final PsiElement element, @Nullable Editor editor) {
  String result = getQualifiedNameFromProviders(element);
  if (result != null) return result;

  if (editor != null) { //IDEA-70346
    PsiReference reference = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset());
    if (reference != null) {
      result = getQualifiedNameFromProviders(reference.resolve());
      if (result != null) return result;
    }
  }

  if (element instanceof PsiFile) {
    return FileUtil.toSystemIndependentName(getFileFqn((PsiFile)element));
  }
  if (element instanceof PsiDirectory) {
    return FileUtil.toSystemIndependentName(getVirtualFileFqn(((PsiDirectory)element).getVirtualFile(), element.getProject()));
  }

  return null;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:23,代码来源:CopyReferenceAction.java


示例6: getNameIdentifier

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
@Override
protected PsiElement getNameIdentifier() {
  final PsiFile currentFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
  if (currentFile == myElementToRename.getContainingFile()){
    return super.getNameIdentifier();
  }
  if (currentFile != null) {
    int offset = myEditor.getCaretModel().getOffset();
    offset = TargetElementUtil.adjustOffset(currentFile, myEditor.getDocument(), offset);
    final PsiElement elementAt = currentFile.findElementAt(offset);
    if (elementAt != null) {
      final PsiElement referenceExpression = elementAt.getParent();
      if (referenceExpression != null) {
        final PsiReference reference = referenceExpression.getReference();
        if (reference != null && reference.resolve() == myElementToRename) {
          return elementAt;
        }
      }
    }
    return null;
  }
  return null;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:24,代码来源:MemberInplaceRenamer.java


示例7: createHighlightUsagesHandler

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
@Override
public HighlightUsagesHandlerBase createHighlightUsagesHandler(final Editor editor, final PsiFile file) {
  int offset = TargetElementUtil.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset());
  PsiElement target = file.findElementAt(offset);
  if (target instanceof PsiKeyword) {
    PsiElement parent = target.getParent();
    if (PsiKeyword.TRY.equals(target.getText()) && parent instanceof PsiTryStatement) {
      return createHighlightTryHandler(editor, file, target, parent);
    }
    if (PsiKeyword.CATCH.equals(target.getText()) && parent instanceof PsiCatchSection) {
      return createHighlightCatchHandler(editor, file, target, parent);
    }
    if (PsiKeyword.THROWS.equals(target.getText())) {
      return createThrowsHandler(editor, file, target);
    }
  }
  return null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:19,代码来源:HighlightExceptionsHandlerFactory.java


示例8: getSymbolTypeDeclarations

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
@RequiredReadAction
@Nullable
@Override
public PsiElement[] getSymbolTypeDeclarations(@NotNull PsiElement targetElement, Editor editor, int offset) {
  PsiType type;
  if (targetElement instanceof PsiVariable){
    type = ((PsiVariable)targetElement).getType();
  }
  else if (targetElement instanceof PsiMethod){
    type = ((PsiMethod)targetElement).getReturnType();
  }
  else{
    return null;
  }
  if (type == null) return null;
  if (editor != null) {
    final PsiReference reference = TargetElementUtil.findReference(editor, offset);
    if (reference instanceof PsiJavaReference) {
      final JavaResolveResult resolveResult = ((PsiJavaReference)reference).advancedResolve(true);
      type = resolveResult.getSubstitutor().substitute(type);
    }
  }
  PsiClass psiClass = PsiUtil.resolveClassInType(type);
  return psiClass == null ? null : new PsiElement[] {psiClass};
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:26,代码来源:JavaTypeDeclarationProvider.java


示例9: getExpression

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
@Nullable
protected PsiExpression getExpression(PsiElement element) {
  if (myMethodCall == null || !myMethodCall.isValid()) {
    return myExpression == null || !myExpression.isValid() ? null : myExpression;
  }
  final PsiElement method = myMethodCall.resolveMethod();
  if (method != null) {
    final PsiMethod psiMethod = (PsiMethod)method;
    return checkMethod(element, psiMethod);
  } else if (myMethodCall instanceof PsiMethodCallExpression){
    final Collection<PsiElement> psiElements = TargetElementUtil.getTargetCandidates(((PsiMethodCallExpression) myMethodCall).getMethodExpression());
    for (PsiElement psiElement : psiElements) {
      if (psiElement instanceof PsiMethod) {
        final PsiExpression expression = checkMethod(element, (PsiMethod)psiElement);
        if (expression != null) return expression;
      }
    }
  }
  return null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:21,代码来源:SurroundWithArrayFix.java


示例10: getTargets

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
@Override
@Nullable
public UsageTarget[] getTargets(Editor editor, final PsiFile file) {
  if (editor == null || file == null) return null;

  PsiElement element = file.findElementAt(TargetElementUtil.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()));
  if (element == null) return null;

  if (element instanceof PsiKeyword && PsiKeyword.THROWS.equals(element.getText())) {
    return new UsageTarget[]{new PsiElement2UsageTargetAdapter(element)};
  }

  final PsiElement parent = element.getParent();
  if (parent instanceof PsiThrowStatement) {
    return new UsageTarget[] {new PsiElement2UsageTargetAdapter(parent)};
  }

  return null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:20,代码来源:ThrowsUsageTargetProvider.java


示例11: canInlineElementInEditor

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
@Override
public boolean canInlineElementInEditor(PsiElement element, Editor editor)
{
	if(canInlineElement(element))
	{
		PsiReference reference = editor != null ? TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset()) : null;
		if(!InlineMethodHandler.isThisReference(reference))
		{
			if(element instanceof PsiMethod && reference != null)
			{
				final PsiElement referenceElement = reference.getElement();
				return referenceElement != null && !PsiTreeUtil.isAncestor(((PsiMethod) element).getContainingClass(), referenceElement, false);
			}
			return true;
		}
	}
	return false;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:19,代码来源:InlineToAnonymousClassHandler.java


示例12: performWithFields

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
private void performWithFields() throws Exception {
  configureByFile(TEST_ROOT + getTestName(false) + ".java");
  PsiElement element = TargetElementUtil.findTargetElement(myEditor, ContainerUtil.newHashSet(TargetElementUtilEx.ELEMENT_NAME_ACCEPTED));
  assertTrue(element instanceof PsiClass);
  PsiClass aClass = (PsiClass)element;
  final ArrayList<VariableData> parametersForFields = new ArrayList<VariableData>();
  final boolean addClassParameter = MakeStaticUtil.buildVariableData(aClass, parametersForFields);

  new MakeClassStaticProcessor(
          getProject(),
          aClass,
          new Settings(true, addClassParameter ? "anObject" : null,
                       parametersForFields.toArray(
                         new VariableData[parametersForFields.size()]))).run();
  checkResultByFile(TEST_ROOT + getTestName(false) + "_after.java");
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:17,代码来源:MakeClassStaticTest.java


示例13: doTest

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
private void doTest(@PsiModifier.ModifierConstant @Nullable String newVisibility,
		@Nullable String newName,
		@Nullable String newReturnType,
		GenParams genParams,
		GenExceptions genExceptions,
		final boolean generateDelegate) throws Exception
{
	String basePath = "/refactoring/changeSignature/" + getTestName(false);
	@NonNls final String filePath = basePath + ".java";
	configureByFile(filePath);
	final PsiElement targetElement = TargetElementUtil.findTargetElement(getEditor(), ContainerUtil.newHashSet(TargetElementUtilEx.ELEMENT_NAME_ACCEPTED));
	assertTrue("<caret> is not on method name", targetElement instanceof PsiMethod);
	PsiMethod method = (PsiMethod) targetElement;
	final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
	PsiType newType = newReturnType != null ? factory.createTypeFromText(newReturnType, method) : method.getReturnType();
	new ChangeSignatureProcessor(getProject(), method, generateDelegate, newVisibility, newName != null ? newName : method.getName(), newType, genParams.genParams(method), genExceptions
			.genExceptions(method)).run();
	@NonNls String after = basePath + "_after.java";
	checkResultByFile(after);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:21,代码来源:ChangeSignatureTest.java


示例14: testPropagateParameter

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
public void testPropagateParameter() throws Exception
{
	String basePath = "/refactoring/changeSignature/" + getTestName(false);
	@NonNls final String filePath = basePath + ".java";
	configureByFile(filePath);
	final PsiElement targetElement = TargetElementUtil.findTargetElement(getEditor(), ContainerUtil.newHashSet(TargetElementUtilEx.ELEMENT_NAME_ACCEPTED));
	assertTrue("<caret> is not on method name", targetElement instanceof PsiMethod);
	PsiMethod method = (PsiMethod) targetElement;
	final PsiClass containingClass = method.getContainingClass();
	assertTrue(containingClass != null);
	final PsiMethod[] callers = containingClass.findMethodsByName("caller", false);
	assertTrue(callers.length > 0);
	final PsiMethod caller = callers[0];
	final HashSet<PsiMethod> propagateParametersMethods = new HashSet<PsiMethod>();
	propagateParametersMethods.add(caller);
	final PsiParameter[] parameters = method.getParameterList().getParameters();
	new ChangeSignatureProcessor(getProject(), method, false, null, method.getName(), CanonicalTypes.createTypeWrapper(PsiType.VOID), new ParameterInfoImpl[]{
			new ParameterInfoImpl(0, parameters[0].getName(), parameters[0].getType()),
			new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN, "true")
	}, null, propagateParametersMethods, null).run();
	@NonNls String after = basePath + "_after.java";
	checkResultByFile(after);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:24,代码来源:ChangeSignatureTest.java


示例15: doTest

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
protected void doTest(final boolean shouldSucceed) throws Exception {
  final String filePath = getTestFilePath();
  configureByFile(filePath);
  final PsiElement targetElement = TargetElementUtil.findTargetElement(getEditor(), ContainerUtil.newHashSet(TargetElementUtilEx.ELEMENT_NAME_ACCEPTED));
  assertTrue("<caret> is not on method name", targetElement instanceof PsiMember);
  final PsiMember psiMethod = (PsiMember)targetElement;

  try {
    MethodDuplicatesHandler.invokeOnScope(getProject(), psiMethod, new AnalysisScope(getFile()));
  }
  catch (RuntimeException e) {
    if (shouldSucceed) {
      fail("duplicates were not found");
    }
    return;
  }
  UIUtil.dispatchAllInvocationEvents();
  if (shouldSucceed) {
    checkResultByFile(filePath + ".after");
  }
  else {
    fail("duplicates found");
  }
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:25,代码来源:FindMethodDuplicatesBaseTest.java


示例16: doTest

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
private void doTest(final boolean createInnerClass) throws Exception {
  final String testName = getTestName(false);
  configureByFile("/refactoring/extractMethodObject/" + testName + ".java");
  PsiElement element = TargetElementUtil.findTargetElement(myEditor, ContainerUtil.newHashSet(TargetElementUtilEx.ELEMENT_NAME_ACCEPTED));
  assertTrue(element instanceof PsiMethod);
  final PsiMethod method = (PsiMethod) element;

  final ExtractMethodObjectProcessor processor =
    new ExtractMethodObjectProcessor(getProject(), getEditor(), method.getBody().getStatements(), "InnerClass");
  final ExtractMethodObjectProcessor.MyExtractMethodProcessor extractProcessor = processor.getExtractProcessor();
  processor.setCreateInnerClass(createInnerClass);
  extractProcessor.setShowErrorDialogs(false);
  extractProcessor.prepare();
  extractProcessor.testPrepare();

  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    public void run() {
      ExtractMethodObjectHandler.run(getProject(), getEditor(), processor, extractProcessor);
    }
  });


  checkResultByFile("/refactoring/extractMethodObject/" + testName + ".java" + ".after");
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:25,代码来源:ExtractMethodObjectTest.java


示例17: testIdWithRefs

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
public void testIdWithRefs() throws Exception {
  configureByFiles(null, getTestName(true) + ".fxml");
  PsiElement element = TargetElementUtil
    .findTargetElement(myEditor, ContainerUtil.newHashSet(TargetElementUtilEx.ELEMENT_NAME_ACCEPTED, TargetElementUtilEx.REFERENCED_ELEMENT_ACCEPTED));
  assertNotNull(element);
  new RenameProcessor(getProject(), element, "lb1", true, true).run();
  checkResultByFile(getTestName(true) + "_after.fxml");
}
 
开发者ID:consulo,项目名称:consulo-javafx,代码行数:9,代码来源:JavaFXRenameTest.java


示例18: doTest

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
private void doTest(final String newName, boolean inline) throws Exception {
  configureByFiles(null, getTestName(true) + ".fxml", getTestName(false) + ".java");
  PsiElement element = TargetElementUtil
    .findTargetElement(myEditor, ContainerUtil.newHashSet(TargetElementUtilEx.ELEMENT_NAME_ACCEPTED, TargetElementUtilEx.REFERENCED_ELEMENT_ACCEPTED));
  assertNotNull(element);
  if (inline) {
    CodeInsightTestUtil.doInlineRename(new MemberInplaceRenameHandler(), newName, getEditor(), element);
  } else {
    new RenameProcessor(getProject(), element, newName, true, true).run();
  }
  checkResultByFile(getTestName(true) + "_after.fxml");
}
 
开发者ID:consulo,项目名称:consulo-javafx,代码行数:13,代码来源:JavaFXRenameTest.java


示例19: doTest

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
protected Collection<PsiElement> doTest(int expectedSize) {
  PsiFile file = myFixture.getFile();
  assertNotNull(file);
  PsiReference reference = file.findReferenceAt(myFixture.getCaretOffset());
  assertNotNull("no reference", reference);
  final Collection<PsiElement> elements = TargetElementUtil.getTargetCandidates(reference);
  assertNotNull(elements);
  assertEquals(expectedSize, elements.size());
  return elements;
}
 
开发者ID:consulo,项目名称:consulo-apache-thrift,代码行数:11,代码来源:ThriftResolveTest.java


示例20: getPsiElementsIn

import consulo.codeInsight.TargetElementUtil; //导入依赖的package包/类
@Nullable
private static PsiElement[] getPsiElementsIn(final Editor editor, final PsiFile psiFile) {
  try {
    final PsiReference reference = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset());
    if (reference == null) {
      return null;
    }
    final Collection<PsiElement> candidates = TargetElementUtil.getTargetCandidates(reference);
    return ContainerUtil.toArray(candidates, new PsiElement[candidates.size()]);
  }
  catch (IndexNotReadyException e) {
    return null;
  }
}
 
开发者ID:consulo,项目名称:consulo-apache-ant,代码行数:15,代码来源:AntRenameHandler.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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