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);
}
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);
}
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();
}
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;
}
Aggregations