use of com.intellij.lang.javascript.psi.ecmal4.JSAttribute 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.JSAttribute 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();
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttribute in project intellij-plugins by JetBrains.
the class ActionScriptGenerateEventHandler method getEventType.
@Nullable
public static String getEventType(final XmlAttribute xmlAttribute) {
final XmlAttributeDescriptor descriptor = xmlAttribute == null ? null : xmlAttribute.getDescriptor();
final PsiElement declaration = descriptor instanceof AnnotationBackedDescriptor ? descriptor.getDeclaration() : null;
final PsiElement declarationParent = declaration == null ? null : declaration.getParent();
if (declaration instanceof JSAttributeNameValuePair && (((JSAttributeNameValuePair) declaration).getName() == null || "name".equals(((JSAttributeNameValuePair) declaration).getName())) && declarationParent instanceof JSAttribute && "Event".equals(((JSAttribute) declarationParent).getName())) {
return ((AnnotationBackedDescriptor) descriptor).getType();
}
return null;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttribute in project intellij-plugins by JetBrains.
the class MyImplicitUsageProvider method isImplicitUsage.
@Override
public boolean isImplicitUsage(PsiElement element) {
if (!(element instanceof JSFunction)) {
return false;
}
final JSFunction method = (JSFunction) element;
final String methodName = method.getName();
if (methodName == null || !Character.isUpperCase(methodName.charAt(0)) || !(method.getParent() instanceof JSClass) || method.getParent() instanceof XmlBackedJSClassImpl) {
return false;
}
final JSClass clazz = (JSClass) method.getParent();
if (!ActionScriptClassResolver.isParentClass(clazz, "com.intellij.flex.uiDesigner.TestCase")) {
return false;
}
final JSAttributeList attributeList = method.getAttributeList();
if (attributeList == null || attributeList.getAccessType() != JSAttributeList.AccessType.PUBLIC) {
return false;
}
final VirtualFile projectBaseDir = element.getProject().getBaseDir();
if (projectBaseDir == null) {
return false;
}
File testSourcePath = new File(projectBaseDir.getPath(), RELATIVE_TEST_DATA_PATH);
if (!testSourcePath.exists()) {
testSourcePath = new File(projectBaseDir.getPath(), "flex/tools/flex-ui-designer/" + RELATIVE_TEST_DATA_PATH);
assert testSourcePath.exists();
}
final JSAttributeList classAttributeList = clazz.getAttributeList();
if (classAttributeList != null) {
final JSAttribute testAnnotation = classAttributeList.findAttributeByName("Test");
if (testAnnotation == null) {
return false;
}
return new File(testSourcePath, testAnnotation.getValueByName("dir").getSimpleValue() + File.separatorChar + methodName + ".mxml").exists();
}
return false;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttribute in project intellij-plugins by JetBrains.
the class FlexAttributeReferenceProvider method getBundleRefsCheckingParent.
private static PsiReference[] getBundleRefsCheckingParent(JSAttributeNameValuePairImpl element) {
JSAttribute attribute = (JSAttribute) element.getParent();
@NonNls final String parentName = attribute.getName();
if (!FlexAnnotationNames.RESOURCE.equals(parentName))
return PsiReference.EMPTY_ARRAY;
return FlexPropertiesSupport.getResourceBundleReference(element, ourBundleInfoProvider);
}
Aggregations