Search in sources :

Example 11 with PsiJavaCodeReferenceElement

use of com.intellij.psi.PsiJavaCodeReferenceElement in project intellij-community by JetBrains.

the class InlineStaticImportHandler method inlineElement.

@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);
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) PsiImportStaticStatement(com.intellij.psi.PsiImportStaticStatement) PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement) RefactoringEventData(com.intellij.refactoring.listeners.RefactoringEventData) Result(com.intellij.openapi.application.Result)

Example 12 with PsiJavaCodeReferenceElement

use of com.intellij.psi.PsiJavaCodeReferenceElement in project intellij-community by JetBrains.

the class ReplaceFullyQualifiedNameWithImportIntention method processIntention.

@Override
public void processIntention(@NotNull PsiElement element) {
    PsiJavaCodeReferenceElement reference = (PsiJavaCodeReferenceElement) element;
    PsiElement target = reference.resolve();
    if (!(target instanceof PsiClass)) {
        PsiElement parent = reference.getParent();
        while (parent instanceof PsiJavaCodeReferenceElement) {
            reference = (PsiJavaCodeReferenceElement) parent;
            target = reference.resolve();
            if (target instanceof PsiClass) {
                break;
            }
            parent = parent.getParent();
        }
    }
    if (!(target instanceof PsiClass)) {
        return;
    }
    final PsiClass aClass = (PsiClass) target;
    final String qualifiedName = aClass.getQualifiedName();
    if (qualifiedName == null) {
        return;
    }
    final PsiJavaFile file = PsiTreeUtil.getParentOfType(reference, PsiJavaFile.class);
    if (file == null) {
        return;
    }
    ImportUtils.addImportIfNeeded(aClass, reference);
    final String fullyQualifiedText = reference.getText();
    final UnnecessaryFullyQualifiedNameInspection.QualificationRemover qualificationRemover = new UnnecessaryFullyQualifiedNameInspection.QualificationRemover(fullyQualifiedText);
    file.accept(qualificationRemover);
    final Collection<PsiElement> shortenedElements = qualificationRemover.getShortenedElements();
    final int elementCount = shortenedElements.size();
    final String text;
    if (elementCount == 1) {
        text = IntentionPowerPackBundle.message("1.fully.qualified.name.status.bar.escape.highlighting.message");
    } else {
        text = IntentionPowerPackBundle.message("multiple.fully.qualified.names.status.bar.escape.highlighting.message", Integer.valueOf(elementCount));
    }
    HighlightUtil.highlightElements(shortenedElements, text);
}
Also used : PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement) PsiClass(com.intellij.psi.PsiClass) PsiJavaFile(com.intellij.psi.PsiJavaFile) UnnecessaryFullyQualifiedNameInspection(com.siyeh.ig.style.UnnecessaryFullyQualifiedNameInspection) PsiElement(com.intellij.psi.PsiElement)

Example 13 with PsiJavaCodeReferenceElement

use of com.intellij.psi.PsiJavaCodeReferenceElement in project intellij-community by JetBrains.

the class AddMavenDependencyQuickFix method getReferenceText.

public String getReferenceText() {
    PsiJavaCodeReferenceElement result = myRef;
    while (true) {
        PsiElement parent = result.getParent();
        if (!(parent instanceof PsiJavaCodeReferenceElement)) {
            break;
        }
        result = (PsiJavaCodeReferenceElement) parent;
    }
    return result.getQualifiedName();
}
Also used : PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement) PsiElement(com.intellij.psi.PsiElement)

Example 14 with PsiJavaCodeReferenceElement

use of com.intellij.psi.PsiJavaCodeReferenceElement in project kotlin by JetBrains.

the class JavaAnnotationImpl method resolvePsi.

@Nullable
private PsiClass resolvePsi() {
    PsiJavaCodeReferenceElement referenceElement = getPsi().getNameReferenceElement();
    if (referenceElement == null)
        return null;
    PsiElement resolved = referenceElement.resolve();
    return resolved instanceof PsiClass ? (PsiClass) resolved : null;
}
Also used : PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiJavaCodeReferenceElement (com.intellij.psi.PsiJavaCodeReferenceElement)14 PsiClass (com.intellij.psi.PsiClass)7 PsiElement (com.intellij.psi.PsiElement)4 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)3 PsiAnnotationMemberValue (com.intellij.psi.PsiAnnotationMemberValue)3 LinkedList (java.util.LinkedList)3 Nullable (org.jetbrains.annotations.Nullable)3 Project (com.intellij.openapi.project.Project)2 PsiAnnotation (com.intellij.psi.PsiAnnotation)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 PsiClassType (com.intellij.psi.PsiClassType)1 PsiImportStaticStatement (com.intellij.psi.PsiImportStaticStatement)1 PsiJavaFile (com.intellij.psi.PsiJavaFile)1 PsiManagerEx (com.intellij.psi.impl.PsiManagerEx)1 PsiImportStatementStub (com.intellij.psi.impl.java.stubs.PsiImportStatementStub)1 LightClassReference (com.intellij.psi.impl.light.LightClassReference)1 PsiJavaCodeReferenceElementImpl (com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl)1