use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlexPropertyReferenceProvider method getReferencesByElement.
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
PsiElement parent = element.getParent();
JSReferenceExpression invokedMethod = JSUtils.getMethodNameIfInsideCall(parent);
List<PsiReference> result = new ArrayList<>();
if (invokedMethod != null) {
String invokedMethodName;
boolean justResourceBundleRef = false;
PsiElement qualifier;
if ((ourMethodsWithPropertyReferences.contains(invokedMethodName = (invokedMethod.getReferencedName())) || (justResourceBundleRef = "getResourceBundle".equals(invokedMethodName))) && ((qualifier = invokedMethod.getQualifier()) instanceof JSReferenceExpression || (qualifier instanceof JSCallExpression && ((JSCallExpression) qualifier).getMethodExpression() instanceof JSReferenceExpression))) {
final JSExpression[] args = ((JSArgumentList) parent).getArguments();
boolean propertyRef = false;
boolean bundleRef = false;
if (justResourceBundleRef) {
bundleRef = args.length > 1 && args[1] == element;
} else {
propertyRef = args.length > 1 && args[1] == element;
bundleRef = args.length > 0 && args[0] == element;
if (bundleRef && args.length == 1) {
// ResourceBundle.getString deprecated, without bundle name
bundleRef = false;
propertyRef = true;
}
}
boolean isSoft = true;
if (propertyRef || bundleRef) {
PsiElement resolved = invokedMethod.resolve();
if (resolved instanceof JSFunction) {
PsiElement parentClass = JSResolveUtil.findParent(resolved);
if (parentClass instanceof JSClass) {
String name = ((JSClass) parentClass).getName();
isSoft = name == null || (name.indexOf("ResourceManager") == -1 && name.indexOf("ResourceBundle") == -1);
}
}
}
if (propertyRef) {
FlexPropertiesSupport.PropertyReferenceInfoProvider<JSLiteralExpressionImpl> provider = isSoft ? ourSoftPropertyInfoProvider : ourPropertyInfoProvider;
if (args.length > 1 && !isSoft) {
JSExpression bundleExpression = args[0];
if (bundleExpression instanceof JSReferenceExpression) {
PsiElement resolved = ((JSReferenceExpression) bundleExpression).resolve();
if (resolved instanceof JSVariable) {
bundleExpression = ((JSVariable) resolved).getInitializer();
}
}
if (bundleExpression instanceof JSLiteralExpression) {
final Object expressionValue = ((JSLiteralExpression) bundleExpression).getValue();
if (expressionValue instanceof String) {
provider = new FlexPropertiesSupport.PropertyReferenceInfoProvider<JSLiteralExpressionImpl>() {
public TextRange getReferenceRange(JSLiteralExpressionImpl element) {
return getValueRange(element);
}
public String getBundleName(JSLiteralExpressionImpl element) {
return (String) expressionValue;
}
public boolean isSoft(JSLiteralExpressionImpl element) {
return false;
}
};
}
}
}
Collections.addAll(result, FlexPropertiesSupport.getPropertyReferences((JSLiteralExpressionImpl) element, provider));
} else if (bundleRef) {
PsiReference[] reference = FlexPropertiesSupport.getResourceBundleReference((JSLiteralExpressionImpl) element, isSoft ? ourSoftBundleInfoProvider : ourBundleInfoProvider);
Collections.addAll(result, reference);
}
}
}
return result.toArray(new PsiReference[result.size()]);
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlexCssPropertyDescriptor method getDeclarations.
@NotNull
@Override
public PsiElement[] getDeclarations(@NotNull PsiElement context) {
Map<PsiElement, PairInfo> navElement2pairInfo = new HashMap<>();
final Project project = context.getProject();
GlobalSearchScope scope = FlexCssUtil.getResolveScope(context);
Set<JSClass> visited = ContainerUtil.newLinkedHashSet();
for (String className : myClassNames) {
Collection<JSQualifiedNamedElement> candidates = StubIndex.getElements(JSQualifiedElementIndex.KEY, className.hashCode(), project, scope, JSQualifiedNamedElement.class);
findStyleAttributes(candidates, visited, navElement2pairInfo);
// search in MXML files
PsiElement jsClass = ActionScriptClassResolver.findClassByQNameStatic(className, scope);
if (jsClass instanceof JSClass) {
findStyleAttributesInClassOrSuper((JSClass) jsClass, visited, navElement2pairInfo);
}
}
Set<JSFile> visitedFiles = ContainerUtil.newLinkedHashSet();
for (String fileName : myFileNames) {
Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(project, fileName, scope);
for (final VirtualFile file : files) {
PsiFile psiFile = ReadAction.compute(() -> PsiManager.getInstance(project).findFile(file));
if (psiFile instanceof JSFile) {
findStyleAttributesInFile((JSFile) psiFile, visitedFiles, navElement2pairInfo);
}
}
}
Set<PsiElement> navPairs = navElement2pairInfo.keySet();
Map<String, PsiElement> qName2ResultElement = new HashMap<>();
for (PsiElement navPair : navPairs) {
PairInfo pairInfo = navElement2pairInfo.get(navPair);
String jsClassQName = pairInfo.myJsClassQName;
PsiElement navPairInOtherClassWithSameQName = jsClassQName != null ? qName2ResultElement.get(jsClassQName) : null;
if (navPairInOtherClassWithSameQName == null || navPairInOtherClassWithSameQName == navElement2pairInfo.get(navPairInOtherClassWithSameQName) && pairInfo.myPair != navPair) {
qName2ResultElement.put(jsClassQName, navPair);
}
}
Collection<PsiElement> result = qName2ResultElement.values();
return PsiUtilCore.toPsiElementArray(result);
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class ActionScriptSmartCompletionContributor method getEventsMap.
public static Map<String, String> getEventsMap(JSClass clazzToProcess) {
if (clazzToProcess == null)
return Collections.emptyMap();
final Map<String, String> eventsMap = new THashMap<>();
class EventsDataCollector extends ResolveProcessor implements ActionScriptResolveUtil.MetaDataProcessor {
public EventsDataCollector() {
super(null);
setToProcessHierarchy(true);
setToProcessMembers(false);
setTypeContext(true);
setLocalResolve(true);
}
@Override
public boolean process(@NotNull final JSAttribute jsAttribute) {
if ("Event".equals(jsAttribute.getName())) {
final JSAttributeNameValuePair eventAttr = jsAttribute.getValueByName("name");
JSAttributeNameValuePair typeAttr = jsAttribute.getValueByName("type");
if (eventAttr != null && typeAttr != null) {
final String simpleValue = eventAttr.getSimpleValue();
if (simpleValue != null) {
eventsMap.put(simpleValue, typeAttr.getSimpleValue());
}
}
}
return true;
}
@Override
public boolean handleOtherElement(final PsiElement el, final PsiElement context, final Ref<PsiElement> continuePassElement) {
return true;
}
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
if (element instanceof JSClass) {
ActionScriptResolveUtil.processMetaAttributesForClass(element, this, true);
}
return true;
}
}
final EventsDataCollector eventsDataCollector = new EventsDataCollector();
if (clazzToProcess instanceof XmlBackedJSClassImpl) {
XmlFile file = (XmlFile) clazzToProcess.getParent().getContainingFile();
if (file != null && JavaScriptSupportLoader.isFlexMxmFile(file)) {
final XmlDocument xmlDocument = file.getDocument();
final XmlTag rootTag = xmlDocument == null ? null : xmlDocument.getRootTag();
final XmlTag[] tags = rootTag == null ? XmlTag.EMPTY : MxmlJSClass.findLanguageSubTags(rootTag, FlexPredefinedTagNames.METADATA);
JSResolveUtil.JSInjectedFilesVisitor injectedFilesVisitor = new JSResolveUtil.JSInjectedFilesVisitor() {
@Override
protected void process(JSFile file) {
for (PsiElement element : file.getChildren()) {
if (element instanceof JSAttributeList) {
ActionScriptResolveUtil.processAttributeList(eventsDataCollector, null, (JSAttributeList) element, true, true);
}
}
}
};
for (XmlTag tag : tags) {
JSResolveUtil.processInjectedFileForTag(tag, injectedFilesVisitor);
}
}
}
clazzToProcess.processDeclarations(eventsDataCollector, ResolveState.initial(), clazzToProcess, clazzToProcess);
return eventsMap;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class ActionScriptSmartCompletionContributor method processContextClass.
@Override
protected int processContextClass(@NotNull JSReferenceExpression location, JSType expectedType, PsiElement parent, List<Object> variants, int qualifiedStaticVariantsStart, SinkResolveProcessor<?> processor, JSClass ourClass) {
JSClass clazz = expectedType.resolveClass();
if (clazz != null && !clazz.isEquivalentTo(ourClass)) {
qualifiedStaticVariantsStart = processor.getResultSink().getResultCount();
processStaticsOf(clazz, processor, ourClass);
}
if (ourClass != null && clazz != null && JSInheritanceUtil.isParentClass(ourClass, clazz, false) && !JSResolveUtil.calculateStaticFromContext(location) && JSCompletionContributor.getInstance().isDoingSmartCodeCompleteAction()) {
variants.add(JSLookupUtilImpl.createPrioritizedLookupItem(null, "this", JSLookupPriority.SMART_PRIORITY, true, true));
}
if (parent instanceof JSArgumentList) {
JSParameterItem param = JSResolveUtil.findParameterForUsedArgument(location, (JSArgumentList) parent);
if (param instanceof JSParameter) {
PsiElement element = JSResolveUtil.findParent(((JSParameter) param).getParent().getParent());
if (element instanceof JSClass && !element.isEquivalentTo(ourClass) && !element.isEquivalentTo(clazz)) {
processStaticsOf((JSClass) element, processor, ourClass);
}
}
}
return qualifiedStaticVariantsStart;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlexUnitSupport method getCustomRunner.
/**
* @return [RunWith] metadata default attribute value. Can be <code>null</code>, empty string or whatever.
*/
@Nullable
public static String getCustomRunner(JSClass clazz) {
final JSAttribute[] attrs = clazz.getAttributeList().getAttributesByName(RUN_WITH_ATTRIBUTE);
if (attrs.length == 0)
return null;
final JSAttributeNameValuePair attr = attrs[0].getValueByName(null);
return attr == null ? null : attr.getSimpleValue();
}
Aggregations