use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement 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.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class SwfProjectViewStructureProvider method findDecompiledElement.
@Nullable
private static PsiElement findDecompiledElement(JSQualifiedNamedElement element) {
if (DumbService.isDumb(element.getProject())) {
return null;
}
JSQualifiedNamedElement mainElement = JSUtils.getMemberContainingClass(element);
if (mainElement == null) {
mainElement = element;
}
final String qName = mainElement.getQualifiedName();
if (qName == null) {
return null;
}
VirtualFile elementVFile = mainElement.getContainingFile().getVirtualFile();
if (elementVFile == null) {
return null;
}
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(mainElement.getProject()).getFileIndex();
GlobalSearchScope searchScope = JSResolveUtil.getResolveScope(mainElement);
Collection<JSQualifiedNamedElement> candidates = StubIndex.getElements(JSQualifiedElementIndex.KEY, qName.hashCode(), mainElement.getProject(), searchScope, JSQualifiedNamedElement.class);
List<OrderEntry> sourceFileEntries = projectFileIndex.getOrderEntriesForFile(elementVFile);
for (JSQualifiedNamedElement candidate : candidates) {
if (candidate == mainElement || !qName.equals(candidate.getQualifiedName())) {
continue;
}
VirtualFile vFile = candidate.getContainingFile().getVirtualFile();
if (vFile != null && projectFileIndex.getClassRootForFile(vFile) != null) {
List<OrderEntry> candidateEntries = projectFileIndex.getOrderEntriesForFile(vFile);
if (ContainerUtil.intersects(sourceFileEntries, candidateEntries)) {
if (element == mainElement) {
return candidate;
} else {
LOG.assertTrue(candidate instanceof JSClass, candidate);
if (element instanceof JSVariable) {
return ((JSClass) candidate).findFieldByName(element.getName());
} else {
LOG.assertTrue(element instanceof JSFunction, element);
return ((JSClass) candidate).findFunctionByNameAndKind(element.getName(), ((JSFunction) element).getKind());
}
}
}
}
}
return null;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class SwfQualifiedNamedElementNode method update.
@Override
protected void update(PresentationData presentation) {
final JSQualifiedNamedElement value = getValue();
if (value != null && value.isValid()) {
presentation.setPresentableText(value.getName());
presentation.setIcon(value.getIcon(Iconable.ICON_FLAG_VISIBILITY));
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class ActionScriptClassResolver method doFindClassByQName.
protected PsiElement doFindClassByQName(@NotNull String link, final JavaScriptIndex index, GlobalSearchScope searchScope, boolean allowFileLocalSymbols, @NotNull DialectOptionHolder dialect) {
Project project = index.getProject();
boolean clazzShouldBeTakenFromOurLibrary = OBJECT_CLASS_NAME.equals(link) || "Arguments".equals(link);
if (clazzShouldBeTakenFromOurLibrary && !(searchScope instanceof AdditionalIndexedRootsScope)) {
// object from swf do not contain necessary members!
searchScope = new AdditionalIndexedRootsScope(searchScope, JSIndexedRootProvider.class);
}
final Collection<JSQualifiedNamedElement> candidates = StubIndex.getElements(JSQualifiedElementIndex.KEY, link.hashCode(), project, searchScope, JSQualifiedNamedElement.class);
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
JSQualifiedNamedElement resultFromSourceContent = null;
JSQualifiedNamedElement resultFromLibraries = null;
long resultFromLibrariesTimestamp = 0;
for (JSQualifiedNamedElement classCandidate : candidates) {
if (!(classCandidate instanceof JSQualifiedNamedElement))
continue;
if (JSResolveUtil.isConstructorFunction(classCandidate))
continue;
JSQualifiedNamedElement clazz = classCandidate;
if (link.equals(clazz.getQualifiedName())) {
PsiFile file = clazz.getContainingFile();
if (!file.getLanguage().isKindOf(JavaScriptSupportLoader.ECMA_SCRIPT_L4))
continue;
VirtualFile vFile = file.getVirtualFile();
if (clazzShouldBeTakenFromOurLibrary && // object from swf do not contain necessary members!
!JavaScriptIndex.ECMASCRIPT_JS2.equals(vFile.getName())) {
continue;
}
if (!allowFileLocalSymbols && JSResolveUtil.isFileLocalSymbol(clazz)) {
continue;
}
if (projectFileIndex.isInSourceContent(vFile)) {
// the absolute preference is for classes from sources
resultFromSourceContent = clazz;
continue;
}
// choose the right class in the same way as compiler does: with the latest timestamp in catalog.xml file
if (resultFromLibraries == null) {
resultFromLibraries = clazz;
// do not initialize resultFromLibrariesTimestamp here, it is expensive and may be not required if only 1 candidate
} else if (JSCommonTypeNames.VECTOR_CLASS_NAME.equals(link)) {
if (clazz instanceof JSClass && resultFromLibraries instanceof JSClass && ((JSClass) clazz).getFunctions().length > ((JSClass) resultFromLibraries).getFunctions().length) {
resultFromLibraries = clazz;
}
} else {
if (resultFromLibrariesTimestamp == 0) {
// was not initialized yet
resultFromLibrariesTimestamp = getResolveResultTimestamp(resultFromLibraries);
}
final long classTimestamp = getResolveResultTimestamp(clazz);
if (classTimestamp > resultFromLibrariesTimestamp) {
resultFromLibraries = clazz;
resultFromLibrariesTimestamp = classTimestamp;
}
}
}
}
PsiElement result = resultFromSourceContent != null ? resultFromSourceContent : resultFromLibraries;
if (result == null) {
String className = link.substring(link.lastIndexOf('.') + 1);
if (className.length() > 0 && !isBuiltInClassName(className) && (Character.isLetter(className.charAt(0)) || '_' == className.charAt(0))) {
// TODO optimization, remove when packages will be properly handled
result = findClassByQNameViaHelper(link, project, className, searchScope);
}
}
return result;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class ActionScriptImportHandler method resolveTypeNameInTheSamePackage.
private static JSNamedElement resolveTypeNameInTheSamePackage(@NotNull final String str, final PsiElement context) {
JSNamedElement fileLocalElement = JSResolveUtil.findFileLocalElement(str, context);
if (fileLocalElement != null)
return fileLocalElement;
final String packageQualifierText = JSResolveUtil.findPackageStatementQualifier(context);
PsiElement byQName;
if (packageQualifierText != null) {
byQName = JSClassResolver.findClassFromNamespace(packageQualifierText + "." + str, context);
if (byQName instanceof JSQualifiedNamedElement) {
return (JSQualifiedNamedElement) byQName;
}
}
byQName = JSDialectSpecificHandlersFactory.forElement(context).getClassResolver().findClassByQName(str, context);
if (byQName instanceof JSQualifiedNamedElement && JSResolveUtil.acceptableSymbol((JSQualifiedNamedElement) byQName, JSResolveUtil.GlobalSymbolsAcceptanceState.WHATEVER, false, context)) {
return (JSQualifiedNamedElement) byQName;
}
return null;
}
Aggregations