use of com.intellij.psi.meta.PsiMetaOwner in project intellij-community by JetBrains.
the class PsiElement2UsageTargetAdapter method update.
private void update(PsiElement element) {
if (element != null && element.isValid()) {
final ItemPresentation presentation = ((NavigationItem) element).getPresentation();
myIconOpen = presentation == null ? null : ComputableIcon.create(presentation, true);
myIconClosed = presentation == null ? null : ComputableIcon.create(presentation, false);
myPresentableText = presentation == null ? UsageViewUtil.createNodeText(element) : presentation.getPresentableText();
if (myIconOpen == null || myIconClosed == null) {
if (element instanceof PsiMetaOwner) {
final PsiMetaOwner psiMetaOwner = (PsiMetaOwner) element;
final PsiMetaData metaData = psiMetaOwner.getMetaData();
if (metaData instanceof PsiPresentableMetaData) {
final PsiPresentableMetaData psiPresentableMetaData = (PsiPresentableMetaData) metaData;
if (myIconOpen == null)
myIconOpen = ComputableIcon.create(psiPresentableMetaData);
if (myIconClosed == null)
myIconClosed = ComputableIcon.create(psiPresentableMetaData);
}
} else if (element instanceof PsiFile) {
final PsiFile psiFile = (PsiFile) element;
final VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile != null) {
myIconOpen = ComputableIcon.create(virtualFile);
myIconClosed = ComputableIcon.create(virtualFile);
}
}
}
}
}
use of com.intellij.psi.meta.PsiMetaOwner in project intellij-community by JetBrains.
the class PsiElementRenameHandler method renameabilityStatus.
@Nullable
static String renameabilityStatus(Project project, PsiElement element) {
if (element == null)
return "";
boolean hasRenameProcessor = RenamePsiElementProcessor.forElement(element) != RenamePsiElementProcessor.DEFAULT;
boolean hasWritableMetaData = element instanceof PsiMetaOwner && ((PsiMetaOwner) element).getMetaData() instanceof PsiWritableMetaData;
if (!hasRenameProcessor && !hasWritableMetaData && !(element instanceof PsiNamedElement)) {
return RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.symbol.to.rename"));
}
if (!PsiManager.getInstance(project).isInProject(element)) {
if (element.isPhysical()) {
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
if (!(virtualFile != null && NonProjectFileWritingAccessProvider.isWriteAccessAllowed(virtualFile, project))) {
String message = RefactoringBundle.message("error.out.of.project.element", UsageViewUtil.getType(element));
return RefactoringBundle.getCannotRefactorMessage(message);
}
}
if (!element.isWritable()) {
return RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.cannot.be.renamed"));
}
}
if (InjectedLanguageUtil.isInInjectedLanguagePrefixSuffix(element)) {
final String message = RefactoringBundle.message("error.in.injected.lang.prefix.suffix", UsageViewUtil.getType(element));
return RefactoringBundle.getCannotRefactorMessage(message);
}
return null;
}
use of com.intellij.psi.meta.PsiMetaOwner in project intellij-community by JetBrains.
the class JavaFindUsagesHelper method getElementNames.
@NotNull
public static Set<String> getElementNames(@NotNull final PsiElement element) {
if (element instanceof PsiDirectory) {
// normalize a directory to a corresponding package
PsiPackage aPackage = ReadAction.compute(() -> JavaDirectoryService.getInstance().getPackage((PsiDirectory) element));
return aPackage == null ? Collections.emptySet() : getElementNames(aPackage);
}
final Set<String> result = new HashSet<>();
ApplicationManager.getApplication().runReadAction(() -> {
if (element instanceof PsiPackage) {
ContainerUtil.addIfNotNull(result, ((PsiPackage) element).getQualifiedName());
} else if (element instanceof PsiClass) {
final String qname = ((PsiClass) element).getQualifiedName();
if (qname != null) {
result.add(qname);
PsiClass topLevelClass = PsiUtil.getTopLevelClass(element);
if (topLevelClass != null && !(topLevelClass instanceof PsiSyntheticClass)) {
String topName = topLevelClass.getQualifiedName();
assert topName != null : "topLevelClass : " + topLevelClass + "; element: " + element + " (" + qname + ") top level file: " + InjectedLanguageManager.getInstance(element.getProject()).getTopLevelFile(element);
if (qname.length() > topName.length()) {
result.add(topName + qname.substring(topName.length()).replace('.', '$'));
}
}
}
} else if (element instanceof PsiMethod) {
ContainerUtil.addIfNotNull(result, ((PsiMethod) element).getName());
} else if (element instanceof PsiVariable) {
ContainerUtil.addIfNotNull(result, ((PsiVariable) element).getName());
} else if (element instanceof PsiMetaOwner) {
final PsiMetaData metaData = ((PsiMetaOwner) element).getMetaData();
if (metaData != null) {
ContainerUtil.addIfNotNull(result, metaData.getName());
}
} else if (element instanceof PsiNamedElement) {
ContainerUtil.addIfNotNull(result, ((PsiNamedElement) element).getName());
} else if (element instanceof XmlAttributeValue) {
ContainerUtil.addIfNotNull(result, ((XmlAttributeValue) element).getValue());
} else {
LOG.error("Unknown element type: " + element);
}
});
return result;
}
use of com.intellij.psi.meta.PsiMetaOwner in project intellij-community by JetBrains.
the class DescriptiveNameUtil method getDescriptiveName.
@NotNull
public static String getDescriptiveName(@NotNull PsiElement psiElement) {
LOG.assertTrue(psiElement.isValid());
if (psiElement instanceof PsiMetaOwner) {
final PsiMetaOwner psiMetaOwner = (PsiMetaOwner) psiElement;
final PsiMetaData metaData = psiMetaOwner.getMetaData();
if (metaData != null)
return getMetaDataName(metaData);
}
if (psiElement instanceof PsiFile) {
return ((PsiFile) psiElement).getName();
}
final Language lang = psiElement.getLanguage();
final FindUsagesProvider provider = LanguageFindUsages.INSTANCE.forLanguage(lang);
assert provider != null : lang;
return provider.getDescriptiveName(psiElement);
}
use of com.intellij.psi.meta.PsiMetaOwner in project intellij-community by JetBrains.
the class AbstractQualifiedReference method bindToElement.
@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
CheckUtil.checkWritable(this);
if (isReferenceTo(element))
return this;
if (element instanceof PsiMethod) {
final PsiMethod method = (PsiMethod) element;
final String methodName = method.getName();
if (isDirectlyVisible(method))
return replaceReference(methodName);
final AbstractQualifiedReference result = replaceReference(method.getContainingClass().getQualifiedName() + "." + methodName);
final AbstractQualifiedReference qualifier = result.getQualifier();
assert qualifier != null;
qualifier.shortenReferences();
return result;
}
if (element instanceof PsiClass) {
return replaceReference(((PsiClass) element).getQualifiedName()).shortenReferences();
}
if (element instanceof PsiPackage) {
return replaceReference(((PsiPackage) element).getQualifiedName());
}
if (element instanceof PsiMetaOwner) {
final PsiMetaData metaData = ((PsiMetaOwner) element).getMetaData();
if (metaData != null) {
final String name = metaData.getName(this);
if (name != null) {
return replaceReference(name);
}
}
}
return this;
}
Aggregations