use of com.intellij.psi.meta.PsiMetaOwner 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.PsiMetaOwner 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.PsiMetaOwner 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.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 DomNameSuggestionProvider method getSuggestedNames.
@Override
public SuggestedNameInfo getSuggestedNames(final PsiElement element, final PsiElement nameSuggestionContext, final Set<String> result) {
if (element instanceof PsiMetaOwner) {
final PsiMetaData psiMetaData = ((PsiMetaOwner) element).getMetaData();
if (psiMetaData instanceof DomMetaData) {
final DomMetaData domMetaData = (DomMetaData) psiMetaData;
final GenericDomValue value = domMetaData.getNameElement(domMetaData.getElement());
ContainerUtil.addIfNotNull(result, getNameFromNameValue(value, true));
}
}
return null;
}
Aggregations