use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class GroovyPositionManager method findReferenceTypeSourceImage.
@Nullable
private static GroovyPsiElement findReferenceTypeSourceImage(SourcePosition position) {
PsiFile file = position.getFile();
if (!(file instanceof GroovyFileBase))
return null;
PsiElement element = file.findElementAt(position.getOffset());
if (element == null)
return null;
return PsiTreeUtil.getParentOfType(element, GrClosableBlock.class, GrTypeDefinition.class);
}
use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class GroovyScriptClassSearcher method findClass.
@Nullable
@Override
public PsiClass findClass(@NotNull PsiElement place) {
if (place.getLanguage() == GroovyLanguage.INSTANCE) {
PsiClass containingClass = PsiTreeUtil.getParentOfType(place, PsiClass.class, false);
while (containingClass instanceof PsiTypeParameter) {
containingClass = PsiTreeUtil.getParentOfType(containingClass, PsiClass.class);
}
if (containingClass != null)
return containingClass;
PsiFile file = place.getContainingFile();
if (file instanceof GroovyFile && ((GroovyFile) file).isScript()) {
return ((GroovyFile) file).getScriptClass();
}
}
return null;
}
use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class GrImportFilteringRule method isVisible.
@Override
public boolean isVisible(@NotNull Usage usage) {
if (usage instanceof PsiElementUsage) {
final PsiElement psiElement = ((PsiElementUsage) usage).getElement();
final PsiFile containingFile = psiElement.getContainingFile();
if (containingFile instanceof GroovyFile) {
// check whether the element is in the import list
return PsiTreeUtil.getParentOfType(psiElement, GrImportStatement.class, true) == null;
}
}
return true;
}
use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class XsltBreakpointHandler method getActualLineNumber.
public static int getActualLineNumber(Project project, @Nullable XSourcePosition position) {
if (position == null) {
return -1;
}
final PsiElement element = findContextElement(project, position);
if (element == null) {
return -1;
}
if (element instanceof XmlToken) {
final IElementType tokenType = ((XmlToken) element).getTokenType();
if (tokenType == XmlTokenType.XML_START_TAG_START || tokenType == XmlTokenType.XML_NAME) {
final PsiManager psiManager = PsiManager.getInstance(project);
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
final PsiFile psiFile = psiManager.findFile(position.getFile());
if (psiFile == null) {
return -1;
}
final Document document = documentManager.getDocument(psiFile);
if (document == null) {
return -1;
}
if (document.getLineNumber(element.getTextRange().getStartOffset()) == position.getLine()) {
final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
if (tag != null) {
final ASTNode node = tag.getNode();
assert node != null;
// TODO: re-check if/when Xalan is supported
final ASTNode end = XmlChildRole.START_TAG_END_FINDER.findChild(node);
if (end != null) {
return document.getLineNumber(end.getTextRange().getEndOffset()) + 1;
} else {
final ASTNode end2 = XmlChildRole.EMPTY_TAG_END_FINDER.findChild(node);
if (end2 != null) {
return document.getLineNumber(end2.getTextRange().getEndOffset()) + 1;
}
}
}
}
}
}
return -1;
}
use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class PyTemporaryInjector method getInjectedLanguage.
@Nullable
@Override
public Language getInjectedLanguage(@NotNull PsiElement context) {
final TemporaryPlacesRegistry registry = TemporaryPlacesRegistry.getInstance(context.getProject());
if (context instanceof PsiLanguageInjectionHost) {
final PsiFile file = context.getContainingFile();
final InjectedLanguage injectedLanguage = registry.getLanguageFor((PsiLanguageInjectionHost) context, file);
if (injectedLanguage != null) {
return injectedLanguage.getLanguage();
}
}
return null;
}
Aggregations