本文整理汇总了Java中consulo.codeInsight.TargetElementUtil.findTargetElement方法的典型用法代码示例。如果您正苦于以下问题:Java TargetElementUtil.findTargetElement方法的具体用法?Java TargetElementUtil.findTargetElement怎么用?Java TargetElementUtil.findTargetElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类consulo.codeInsight.TargetElementUtil
的用法示例。
在下文中一共展示了TargetElementUtil.findTargetElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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");
}
}
示例2: 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");
}
示例3: doTest
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
private void doTest(final int targetParameter, final String visibility) throws Exception {
final String filePath = "/refactoring/convertToInstanceMethod/" + getTestName(false) + ".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;
new ConvertToInstanceMethodProcessor(getProject(),
method, method.getParameterList().getParameters()[targetParameter],
visibility).run();
checkResultByFile(filePath + ".after");
}
示例4: perform
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
private static void perform(boolean addClassParameter) {
PsiElement element = TargetElementUtil.findTargetElement(myEditor, ContainerUtil.newHashSet(TargetElementUtilEx.ELEMENT_NAME_ACCEPTED));
assertTrue(element instanceof PsiMethod);
PsiMethod method = (PsiMethod) element;
new MakeMethodStaticProcessor(
getProject(),
method,
new Settings(true, addClassParameter ? "anObject" : null, null)).run();
}
示例5: findElementToShowUsagesOf
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
public static PsiNameIdentifierOwner findElementToShowUsagesOf(@Nonnull Editor editor, @Nonnull PsiFile file, int offset) {
PsiElement elementAt = TargetElementUtil.findTargetElement(editor, ContainerUtil.newHashSet(TargetElementUtilEx.ELEMENT_NAME_ACCEPTED), offset);
if (elementAt instanceof PsiNameIdentifierOwner) {
return (PsiNameIdentifierOwner)elementAt;
}
return null;
}
示例6: performInline
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
public static void performInline(Project project, Editor editor) {
PsiElement element = TargetElementUtil
.findTargetElement(editor, ContainerUtil.newHashSet(TargetElementUtilEx.ELEMENT_NAME_ACCEPTED, TargetElementUtilEx.REFERENCED_ELEMENT_ACCEPTED));
assertTrue(element instanceof PsiLocalVariable);
InlineLocalHandler.invoke(project, editor, (PsiLocalVariable)element, null);
}
示例7: getPsiElementIn
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
@Nullable
private static PsiElement getPsiElementIn(@Nonnull Editor editor, @Nonnull Caret caret, @Nonnull VirtualFile file) {
final PsiFile psiFile = getPsiFile(editor, file);
if (psiFile == null) return null;
try {
return TargetElementUtil.findTargetElement(editor, TargetElementUtil.getReferenceSearchFlags(), caret.getOffset());
}
catch (IndexNotReadyException e) {
return null;
}
}
示例8: doTest
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
private void doTest() throws Exception {
configureByFile(TEST_ROOT + getTestName(true) + ".java");
PsiElement element = TargetElementUtil.findTargetElement(myEditor, ContainerUtil.newHashSet(TargetElementUtilEx.ELEMENT_NAME_ACCEPTED));
assertTrue(element instanceof PsiNamedElement);
final PsiNamedElement namedElement = (PsiNamedElement)element;
final String name = namedElement.getName();
new InvertBooleanProcessor(namedElement, name + "Inverted").run();
checkResultByFile(TEST_ROOT + getTestName(true) + "_after.java");
}
示例9: performAction
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
private void performAction()
{
PsiElement element = TargetElementUtil.findTargetElement(myEditor, ContainerUtil.newHashSet(TargetElementUtilEx.ELEMENT_NAME_ACCEPTED, TargetElementUtilEx.REFERENCED_ELEMENT_ACCEPTED));
final PsiReference ref = myFile.findReferenceAt(myEditor.getCaretModel().getOffset());
PsiReferenceExpression refExpr = ref instanceof PsiReferenceExpression ? (PsiReferenceExpression) ref : null;
assertTrue(element instanceof PsiField);
PsiField field = (PsiField) element.getNavigationElement();
new InlineConstantFieldProcessor(field, getProject(), refExpr, element instanceof PsiCompiledElement).run();
}
示例10: doTestCanBeInvokedOnReference
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
private void doTestCanBeInvokedOnReference(boolean canBeInvokedOnReference) throws Exception
{
configureByFile("/refactoring/inlineToAnonymousClass/" + getTestName(false) + ".java");
PsiElement element = TargetElementUtil.findTargetElement(myEditor, ContainerUtil.newHashSet(TargetElementUtilEx.ELEMENT_NAME_ACCEPTED, TargetElementUtilEx.REFERENCED_ELEMENT_ACCEPTED));
PsiCall callToInline = InlineToAnonymousClassHandler.findCallToInline(myEditor);
PsiClass classToInline = (PsiClass) element;
assertEquals(null, InlineToAnonymousClassHandler.getCannotInlineMessage(classToInline));
final PsiClassType superType = InlineToAnonymousClassProcessor.getSuperType(classToInline);
assertTrue(superType != null);
assertEquals(canBeInvokedOnReference, InlineToAnonymousClassHandler.canBeInvokedOnReference(callToInline, superType));
}
示例11: doTestPreprocessUsages
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
private void doTestPreprocessUsages(final String expectedMessage) throws Exception
{
configureByFile("/refactoring/inlineToAnonymousClass/" + getTestName(false) + ".java");
PsiElement element = TargetElementUtil.findTargetElement(myEditor, ContainerUtil.newHashSet(TargetElementUtilEx.ELEMENT_NAME_ACCEPTED, TargetElementUtilEx.REFERENCED_ELEMENT_ACCEPTED));
assertInstanceOf(element, PsiClass.class);
final PsiClass psiClass = (PsiClass) element;
assertEquals(expectedMessage, InlineToAnonymousClassHandler.getCannotInlineMessage(psiClass));
}
示例12: doTestNoInline
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
private void doTestNoInline(final String expectedMessage) throws Exception
{
String name = getTestName(false);
@NonNls String fileName = "/refactoring/inlineToAnonymousClass/" + name + ".java";
configureByFile(fileName);
PsiElement element = TargetElementUtil.findTargetElement(myEditor, ContainerUtil.newHashSet(TargetElementUtilEx.ELEMENT_NAME_ACCEPTED, TargetElementUtilEx.REFERENCED_ELEMENT_ACCEPTED));
assertInstanceOf(element, PsiClass.class);
String message = InlineToAnonymousClassHandler.getCannotInlineMessage((PsiClass) element);
assertEquals(expectedMessage, message);
}
示例13: testAllUsagesInCode
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
public void testAllUsagesInCode() throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".java");
PsiElement element = TargetElementUtil
.findTargetElement(myEditor, ContainerUtil.newHashSet(TargetElementUtilEx.ELEMENT_NAME_ACCEPTED, TargetElementUtilEx.REFERENCED_ELEMENT_ACCEPTED));
assertNotNull(element);
final UsageInfo[] usageInfos = RenameUtil.findUsages(element, "newName", true, true, new HashMap<PsiElement, String>());
assertSize(1, usageInfos);
for (UsageInfo usageInfo : usageInfos) {
assertTrue(usageInfo instanceof MoveRenameUsageInfo);
assertFalse(usageInfo.isNonCodeUsage);
}
}
示例14: testRenameParamUniqueName
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
public void testRenameParamUniqueName() throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".java");
PsiElement element = TargetElementUtil
.findTargetElement(myEditor, ContainerUtil.newHashSet(TargetElementUtilEx.ELEMENT_NAME_ACCEPTED,TargetElementUtilEx.REFERENCED_ELEMENT_ACCEPTED));
assertNotNull(element);
final HashSet<String> result = new HashSet<String>();
new JavaNameSuggestionProvider().getSuggestedNames(element, getFile(), result);
assertTrue(result.toString(), result.contains("window"));
}
示例15: doTest
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
private void doTest(boolean isTargetParameter, final int targetIndex, final String newVisibility) throws Exception {
final String filePath = "/refactoring/moveInstanceMethod/" + getTestName(false) + ".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 PsiVariable targetVariable = isTargetParameter ? method.getParameterList().getParameters()[targetIndex] :
method.getContainingClass().getFields()[targetIndex];
new MoveInstanceMethodProcessor(getProject(),
method, targetVariable, newVisibility, MoveInstanceMethodHandler.suggestParameterNames (method, targetVariable)).run();
checkResultByFile(filePath + ".after");
}