use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement 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.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class SwfProjectViewStructureProvider method getChildrenForPackage.
static Collection<AbstractTreeNode> getChildrenForPackage(String aPackage, List<JSQualifiedNamedElement> elements, int from, int to, Project project, ViewSettings settings) {
List<AbstractTreeNode> packages = new ArrayList<>();
List<AbstractTreeNode> classes = new ArrayList<>();
int subpackageStart = -1;
String currentSubpackage = null;
for (int i = from; i < to; i++) {
JSQualifiedNamedElement element = elements.get(i);
String qName = element.getQualifiedName();
assert aPackage.isEmpty() || qName.startsWith(aPackage + ".") : qName + " does not start with " + aPackage;
if (StringUtil.getPackageName(qName).equals(aPackage)) {
classes.add(new SwfQualifiedNamedElementNode(project, element, settings));
} else {
final int endIndex = qName.indexOf('.', aPackage.length() + 1);
if (endIndex <= 0) {
final Attachment attachment = element.getParent() != null ? new Attachment("Parent element.txt", element.getParent().getText()) : new Attachment("Element text.txt", element.getText());
LOG.error(LogMessageEx.createEvent("package=[" + aPackage + "], qName=[" + qName + "]", DebugUtil.currentStackTrace(), attachment));
continue;
}
String subpackage = settings.isFlattenPackages() ? StringUtil.getPackageName(qName) : qName.substring(0, endIndex);
if (currentSubpackage == null) {
subpackageStart = i;
} else if (!currentSubpackage.equals(subpackage)) {
packages.add(createSubpackageNode(elements, project, settings, subpackageStart, i, currentSubpackage));
subpackageStart = i;
}
currentSubpackage = subpackage;
}
}
if (currentSubpackage != null) {
packages.add(createSubpackageNode(elements, project, settings, subpackageStart, to, currentSubpackage));
}
return ContainerUtil.concat(packages, classes);
}
Aggregations