use of com.intellij.psi.PsiCompiledFile in project intellij-plugins by JetBrains.
the class FlexTreeStructureProvider method modify.
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
List<AbstractTreeNode> result = new ArrayList<>();
if (parent instanceof SwfQualifiedNamedElementNode || parent instanceof FlexFileNode) {
if (((ProjectViewNode) parent).getSettings().isShowMembers()) {
JSQualifiedNamedElement parentElement = getElement(parent);
if (parentElement != null) {
JSStructureViewElement structureViewElement = parentElement instanceof XmlBackedJSClassImpl ? new FlexStructureViewElement(((XmlBackedJSClassImpl) parentElement), (XmlFile) parentElement.getContainingFile(), false) : new JSStructureViewElement(parentElement, false, true);
StructureViewTreeElement[] structureViewChildren = structureViewElement.getChildren();
for (final StructureViewTreeElement structureViewChild : structureViewChildren) {
if (structureViewChild instanceof JSStructureViewElement) {
PsiElement childElement = ((JSStructureViewElement) structureViewChild).getValue();
result.add(new FlexClassMemberNode((JSElement) childElement, ((ProjectViewNode) parent).getSettings()));
} else {
result.add(new UnknownNode(parentElement.getProject(), structureViewChild, ((ProjectViewNode) parent).getSettings()));
}
}
}
}
} else {
for (final AbstractTreeNode child : children) {
Object o = child.getValue();
if (o instanceof JSFileImpl && !(o instanceof PsiCompiledFile) && DialectDetector.isActionScript((PsiFile) o) || o instanceof XmlFile && JavaScriptSupportLoader.isFlexMxmFile((PsiFile) o)) {
result.add(new FlexFileNode((PsiFile) o, ((ProjectViewNode) parent).getSettings()));
continue;
}
result.add(child);
}
}
return result;
}
use of com.intellij.psi.PsiCompiledFile in project intellij-plugins by JetBrains.
the class SwfProjectViewStructureProvider method modify.
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
if (!(parent instanceof PsiFileNode)) {
return children;
}
final PsiFile psiFile = ((PsiFileNode) parent).getValue();
if (!(psiFile instanceof PsiCompiledFile) || !(psiFile instanceof JSFile)) {
return children;
}
final VirtualFile vFile = psiFile.getVirtualFile();
if (vFile == null || vFile.getFileType() != FlexApplicationComponent.SWF_FILE_TYPE) {
return children;
}
if (isTooManySWFs(vFile.getParent())) {
return children;
}
List<JSQualifiedNamedElement> elements = new ArrayList<>();
for (JSSourceElement e : ((JSFile) psiFile).getStatements()) {
if (e instanceof JSQualifiedNamedElement) {
String qName = ((JSQualifiedNamedElement) e).getQualifiedName();
if (qName == null) {
final Attachment attachment = e.getParent() != null ? new Attachment("Parent element.txt", e.getParent().getText()) : new Attachment("Element text.txt", e.getText());
LOG.error(LogMessageEx.createEvent("Null qname: '" + e.getClass().getName() + "'", DebugUtil.currentStackTrace(), attachment));
continue;
}
elements.add((JSQualifiedNamedElement) e);
} else if (e instanceof JSVarStatement) {
Collections.addAll(elements, ((JSVarStatement) e).getVariables());
}
}
Collections.sort(elements, QNAME_COMPARATOR);
return getChildrenForPackage("", elements, 0, elements.size(), psiFile.getProject(), ((PsiFileNode) parent).getSettings());
}
use of com.intellij.psi.PsiCompiledFile in project intellij-community by JetBrains.
the class CompletionUtilCoreImpl method getOriginalElement.
@Nullable
public static <T extends PsiElement> T getOriginalElement(@NotNull T psi, PsiFile containingFile) {
if (containingFile == null)
return psi;
PsiFile originalFile = containingFile.getOriginalFile();
TextRange range;
if (originalFile != containingFile && !(originalFile instanceof PsiCompiledFile) && (range = psi.getTextRange()) != null) {
Integer start = range.getStartOffset();
Integer end = range.getEndOffset();
Document document = containingFile.getViewProvider().getDocument();
if (document != null) {
Document hostDocument = document instanceof DocumentWindow ? ((DocumentWindow) document).getDelegate() : document;
OffsetTranslator translator = hostDocument.getUserData(OffsetTranslator.RANGE_TRANSLATION);
if (translator != null) {
if (document instanceof DocumentWindow) {
TextRange translated = ((DocumentWindow) document).injectedToHost(new TextRange(start, end));
start = translated.getStartOffset();
end = translated.getEndOffset();
}
start = translator.translateOffset(start);
end = translator.translateOffset(end);
if (start == null || end == null) {
return null;
}
if (document instanceof DocumentWindow) {
start = ((DocumentWindow) document).hostToInjected(start);
end = ((DocumentWindow) document).hostToInjected(end);
}
}
}
//noinspection unchecked
return (T) PsiTreeUtil.findElementOfClassAtRange(originalFile, start, end, psi.getClass());
}
return psi;
}
Aggregations