本文整理汇总了Java中com.intellij.usageView.UsageInfo.getElement方法的典型用法代码示例。如果您正苦于以下问题:Java UsageInfo.getElement方法的具体用法?Java UsageInfo.getElement怎么用?Java UsageInfo.getElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.usageView.UsageInfo
的用法示例。
在下文中一共展示了UsageInfo.getElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import com.intellij.usageView.UsageInfo; //导入方法依赖的package包/类
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
final PsiElement element = PyUtil.findNonWhitespaceAtOffset(file, editor.getCaretModel().getOffset());
PyFunction problemFunction = PsiTreeUtil.getParentOfType(element, PyFunction.class);
if (problemFunction == null) return;
final PyClass containingClass = problemFunction.getContainingClass();
if (containingClass == null) return;
final List<UsageInfo> usages = PyRefactoringUtil.findUsages(problemFunction, false);
final PyDecoratorList decoratorList = problemFunction.getDecoratorList();
if (decoratorList != null) {
final PyDecorator decorator = decoratorList.findDecorator(PyNames.STATICMETHOD);
if (decorator != null) decorator.delete();
}
final PsiElement copy = problemFunction.copy();
problemFunction.delete();
file.addAfter(copy, containingClass);
for (UsageInfo usage : usages) {
final PsiElement usageElement = usage.getElement();
if (usageElement instanceof PyReferenceExpression) {
PyUtil.removeQualifier((PyReferenceExpression)usageElement);
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:PyConvertStaticMethodToFunctionIntention.java
示例2: performRefactoring
import com.intellij.usageView.UsageInfo; //导入方法依赖的package包/类
@Override
protected void performRefactoring(@NotNull UsageInfo[] usages) {
moveMembersToBase();
moveFieldInitializations();
for (UsageInfo usage : usages) {
PsiElement element = usage.getElement();
if (element == null) continue;
PullUpHelper<MemberInfo> processor = getProcessor(element);
processor.updateUsage(element);
}
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
processMethodsDuplicates();
}
}, ModalityState.NON_MODAL, myProject.getDisposed());
}
示例3: filterUsages
import com.intellij.usageView.UsageInfo; //导入方法依赖的package包/类
protected List<UsageInfo> filterUsages(List<UsageInfo> infos) {
Map<PsiElement, MoveRenameUsageInfo> moveRenameInfos = new HashMap<PsiElement, MoveRenameUsageInfo>();
Set<PsiElement> usedElements = new HashSet<PsiElement>();
List<UsageInfo> result = new ArrayList<UsageInfo>(infos.size() / 2);
for (UsageInfo info : infos) {
LOG.assertTrue(info != null, getClass());
PsiElement element = info.getElement();
if (info instanceof MoveRenameUsageInfo) {
if (usedElements.contains(element)) continue;
moveRenameInfos.put(element, (MoveRenameUsageInfo)info);
}
else {
moveRenameInfos.remove(element);
usedElements.add(element);
if (!(info instanceof PossiblyIncorrectUsage) || ((PossiblyIncorrectUsage)info).isCorrect()) {
result.add(info);
}
}
}
result.addAll(moveRenameInfos.values());
return result;
}
示例4: processChangeMethodSignature
import com.intellij.usageView.UsageInfo; //导入方法依赖的package包/类
@Override
public boolean processChangeMethodSignature(IntroduceParameterData data, UsageInfo usage, UsageInfo[] usages) throws IncorrectOperationException {
if (!(usage.getElement() instanceof GrMethod) || !isGroovyUsage(usage)) return true;
GrMethod method = (GrMethod)usage.getElement();
final FieldConflictsResolver fieldConflictsResolver = new FieldConflictsResolver(data.getParameterName(), method.getBlock());
final MethodJavaDocHelper javaDocHelper = new MethodJavaDocHelper(method);
final PsiParameter[] parameters = method.getParameterList().getParameters();
data.getParametersToRemove().forEachDescending(new TIntProcedure() {
@Override
public boolean execute(final int paramNum) {
try {
PsiParameter param = parameters[paramNum];
PsiDocTag tag = javaDocHelper.getTagForParameter(param);
if (tag != null) {
tag.delete();
}
param.delete();
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
return true;
}
});
addParameter(method, javaDocHelper, data.getForcedType(), data.getParameterName(), data.isDeclareFinal(), data.getProject());
fieldConflictsResolver.fix();
return false;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:GroovyIntroduceParameterMethodUsagesProcessor.java
示例5: detectConflicts
import com.intellij.usageView.UsageInfo; //导入方法依赖的package包/类
private static MultiMap<PsiElement, String> detectConflicts(UsageInfo[] usages) {
final List<PsiElement> nonXmlUsages = new ArrayList<PsiElement>();
final List<PsiElement> unsupportedUsages = new ArrayList<PsiElement>();
final List<PsiElement> unambiguousUsages = new ArrayList<PsiElement>();
for (UsageInfo usage : usages) {
final PsiElement element = usage.getElement();
if (element == null) continue;
if (element.getLanguage() != XMLLanguage.INSTANCE) {
nonXmlUsages.add(element);
continue;
}
final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
final LayoutUsageData usageData = tag != null
? AndroidInlineUtil.getLayoutUsageData(tag)
: null;
if (usageData == null) {
unsupportedUsages.add(element);
continue;
}
if (usageData.getReference().computeTargetElements().length > 1) {
unambiguousUsages.add(element);
}
}
return AndroidInlineUtil.buildConflicts(nonXmlUsages, unambiguousUsages, unsupportedUsages,
Collections.<PsiElement>emptyList());
}
示例6: doClassMigration
import com.intellij.usageView.UsageInfo; //导入方法依赖的package包/类
public static void doClassMigration(Project project, PsiMigration migration, String newQName, UsageInfo[] usages) {
try {
PsiClass aClass = findOrCreateClass(project, migration, newQName);
// rename all references
for (UsageInfo usage : usages) {
if (usage instanceof MigrationProcessor.MigrationUsageInfo) {
final MigrationProcessor.MigrationUsageInfo usageInfo = (MigrationProcessor.MigrationUsageInfo)usage;
if (Comparing.equal(newQName, usageInfo.mapEntry.getNewName())) {
PsiElement element = usage.getElement();
if (element == null || !element.isValid()) continue;
if (element instanceof PsiJavaCodeReferenceElement) {
final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)element;
referenceElement.bindToElement(aClass);
}
else {
bindNonJavaReference(aClass, element, usage);
}
}
}
}
}
catch (IncorrectOperationException e) {
// should not happen!
LOG.error(e);
}
}
示例7: findCollisions
import com.intellij.usageView.UsageInfo; //导入方法依赖的package包/类
@Override
public void findCollisions(PsiElement element,
String newName,
Map<? extends PsiElement, String> allRenames,
List<UsageInfo> result) {
List<UsageInfo> collisions = new ArrayList<UsageInfo>();
for (UsageInfo info : result) {
if (!(info instanceof MoveRenameUsageInfo)) continue;
final PsiElement infoElement = info.getElement();
final PsiElement referencedElement = ((MoveRenameUsageInfo)info).getReferencedElement();
if (!(infoElement instanceof GrReferenceExpression)) continue;
final GrReferenceExpression refExpr = (GrReferenceExpression)infoElement;
if (!(referencedElement instanceof GrField || refExpr.advancedResolve().isInvokedOnProperty())) continue;
if (!(refExpr.getParent() instanceof GrCall)) continue;
final PsiType[] argTypes = PsiUtil.getArgumentTypes(refExpr, false);
final PsiType[] typeArguments = refExpr.getTypeArguments();
final MethodResolverProcessor processor =
new MethodResolverProcessor(newName, refExpr, false, null, argTypes, typeArguments);
final PsiMethod resolved = ResolveUtil.resolveExistingElement(refExpr, processor, PsiMethod.class);
if (resolved == null) continue;
collisions.add(new UnresolvableCollisionUsageInfo(resolved, refExpr) {
@Override
public String getDescription() {
return GroovyRefactoringBundle.message("usage.will.be.overriden.by.method", refExpr.getParent().getText(), PsiFormatUtil
.formatMethod(resolved, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME, PsiFormatUtilBase.SHOW_TYPE));
}
});
}
result.addAll(collisions);
super.findCollisions(element, newName, allRenames, result);
}
示例8: preprocessUsages
import com.intellij.usageView.UsageInfo; //导入方法依赖的package包/类
@Override
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
UsageInfo[] usagesIn = refUsages.get();
MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
if (!mySettings.generateDelegate()) {
detectAccessibilityConflicts(usagesIn, conflicts);
}
final GrExpression expression = mySettings.getExpression();
if (expression != null && toSearchFor instanceof PsiMember) {
final AnySupers anySupers = new AnySupers();
expression.accept(anySupers);
if (anySupers.containsSupers()) {
final PsiElement containingClass = PsiUtil.getFileOrClassContext(toReplaceIn);
for (UsageInfo usageInfo : usagesIn) {
if (!(usageInfo.getElement() instanceof PsiMethod) && !(usageInfo instanceof InternalUsageInfo)) {
if (!PsiTreeUtil.isAncestor(containingClass, usageInfo.getElement(), false)) {
conflicts.putValue(expression, RefactoringBundle
.message("parameter.initializer.contains.0.but.not.all.calls.to.method.are.in.its.class", CommonRefactoringUtil.htmlEmphasize(PsiKeyword.SUPER)));
break;
}
}
}
}
}
//todo
//for (IntroduceParameterMethodUsagesProcessor processor : IntroduceParameterMethodUsagesProcessor.EP_NAME.getExtensions()) {
//processor.findConflicts(this, refUsages.get(), conflicts);
//}
return showConflicts(conflicts, usagesIn);
}
示例9: AutomaticVariableRenamer
import com.intellij.usageView.UsageInfo; //导入方法依赖的package包/类
public AutomaticVariableRenamer(PsiClass aClass, String newClassName, Collection<UsageInfo> usages) {
final String oldClassName = aClass.getName();
for (final UsageInfo info : usages) {
final PsiElement element = info.getElement();
if (!(element instanceof PsiJavaCodeReferenceElement)) continue;
final PsiDeclarationStatement statement = PsiTreeUtil.getParentOfType(element, PsiDeclarationStatement.class);
if (statement != null) {
for(PsiElement declaredElement: statement.getDeclaredElements()) {
if (declaredElement instanceof PsiVariable) {
checkRenameVariable(element, (PsiVariable) declaredElement, oldClassName);
}
}
}
else {
PsiVariable variable = PsiTreeUtil.getParentOfType(element, PsiVariable.class);
if (variable != null) {
checkRenameVariable(element, variable, oldClassName);
if (variable instanceof PsiField) {
for(PsiField field: getFieldsInSameDeclaration((PsiField) variable)) {
checkRenameVariable(element, field, oldClassName);
}
}
}
}
}
suggestAllNames(oldClassName, newClassName);
}
示例10: getParentFromUsage
import com.intellij.usageView.UsageInfo; //导入方法依赖的package包/类
private static PsiElement getParentFromUsage(UsageInfo usage) {
ProperTextRange range = usage.getRangeInElement();
assertNotNull(range);
PsiElement element = usage.getElement();
assertNotNull(element);
PsiElement elementAt = element.findElementAt(range.getStartOffset());
assertNotNull(elementAt);
return elementAt.getParent();
}
示例11: preprocessUsages
import com.intellij.usageView.UsageInfo; //导入方法依赖的package包/类
@Override
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
UsageInfo[] usagesIn = refUsages.get();
MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
if (!mySettings.generateDelegate()) {
GroovyIntroduceParameterUtil.detectAccessibilityConflicts(mySettings.getExpression(), usagesIn, conflicts,
mySettings.replaceFieldsWithGetters() != IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE,
myProject
);
}
final GrMethod toReplaceIn = (GrMethod)mySettings.getToReplaceIn();
if (mySettings.getExpression() != null && !toReplaceIn.hasModifierProperty(PsiModifier.PRIVATE)) {
final AnySupers anySupers = new AnySupers();
mySettings.getExpression().accept(anySupers);
if (anySupers.containsSupers()) {
for (UsageInfo usageInfo : usagesIn) {
if (!(usageInfo.getElement() instanceof PsiMethod) && !(usageInfo instanceof InternalUsageInfo)) {
if (!PsiTreeUtil.isAncestor(toReplaceIn.getContainingClass(), usageInfo.getElement(), false)) {
conflicts.putValue(mySettings.getExpression(),
RefactoringBundle.message("parameter.initializer.contains.0.but.not.all.calls.to.method.are.in.its.class",
CommonRefactoringUtil.htmlEmphasize(PsiKeyword.SUPER)));
break;
}
}
}
}
}
for (IntroduceParameterMethodUsagesProcessor processor : IntroduceParameterMethodUsagesProcessor.EP_NAME.getExtensions()) {
processor.findConflicts(this, refUsages.get(), conflicts);
}
return showConflicts(conflicts, usagesIn);
}
示例12: postProcessUsages
import com.intellij.usageView.UsageInfo; //导入方法依赖的package包/类
@Override
public void postProcessUsages(UsageInfo[] usages, Function<PsiDirectory, PsiDirectory> newDirMapper) {
for (UsageInfo usage : usages) {
if (usage instanceof RemoveOnDemandImportStatementsUsageInfo) {
final PsiElement element = usage.getElement();
if (element != null) {
element.delete();
}
}
}
}
示例13: detectAccessibilityConflicts
import com.intellij.usageView.UsageInfo; //导入方法依赖的package包/类
public static void detectAccessibilityConflicts(@Nullable GroovyPsiElement elementToProcess,
final UsageInfo[] usages,
MultiMap<PsiElement, String> conflicts,
boolean replaceFieldsWithGetters,
Project project) {
if (elementToProcess == null) return;
final ReferencedElementsCollector collector = new ReferencedElementsCollector();
elementToProcess.accept(collector);
final List<PsiElement> result = collector.getResult();
if (result.isEmpty()) return;
for (final UsageInfo usageInfo : usages) {
if (!(usageInfo instanceof ExternalUsageInfo) || !IntroduceParameterUtil.isMethodUsage(usageInfo)) continue;
final PsiElement place = usageInfo.getElement();
for (PsiElement element : result) {
if (element instanceof PsiField && replaceFieldsWithGetters) {
//check getter access instead
final PsiClass psiClass = ((PsiField)element).getContainingClass();
LOG.assertTrue(psiClass != null);
final PsiMethod method = GroovyPropertyUtils.findGetterForField((PsiField)element);
if (method != null) {
element = method;
}
}
if (element instanceof PsiMember &&
!JavaPsiFacade.getInstance(project).getResolveHelper().isAccessible((PsiMember)element, place, null)) {
String message = RefactoringBundle.message(
"0.is.not.accessible.from.1.value.for.introduced.parameter.in.that.method.call.will.be.incorrect",
RefactoringUIUtil.getDescription(element, true),
RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(place), true));
conflicts.putValue(element, message);
}
}
}
}
示例14: prepareWritable
import com.intellij.usageView.UsageInfo; //导入方法依赖的package包/类
private boolean prepareWritable(final UsageInfo[] usages) {
Set<PsiElement> elementsToMakeWritable = new HashSet<PsiElement>();
Collections.addAll(elementsToMakeWritable, myClassesToMove);
elementsToMakeWritable.add(myTargetClass);
for(UsageInfo usage: usages) {
PsiElement element = usage.getElement();
if (element != null) {
elementsToMakeWritable.add(element);
}
}
if (!CommonRefactoringUtil.checkReadOnlyStatus(myProject, PsiUtilCore.toPsiElementArray(elementsToMakeWritable))) {
return false;
}
return true;
}
示例15: inlineReference
import com.intellij.usageView.UsageInfo; //导入方法依赖的package包/类
public static void inlineReference(final UsageInfo usage,
final PsiElement element,
final Map<Language, InlineHandler.Inliner> inliners) {
PsiElement usageElement = usage.getElement();
if (usageElement == null) return;
final Language language = usageElement.getLanguage();
final InlineHandler.Inliner inliner = inliners.get(language);
if (inliner != null) {
inliner.inlineUsage(usage, element);
}
}