use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlexXmlBackedClassesIndex method getIndexer.
@Override
@NotNull
public DataIndexer<String, Void, FileContent> getIndexer() {
return new DataIndexer<String, Void, FileContent>() {
@Override
@NotNull
public Map<String, Void> map(@NotNull FileContent inputData) {
final XmlFile file = (XmlFile) inputData.getPsiFile();
final Map<String, Void> result = new HashMap<>();
for (JSClass clazz : XmlBackedJSClassImpl.getClasses(file)) {
JSReferenceList supers = getSupers(clazz);
if (supers != null) {
final JSExpression[] expressions = supers.getExpressions();
for (JSExpression expr : expressions) {
String s = expr instanceof JSReferenceExpression ? ((JSReferenceExpression) expr).getReferenceName() : null;
if (s != null)
result.put(s, null);
}
}
}
return result;
}
};
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlexSchemaHandler method getAvailableNamespaces.
@NotNull
@Override
public Set<String> getAvailableNamespaces(@NotNull XmlFile _file, @Nullable @NonNls final String tagName) {
// tagName == null => tag name completion
// tagName != null => guess namespace of unresolved tag
PsiFile originalFile = _file.getOriginalFile();
if (originalFile instanceof XmlFile)
_file = (XmlFile) originalFile;
final XmlFile file = _file;
final Project project = file.getProject();
final Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(file.getVirtualFile());
final Collection<String> illegalNamespaces = getIllegalNamespaces(file);
final Set<String> result = new THashSet<>();
final Set<String> componentsThatHaveNotPackageBackedNamespace = new THashSet<>();
for (final String namespace : CodeContextHolder.getInstance(project).getNamespaces(module)) {
if (!CodeContext.isPackageBackedNamespace(namespace) && !illegalNamespaces.contains(namespace)) {
// package backed namespaces will be added later from JSPackageIndex
if (tagName == null) {
result.add(namespace);
} else {
final XmlElementDescriptor descriptor = CodeContext.getContext(namespace, module).getElementDescriptor(tagName, (XmlTag) null);
if (descriptor != null) {
result.add(namespace);
componentsThatHaveNotPackageBackedNamespace.add(descriptor.getQualifiedName());
}
}
}
}
if (tagName == null && !illegalNamespaces.contains(JavaScriptSupportLoader.MXML_URI)) {
result.add(JavaScriptSupportLoader.MXML_URI);
}
if (XmlBackedJSClassImpl.SCRIPT_TAG_NAME.equals(tagName) || "Style".equals(tagName))
return result;
if (DumbService.isDumb(project))
return result;
if (tagName == null) {
FileBasedIndex.getInstance().processAllKeys(JSPackageIndex.INDEX_ID, packageName -> {
result.add(StringUtil.isEmpty(packageName) ? "*" : packageName + ".*");
return true;
}, project);
} else {
final GlobalSearchScope scopeWithLibs = module != null ? GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module) : GlobalSearchScope.allScope(project);
for (JSQualifiedNamedElement element : JSResolveUtil.findElementsByName(tagName, project, scopeWithLibs, false)) {
if (element instanceof JSClass && CodeContext.hasDefaultConstructor((JSClass) element)) {
final String packageName = StringUtil.getPackageName(element.getQualifiedName());
if (!componentsThatHaveNotPackageBackedNamespace.contains(StringUtil.getQualifiedName(packageName, tagName))) {
result.add(StringUtil.isEmpty(packageName) ? "*" : packageName + ".*");
}
}
}
}
final GlobalSearchScope scopeWithoutLibs = module != null ? GlobalSearchScope.moduleWithDependenciesScope(module) : GlobalSearchScope.allScope(project);
// packages that contain *.mxml files and do not contain *.as are not retrieved from JSPackageIndex
FlexResolveHelper.processAllMxmlAndFxgFiles(scopeWithoutLibs, project, new FlexResolveHelper.MxmlAndFxgFilesProcessor() {
public void addDependency(final PsiDirectory directory) {
}
public boolean processFile(final VirtualFile file, final VirtualFile root) {
if (tagName == null || tagName.equals(file.getNameWithoutExtension())) {
final String packageName = VfsUtilCore.getRelativePath(file.getParent(), root, '.');
if (packageName != null && (tagName == null || !componentsThatHaveNotPackageBackedNamespace.contains(StringUtil.getQualifiedName(packageName, tagName)))) {
result.add(StringUtil.isEmpty(packageName) ? "*" : packageName + ".*");
}
}
return true;
}
}, tagName);
return result;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlexUndefinedElementFixProvider method createFixes.
@Nullable
@Override
public IntentionAction[] createFixes(@NotNull XmlAttribute attribute) {
if (!JavaScriptSupportLoader.isFlexMxmFile(attribute.getContainingFile()))
return null;
final String name = attribute.getName();
if (!JSRefactoringUtil.isValidIdentifier(name, attribute.getProject())) {
return IntentionAction.EMPTY_ARRAY;
}
final XmlElementDescriptor descriptor = attribute.getParent().getDescriptor();
final PsiElement declaration = descriptor instanceof ClassBackedElementDescriptor ? descriptor.getDeclaration() : null;
final VirtualFile virtualFile = declaration == null ? null : declaration.getContainingFile().getVirtualFile();
if (virtualFile == null || ProjectRootManager.getInstance(declaration.getProject()).getFileIndex().getSourceRootForFile(virtualFile) == null) {
return IntentionAction.EMPTY_ARRAY;
}
if (declaration instanceof JSClass || declaration instanceof XmlFile && JavaScriptSupportLoader.isFlexMxmFile((XmlFile) declaration)) {
final String attributeValue = attribute.getValue();
final FixAndIntentionAction fix1 = new CreateFieldByMxmlAttributeFix(name, attributeValue);
fix1.registerElementRefForFix(attribute, null);
final FixAndIntentionAction fix2 = new CreateSetterByMxmlAttributeFix(name, attributeValue);
fix2.registerElementRefForFix(attribute, null);
final FixAndIntentionAction fix3 = new CreateEventMetadataByMxmlAttributeFix(name);
fix3.registerElementRefForFix(attribute, null);
return new IntentionAction[] { fix1, fix2, fix3 };
}
return IntentionAction.EMPTY_ARRAY;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class AngularAttributeDescriptor method getFieldBasedDescriptors.
public static XmlAttributeDescriptor[] getFieldBasedDescriptors(JSImplicitElement declaration, String decorator, NullableFunction<Pair<PsiElement, String>, XmlAttributeDescriptor> factory) {
final JSClass clazz = PsiTreeUtil.getContextOfType(declaration, JSClass.class);
if (clazz != null) {
JSField[] fields = clazz.getFields();
final List<XmlAttributeDescriptor> result = new ArrayList<>(fields.length);
for (JSField field : fields) {
String decoratedName = getDecoratedName(field, decorator);
if (decoratedName == null)
continue;
ContainerUtil.addIfNotNull(result, factory.fun(Pair.create(field, decoratedName)));
}
for (JSFunction function : clazz.getFunctions()) {
String decoratedName = getDecoratedName(function, decorator);
if (decoratedName == null)
continue;
ContainerUtil.addIfNotNull(result, factory.fun(Pair.create(function, decoratedName)));
}
return result.toArray(new XmlAttributeDescriptor[result.size()]);
}
if (!DialectDetector.isTypeScript(declaration)) {
return getCompiledFieldBasedDescriptors(declaration, decorator, factory);
}
return EMPTY;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class ActionScriptHighlightingTest method testNamespaceElementReferences2.
public void testNamespaceElementReferences2() throws Exception {
defaultTest();
JSReferenceExpression expr = PsiTreeUtil.getParentOfType(myFile.findElementAt(myEditor.getCaretModel().getOffset()), JSReferenceExpression.class);
assertNotNull(expr);
PsiElement exprResolve = expr.resolve();
assertTrue(exprResolve instanceof JSFunction);
JSClass clazz = PsiTreeUtil.getParentOfType(exprResolve, JSClass.class);
assertNotNull(clazz);
assertEquals("Foo", clazz.getQualifiedName());
}
Aggregations