use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeList in project intellij-plugins by JetBrains.
the class CreateFlexUnitTestDialog method createUIComponents.
private void createUIComponents() {
final Module module = ModuleUtil.findModuleForPsiElement(myContextClass);
assert module != null;
myPackageCombo = JSReferenceEditor.forPackageName(StringUtil.getPackageName(myContextClass.getQualifiedName()), module.getProject(), null, getTestClassPackageScope(module), RefactoringBundle.message("choose.destination.package"));
final Condition<JSClass> filter = jsClass -> {
final JSAttributeList attributeList = jsClass.getAttributeList();
return !jsClass.isInterface() && attributeList != null && !attributeList.hasModifier(JSAttributeList.ModifierType.FINAL);
};
mySuperClassField = JSReferenceEditor.forClassName("", module.getProject(), null, getSuperClassScope(module), null, filter, JSBundle.message("choose.super.class.title"));
final List<JSMemberInfo> memberInfos = new ArrayList<>();
JSMemberInfo.extractClassMembers(myContextClass, memberInfos, new MemberInfoBase.Filter<JSAttributeListOwner>() {
public boolean includeMember(final JSAttributeListOwner member) {
final JSAttributeList attributeList = member.getAttributeList();
return member instanceof JSFunction && ((JSFunction) member).getKind() != JSFunction.FunctionKind.CONSTRUCTOR && attributeList != null && attributeList.getAccessType() == JSAttributeList.AccessType.PUBLIC;
}
});
myMemberSelectionPanel = new JSMemberSelectionPanel("Generate test methods for:", memberInfos, null);
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeList in project intellij-plugins by JetBrains.
the class NodeClassInfo method getNodeClassInfo.
static NodeClassInfo getNodeClassInfo(@NotNull final JSClass jsClass) {
final JSAttributeList classAttributes = jsClass.getAttributeList();
final boolean dynamic = classAttributes != null && classAttributes.hasModifier(JSAttributeList.ModifierType.DYNAMIC);
final Map<String, Icon> ownStaticFields = new THashMap<>();
final Map<String, Icon> ownStaticProperties = new THashMap<>();
final Map<String, Icon> ownFields = new THashMap<>();
final Map<String, Icon> ownProperties = new THashMap<>();
final Map<String, Icon> inheritedStaticFields = new THashMap<>();
final Map<String, Icon> inheritedStaticProperties = new THashMap<>();
final Map<String, Icon> inheritedFields = new THashMap<>();
final Map<String, Icon> inheritedProperties = new THashMap<>();
fillMapsForClass(jsClass, ownStaticFields, ownStaticProperties, ownFields, ownProperties);
fillMapsForSupersRecursively(jsClass, new THashSet<>(), inheritedStaticFields, inheritedStaticProperties, inheritedFields, inheritedProperties);
return new NodeClassInfo(normalizeIfVector(jsClass.getQualifiedName()), dynamic, ownStaticFields, ownStaticProperties, ownFields, ownProperties, inheritedStaticFields, inheritedStaticProperties, inheritedFields, inheritedProperties);
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeList in project intellij-plugins by JetBrains.
the class NodeClassInfo method fillMapsForClass.
private static void fillMapsForClass(final JSClass jsClass, final Map<String, Icon> staticFields, final Map<String, Icon> staticProperties, final Map<String, Icon> fields, final Map<String, Icon> properties) {
for (final JSField variable : jsClass.getFields()) {
final JSAttributeList varAttributes = variable.getAttributeList();
if (varAttributes != null && varAttributes.hasModifier(JSAttributeList.ModifierType.STATIC)) {
staticFields.put(variable.getName(), variable.getIcon(Iconable.ICON_FLAG_VISIBILITY));
} else {
fields.put(variable.getName(), variable.getIcon(Iconable.ICON_FLAG_VISIBILITY));
}
}
for (final JSFunction function : jsClass.getFunctions()) {
if (function.getKind() == JSFunction.FunctionKind.GETTER && function.getName() != null) {
final JSAttributeList functionAttributes = function.getAttributeList();
if (functionAttributes != null && functionAttributes.hasModifier(JSAttributeList.ModifierType.STATIC)) {
staticProperties.put(function.getName(), function.getIcon(Iconable.ICON_FLAG_VISIBILITY));
} else {
properties.put(function.getName(), function.getIcon(Iconable.ICON_FLAG_VISIBILITY));
}
}
}
if (jsClass instanceof MxmlJSClass) {
final PsiFile file = jsClass.getContainingFile();
final XmlFile xmlFile = file instanceof XmlFile ? (XmlFile) file : null;
final XmlTag rootTag = xmlFile == null ? null : xmlFile.getRootTag();
if (rootTag != null) {
processSubtagsRecursively(rootTag, tag -> {
final String id = tag.getAttributeValue("id");
if (id != null) {
fields.put(id, tag.getIcon(Iconable.ICON_FLAG_VISIBILITY));
}
return !MxmlJSClass.isTagThatAllowsAnyXmlContent(tag);
});
}
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeList 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.JSAttributeList in project intellij-plugins by JetBrains.
the class FlexCompilationUtils method replaceMacros.
private static String replaceMacros(final String wrapperText, final String outputFileName, final String targetPlayer, @Nullable final JSClass mainClass) {
final Map<String, String> replacementMap = new THashMap<>();
replacementMap.put(FlexCommonUtils.SWF_MACRO, outputFileName);
replacementMap.put(FlexCommonUtils.TITLE_MACRO, outputFileName);
replacementMap.put(FlexCommonUtils.APPLICATION_MACRO, outputFileName);
replacementMap.put(FlexCommonUtils.BG_COLOR_MACRO, "#ffffff");
replacementMap.put(FlexCommonUtils.WIDTH_MACRO, "100%");
replacementMap.put(FlexCommonUtils.HEIGHT_MACRO, "100%");
final List<String> versionParts = StringUtil.split(targetPlayer, ".");
replacementMap.put(FlexCommonUtils.VERSION_MAJOR_MACRO, versionParts.size() >= 1 ? versionParts.get(0) : "0");
replacementMap.put(FlexCommonUtils.VERSION_MINOR_MACRO, versionParts.size() >= 2 ? versionParts.get(1) : "0");
replacementMap.put(FlexCommonUtils.VERSION_REVISION_MACRO, versionParts.size() >= 3 ? versionParts.get(2) : "0");
final Ref<JSAttribute> swfMetadataRef = new Ref<>();
final PsiFile psiFile = mainClass == null ? null : mainClass.getContainingFile();
if (psiFile instanceof XmlFile) {
final XmlTag rootTag = ((XmlFile) psiFile).getRootTag();
if (rootTag != null) {
final String ns = rootTag.getPrefixByNamespace(JavaScriptSupportLoader.MXML_URI3) == null ? JavaScriptSupportLoader.MXML_URI : JavaScriptSupportLoader.MXML_URI3;
for (XmlTag tag : rootTag.findSubTags(FlexPredefinedTagNames.METADATA, ns)) {
JSResolveUtil.processInjectedFileForTag(tag, new JSResolveUtil.JSInjectedFilesVisitor() {
@Override
protected void process(final JSFile file) {
for (PsiElement elt : file.getChildren()) {
if (elt instanceof JSAttributeList) {
final JSAttribute swfMetadata = ((JSAttributeList) elt).findAttributeByName("SWF");
if (swfMetadataRef.isNull() && swfMetadata != null) {
swfMetadataRef.set(swfMetadata);
return;
}
}
}
}
});
}
}
} else {
final JSAttributeList attributeList = mainClass == null ? null : mainClass.getAttributeList();
swfMetadataRef.set(attributeList == null ? null : attributeList.findAttributeByName("SWF"));
}
if (!swfMetadataRef.isNull()) {
final JSAttribute swfMetadata = swfMetadataRef.get();
final JSAttributeNameValuePair titleAttr = swfMetadata.getValueByName(FlexCommonUtils.TITLE_ATTR);
ContainerUtil.putIfNotNull(FlexCommonUtils.TITLE_MACRO, titleAttr == null ? null : titleAttr.getSimpleValue(), replacementMap);
final JSAttributeNameValuePair bgColorAttr = swfMetadata.getValueByName(FlexCommonUtils.BG_COLOR_ATTR);
ContainerUtil.putIfNotNull(FlexCommonUtils.BG_COLOR_MACRO, bgColorAttr == null ? null : bgColorAttr.getSimpleValue(), replacementMap);
final JSAttributeNameValuePair widthAttr = swfMetadata.getValueByName(FlexCommonUtils.WIDTH_ATTR);
ContainerUtil.putIfNotNull(FlexCommonUtils.WIDTH_MACRO, widthAttr == null ? null : widthAttr.getSimpleValue(), replacementMap);
final JSAttributeNameValuePair heightAttr = swfMetadata.getValueByName(FlexCommonUtils.HEIGHT_ATTR);
ContainerUtil.putIfNotNull(FlexCommonUtils.HEIGHT_MACRO, heightAttr == null ? null : heightAttr.getSimpleValue(), replacementMap);
}
return FlexCommonUtils.replace(wrapperText, replacementMap);
}
Aggregations