@Override public void inlineElement(Project project, Editor editor, PsiElement element) { final PsiImportStaticStatement staticStatement = PsiTreeUtil.getParentOfType(element, PsiImportStaticStatement.class); final List<PsiJavaCodeReferenceElement> referenceElements = collectReferencesThrough(element.getContainingFile(), null, staticStatement); RefactoringEventData data = new RefactoringEventData(); data.addElement(element); project.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringStarted(REFACTORING_ID, data); new WriteCommandAction(project, REFACTORING_NAME){ @Override protected void run(@NotNull Result result) throws Throwable { replaceAllAndDeleteImport(referenceElements, null, staticStatement); } }.execute(); project.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringDone(REFACTORING_ID, null); }
static HighlightInfo checkStaticOnDemandImportResolvesToClass(PsiImportStaticStatement statement) { if(statement.isOnDemand() && statement.resolveTargetClass() == null) { PsiJavaCodeReferenceElement ref = statement.getImportReference(); if(ref != null) { PsiElement resolve = ref.resolve(); if(resolve != null) { return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(ObjectUtils.notNull(ref.getReferenceNameElement(), ref)).descriptionAndTooltip("Class " + ref .getCanonicalText() + " not found").create(); } } } return null; }
@NotNull @Override protected InspectionGadgetsFix[] buildFixes(Object... infos) { final List<InspectionGadgetsFix> result = new SmartList<>(); final PsiImportStaticStatement importStaticStatement = (PsiImportStaticStatement) infos[0]; final SuppressForTestsScopeFix fix = SuppressForTestsScopeFix.build(this, importStaticStatement); ContainerUtil.addIfNotNull(result, fix); final PsiClass aClass = importStaticStatement.resolveTargetClass(); if(aClass != null) { final String name = aClass.getQualifiedName(); result.add(new IgnoreClassFix(name, allowedClasses, "Allow static imports for class '" + name + "'")); } result.add(buildFix(infos)); return result.toArray(InspectionGadgetsFix.EMPTY_ARRAY); }
@Override public void inlineElement(Project project, Editor editor, PsiElement element) { final PsiImportStaticStatement staticStatement = PsiTreeUtil.getParentOfType(element, PsiImportStaticStatement.class); final List<PsiJavaCodeReferenceElement> referenceElements = collectReferencesThrough(element.getContainingFile(), null, staticStatement); new WriteCommandAction(project, REFACTORING_NAME){ @Override protected void run(Result result) throws Throwable { replaceAllAndDeleteImport(referenceElements, null, staticStatement); } }.execute(); }
@Override public void visitImportStaticStatement(PsiImportStaticStatement statement) { mVisitor.report("PsiImportStaticStatement", statement.getText(), statement); super.visitElement(statement); }
@Override public boolean canInlineElement(PsiElement element) { if (element.getContainingFile() == null) return false; return PsiTreeUtil.getParentOfType(element, PsiImportStaticStatement.class) != null; }
public ReplaceStaticImportUsageInfo(final PsiImportStaticStatement staticImportStatement, final PsiClass[] targetClass) { super(staticImportStatement); myStaticImportStatement = staticImportStatement; myTargetClasses = targetClass; }