use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class DefaultLookupItemRenderer method getName.
private static String getName(final LookupItem item) {
final String presentableText = item.getPresentableText();
if (presentableText != null)
return presentableText;
final Object o = item.getObject();
String name = null;
if (o instanceof PsiElement) {
final PsiElement element = (PsiElement) o;
if (element.isValid()) {
name = PsiUtilCore.getName(element);
}
} else if (o instanceof PsiMetaData) {
name = ((PsiMetaData) o).getName();
} else if (o instanceof PresentableLookupValue) {
name = ((PresentableLookupValue) o).getPresentation();
} else {
name = String.valueOf(o);
}
if (name == null) {
name = "";
}
return name;
}
use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class CachesBasedRefSearcher method processQuery.
@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters p, @NotNull Processor<PsiReference> consumer) {
final PsiElement refElement = p.getElementToSearch();
boolean caseSensitive = refElement.getLanguage().isCaseSensitive();
String text = null;
if (refElement instanceof PsiFileSystemItem && !(refElement instanceof SyntheticFileSystemItem)) {
final VirtualFile vFile = ((PsiFileSystemItem) refElement).getVirtualFile();
if (vFile != null) {
text = vFile.getNameWithoutExtension();
}
// We must not look for file references with the file language's case-sensitivity,
// since case-sensitivity of the references themselves depends either on file system
// or on the rules of the language of reference
caseSensitive = false;
} else if (refElement instanceof PsiNamedElement) {
text = ((PsiNamedElement) refElement).getName();
if (refElement instanceof PsiMetaOwner) {
final PsiMetaData metaData = ((PsiMetaOwner) refElement).getMetaData();
if (metaData != null)
text = metaData.getName();
}
}
if (text == null && refElement instanceof PsiMetaOwner) {
final PsiMetaData metaData = ((PsiMetaOwner) refElement).getMetaData();
if (metaData != null)
text = metaData.getName();
}
if (StringUtil.isNotEmpty(text)) {
final SearchScope searchScope = p.getEffectiveSearchScope();
p.getOptimizer().searchWord(text, searchScope, caseSensitive, refElement);
}
}
use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class RenameUtil method getStringToReplace.
private static String getStringToReplace(PsiElement element, String newName, boolean nonJava, final RenamePsiElementProcessor theProcessor) {
if (element instanceof PsiMetaOwner) {
final PsiMetaOwner psiMetaOwner = (PsiMetaOwner) element;
final PsiMetaData metaData = psiMetaOwner.getMetaData();
if (metaData != null) {
return metaData.getName();
}
}
if (theProcessor != null) {
String result = theProcessor.getQualifiedNameAfterRename(element, newName, nonJava);
if (result != null) {
return result;
}
}
if (element instanceof PsiNamedElement) {
return newName;
} else {
LOG.error("Unknown element type : " + element);
return null;
}
}
use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class RenameUtil method doRenameGenericNamedElement.
public static void doRenameGenericNamedElement(@NotNull PsiElement namedElement, String newName, UsageInfo[] usages, @Nullable RefactoringElementListener listener) throws IncorrectOperationException {
PsiWritableMetaData writableMetaData = null;
if (namedElement instanceof PsiMetaOwner) {
final PsiMetaData metaData = ((PsiMetaOwner) namedElement).getMetaData();
if (metaData instanceof PsiWritableMetaData) {
writableMetaData = (PsiWritableMetaData) metaData;
}
}
if (writableMetaData == null && !(namedElement instanceof PsiNamedElement)) {
LOG.error("Unknown element type:" + namedElement);
}
boolean hasBindables = false;
for (UsageInfo usage : usages) {
if (!(usage.getReference() instanceof BindablePsiReference)) {
rename(usage, newName);
} else {
hasBindables = true;
}
}
if (writableMetaData != null) {
writableMetaData.setName(newName);
} else {
PsiElement namedElementAfterRename = ((PsiNamedElement) namedElement).setName(newName);
if (namedElementAfterRename != null)
namedElement = namedElementAfterRename;
}
if (hasBindables) {
for (UsageInfo usage : usages) {
final PsiReference ref = usage.getReference();
if (ref instanceof BindablePsiReference) {
boolean fallback = true;
if (!(ref instanceof FragmentaryPsiReference && ((FragmentaryPsiReference) ref).isFragmentOnlyRename())) {
try {
ref.bindToElement(namedElement);
fallback = false;
} catch (IncorrectOperationException ignored) {
}
}
if (fallback) {
//fall back to old scheme
ref.handleElementRename(newName);
}
}
}
}
if (listener != null) {
listener.elementRenamed(namedElement);
}
}
use of com.intellij.psi.meta.PsiMetaData 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);
}
Aggregations