use of com.intellij.lang.javascript.psi.ecmal4.JSAttribute in project intellij-plugins by JetBrains.
the class InjectedPsiVisitor method processEmbedDirective.
private ValueWriter processEmbedDirective(JSAttribute attribute) {
VirtualFile source = null;
String mimeType = null;
String symbol = null;
for (JSAttributeNameValuePair p : attribute.getValues()) {
final String name = p.getName();
if (name == null || name.equals("source")) {
try {
source = InjectionUtil.getReferencedFile(p);
} catch (InvalidPropertyException e) {
problemsHolder.add(e);
return InjectedASWriter.IGNORE;
}
} else if (name.equals("mimeType")) {
mimeType = p.getSimpleValue();
} else if (name.equals("symbol")) {
symbol = p.getSimpleValue();
}
}
if (source == null) {
problemsHolder.add(host, FlashUIDesignerBundle.message("embed.source.not.specified", host.getText()));
return InjectedASWriter.IGNORE;
}
if (InjectionUtil.isSwf(source, mimeType)) {
return new SwfValueWriter(source, symbol);
} else {
if (symbol != null) {
LOG.warn("Attribute symbol is unneeded for " + host.getText());
}
if (InjectionUtil.isImage(source, mimeType)) {
return new ImageValueWriter(source, mimeType);
} else {
problemsHolder.add(host, FlashUIDesignerBundle.message("unsupported.embed.asset.type", host.getText()));
return InjectedASWriter.IGNORE;
}
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttribute in project intellij-plugins by JetBrains.
the class InjectedPsiVisitor method processResourceDirective.
private ValueWriter processResourceDirective(JSAttribute attribute) {
String key = null;
PropertiesFile bundle = null;
for (JSAttributeNameValuePair p : attribute.getValues()) {
final String name = p.getName();
if ("key".equals(name)) {
key = p.getSimpleValue();
} else if ("bundle".equals(name)) {
try {
// IDEA-74868
final PsiFileSystemItem referencedPsiFile = InjectionUtil.getReferencedPsiFile(p);
if (referencedPsiFile instanceof PropertiesFile) {
bundle = (PropertiesFile) referencedPsiFile;
} else {
LOG.warn("skip resource directive, referenced file is not properties file " + host.getText());
}
} catch (InvalidPropertyException e) {
invalidPropertyException = e;
return InjectedASWriter.IGNORE;
}
}
}
if (key == null || key.isEmpty() || bundle == null) {
LOG.warn("skip resource directive, one of the required attributes is missed " + host.getText());
return InjectedASWriter.IGNORE;
}
final IProperty property = bundle.findPropertyByKey(key);
if (property == null) {
LOG.warn("skip resource directive, key not found " + host.getText());
return InjectedASWriter.IGNORE;
}
return new ResourceDirectiveValueWriter(property.getUnescapedValue());
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttribute in project intellij-plugins by JetBrains.
the class InjectedPsiVisitor method checkCompilerDirective.
private ValueWriter checkCompilerDirective(JSFile jsFile) {
PsiElement firstChild = jsFile.getFirstChild();
if (firstChild instanceof LeafPsiElement && ((LeafPsiElement) firstChild).getElementType() == JSTokenTypes.AT) {
JSAttribute attribute = (JSAttribute) firstChild.getNextSibling();
assert attribute != null;
final String attributeName = attribute.getName();
if (FlexAnnotationNames.EMBED.equals(attributeName)) {
return processEmbedDirective(attribute);
} else if (FlexAnnotationNames.RESOURCE.equals(attributeName)) {
return processResourceDirective(attribute);
} else {
if (!StringUtil.isEmpty(attributeName)) {
problemsHolder.add(host, FlashUIDesignerBundle.message("unsupported.compiler.directive", host.getText()));
}
return InjectedASWriter.IGNORE;
}
}
return null;
}
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);
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttribute 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