use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class AntDomProperty method getNavigationElement.
public PsiElement getNavigationElement(final String propertyName) {
DomTarget domTarget = DomTarget.getTarget(this);
if (domTarget == null) {
final GenericAttributeValue<String> environment = getEnvironment();
if (environment.getRawText() != null) {
domTarget = DomTarget.getTarget(this, environment);
}
if (domTarget == null) {
final GenericAttributeValue<String> resource = getResource();
if (resource.getRawText() != null) {
domTarget = DomTarget.getTarget(this, resource);
}
}
}
if (domTarget != null) {
final PsiElement psi = PomService.convertToPsi(domTarget);
if (psi != null) {
return psi;
}
}
final PsiFileSystemItem psiFile = getFile().getValue();
if (psiFile != null) {
final String prefix = getPropertyPrefixValue();
String _propertyName = propertyName;
if (prefix != null) {
if (!propertyName.startsWith(prefix)) {
return null;
}
_propertyName = propertyName.substring(prefix.length());
}
final PropertiesFile pf = toPropertiesFile(psiFile);
if (pf != null) {
final IProperty property = pf.findPropertyByKey(_propertyName);
return property != null ? property.getPsiElement() : null;
}
}
return null;
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class FilePathCompletionContributor method fileMatchesPathPrefix.
private static boolean fileMatchesPathPrefix(@Nullable final PsiFileSystemItem file, @NotNull final List<String> pathPrefix) {
if (file == null)
return false;
final List<String> contextParts = new ArrayList<>();
PsiFileSystemItem parentFile = file;
PsiFileSystemItem parent;
while ((parent = parentFile.getParent()) != null) {
if (parent.getName().length() > 0)
contextParts.add(0, parent.getName().toLowerCase());
parentFile = parent;
}
final String path = StringUtil.join(contextParts, "/");
int nextIndex = 0;
for (@NonNls final String s : pathPrefix) {
if ((nextIndex = path.indexOf(s.toLowerCase(), nextIndex)) == -1)
return false;
}
return true;
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class PsiFileSystemItemUtil method getRelativePath.
@Nullable
public static String getRelativePath(PsiFileSystemItem src, PsiFileSystemItem dst) {
final PsiFileSystemItem commonAncestor = getCommonAncestor(src, dst);
if (commonAncestor != null) {
StringBuilder buffer = new StringBuilder();
if (!src.equals(commonAncestor)) {
while (!commonAncestor.equals(src.getParent())) {
buffer.append("..").append('/');
src = src.getParent();
assert src != null;
}
}
buffer.append(getRelativePathFromAncestor(dst, commonAncestor));
return buffer.toString();
}
return null;
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class PsiFileSystemItemUtil method getRelativePathFromAncestor.
@Nullable
public static String getRelativePathFromAncestor(PsiFileSystemItem file, PsiFileSystemItem ancestor) {
int length = 0;
PsiFileSystemItem parent = file;
while (true) {
if (parent == null)
return null;
if (parent.equals(ancestor))
break;
if (length > 0) {
length++;
}
String name = parent.getName();
if (name == null) {
throw new AssertionError("Null name for " + parent + " of " + parent.getClass());
}
length += name.length();
parent = parent.getParent();
}
char[] chars = new char[length];
int index = chars.length;
parent = file;
while (true) {
if (parent.equals(ancestor))
break;
if (index < length) {
chars[--index] = '/';
}
String name = parent.getName();
for (int i = name.length() - 1; i >= 0; i--) {
chars[--index] = name.charAt(i);
}
parent = parent.getParent();
}
return StringFactory.createShared(chars);
}
use of com.intellij.psi.PsiFileSystemItem 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);
}
}
Aggregations