use of com.intellij.lang.javascript.index.JavaScriptIndex in project intellij-plugins by JetBrains.
the class FlexHighlightingTest method checkNavigatableSymbols.
private void checkNavigatableSymbols(String s) {
JavaScriptIndex scriptIndex = JavaScriptIndex.getInstance(myProject);
String[] strings = scriptIndex.getSymbolNames();
Arrays.sort(strings);
assertTrue(Arrays.binarySearch(strings, s) >= 0);
NavigationItem[] navigationItems = scriptIndex.getSymbolsByName(s, true);
assertTrue(navigationItems.length > 0);
boolean containedInLibrarySwf = false;
for (NavigationItem navigationItem : navigationItems) {
if (navigationItem instanceof JSNamedElement && "library.swf".equals(((PsiElement) navigationItem).getContainingFile().getName())) {
containedInLibrarySwf = true;
break;
}
}
assertTrue(containedInLibrarySwf);
}
use of com.intellij.lang.javascript.index.JavaScriptIndex in project intellij-plugins by JetBrains.
the class FlexValue method findJSClass.
@Nullable
private static JSClass findJSClass(final Project project, @Nullable final Module module, final String typeFromFlexValueResult) {
String type = getType(typeFromFlexValueResult);
if (type != null) {
if (isGenericVector(type)) {
type = VECTOR;
}
final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project);
PsiElement jsClass = ActionScriptClassResolver.findClassByQName(type, jsIndex, module);
if (!(jsClass instanceof JSClass) && type.endsWith("$")) {
// fdb adds '$' to class name in case of static context
jsClass = ActionScriptClassResolver.findClassByQName(type.substring(0, type.length() - 1), jsIndex, module);
}
if (!(jsClass instanceof JSClass) && module != null) {
// probably this class came from dynamically loaded module that is not in moduleWithDependenciesAndLibrariesScope(module)
final GlobalSearchScope scope = ProjectScope.getAllScope(project);
jsClass = ActionScriptClassResolver.findClassByQNameStatic(type, scope);
if (!(jsClass instanceof JSClass) && type.endsWith("$")) {
jsClass = ActionScriptClassResolver.findClassByQNameStatic(type.substring(0, type.length() - 1), scope);
}
}
return jsClass instanceof JSClass ? (JSClass) jsClass : null;
}
return null;
}
use of com.intellij.lang.javascript.index.JavaScriptIndex in project intellij-plugins by JetBrains.
the class FlexDocumentationProvider method getDocumentationElementForLinkStatic.
@Nullable
private static PsiElement getDocumentationElementForLinkStatic(final PsiManager psiManager, String link, final PsiElement context) {
final int delimiterIndex = link.lastIndexOf(':');
final JavaScriptIndex index = JavaScriptIndex.getInstance(psiManager.getProject());
String attributeType = null;
String attributeName = null;
for (Map.Entry<String, String> e : DOCUMENTED_ATTRIBUTES.entrySet()) {
final String pattern = "." + e.getValue();
if (link.contains(pattern)) {
attributeType = e.getKey();
attributeName = StringUtil.substringAfter(link, pattern);
link = link.substring(0, link.indexOf(pattern));
break;
}
}
if (delimiterIndex != -1 && attributeType == null) {
return resolveDocumentLink(psiManager, link, delimiterIndex);
} else if (attributeType != null) {
PsiElement clazz = ActionScriptClassResolver.findClassByQName(link, index, context != null ? ModuleUtilCore.findModuleForPsiElement(context) : null);
if (!(clazz instanceof JSClass)) {
return null;
}
return findNamedAttribute((JSClass) clazz, attributeType, attributeName);
} else {
PsiElement clazz = ActionScriptClassResolver.findClassByQName(link, index, context != null ? ModuleUtilCore.findModuleForPsiElement(context) : null);
if (clazz == null && link.contains(".")) {
String qname = link.substring(0, link.lastIndexOf('.'));
clazz = ActionScriptClassResolver.findClassByQName(qname, index, context != null ? ModuleUtilCore.findModuleForPsiElement(context) : null);
if (clazz instanceof JSClass) {
JSClass jsClass = (JSClass) clazz;
String member = link.substring(link.lastIndexOf('.') + 1);
if (member.endsWith("()")) {
member = member.substring(0, member.length() - 2);
PsiElement result = findMethod(jsClass, member);
if (result == null) {
// user might refer to a property
result = findProperty(jsClass, member);
}
return result;
} else {
PsiElement result = jsClass.findFieldByName(member);
if (result == null) {
result = findProperty(jsClass, member);
}
if (result == null) {
// user might forget brackets
result = findMethod(jsClass, member);
}
return result;
}
}
}
if (clazz instanceof JSVariable) {
return clazz;
}
if (link.endsWith("()")) {
link = link.substring(0, link.length() - 2);
clazz = ActionScriptClassResolver.findClassByQName(link, index, context != null ? ModuleUtilCore.findModuleForPsiElement(context) : null);
if (clazz instanceof JSFunction) {
return clazz;
}
}
if (clazz == null && context != null) {
final PsiReference[] references = new JSDocReferenceSet(context, link, 0, false).getReferences();
if (references.length > 0) {
final PsiElement resolve = references[references.length - 1].resolve();
if (resolve != null)
return resolve;
}
}
return clazz;
}
}
use of com.intellij.lang.javascript.index.JavaScriptIndex in project intellij-plugins by JetBrains.
the class FlexQualifiedNameLocationProvider method findElement.
@Nullable
private static JSElement findElement(String link, Project project) {
String moduleName = link.substring(0, link.indexOf(":"));
Module module = ModuleManager.getInstance(project).findModuleByName(moduleName);
link = link.substring(link.indexOf(":") + 1);
final JavaScriptIndex index = JavaScriptIndex.getInstance(project);
PsiElement element = ActionScriptClassResolver.findClassByQName(link, index, module);
if (element instanceof JSClass) {
return (JSElement) element;
}
if (element == null && link.contains(".") && link.endsWith("()")) {
String qname = link.substring(0, link.lastIndexOf('.'));
element = ActionScriptClassResolver.findClassByQName(qname, index, module);
if (element instanceof JSClass) {
String methodName = link.substring(link.lastIndexOf('.') + 1, link.length() - 2);
return ((JSClass) element).findFunctionByNameAndKind(methodName, JSFunction.FunctionKind.SIMPLE);
}
}
return null;
}
Aggregations