当前位置: 首页>>代码示例>>Java>>正文


Java TargetElementUtil类代码示例

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


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


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