use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair 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.JSAttributeNameValuePair in project intellij-plugins by JetBrains.
the class ActionScriptAnnotatingVisitor method visitJSAttributeNameValuePair.
@Override
public void visitJSAttributeNameValuePair(@NotNull final JSAttributeNameValuePair attributeNameValuePair) {
final boolean ok = checkReferences(attributeNameValuePair);
if (!ok)
return;
// check if attribute value must be FQN of a class class inherited from some other class
if (attributeNameValuePair.getValueNode() == null)
return;
final PsiElement parent = attributeNameValuePair.getParent();
final XmlElementDescriptor descriptor = parent instanceof JSAttributeImpl ? ((JSAttributeImpl) parent).getBackedDescriptor() : null;
final String attributeName = StringUtil.notNullize(attributeNameValuePair.getName(), JSAttributeNameValuePair.DEFAULT);
final XmlAttributeDescriptor attributeDescriptor = descriptor == null ? null : descriptor.getAttributeDescriptor(attributeName, null);
final String baseClassFqns = attributeDescriptor == null ? null : attributeDescriptor.getDefaultValue();
if (baseClassFqns != null && !StringUtil.isEmptyOrSpaces(baseClassFqns)) {
final PsiReference[] references = attributeNameValuePair.getReferences();
PsiReference lastReference = references.length > 0 ? references[0] : null;
for (final PsiReference reference : references) {
if (reference.getRangeInElement().getEndOffset() > lastReference.getRangeInElement().getEndOffset()) {
lastReference = reference;
}
}
final PsiElement resolved = lastReference != null ? lastReference.resolve() : null;
if (resolved instanceof JSClass) {
boolean correctClass = false;
final Collection<String> resolvedBaseClasses = new ArrayList<>();
final GlobalSearchScope scope = JSResolveUtil.getResolveScope(attributeNameValuePair);
for (String baseClassFqn : StringUtil.split(baseClassFqns, ",")) {
if ("Object".equals(baseClassFqn)) {
correctClass = true;
break;
}
final PsiElement baseClass = ActionScriptClassResolver.findClassByQNameStatic(baseClassFqn, attributeNameValuePair);
if (baseClass instanceof JSClass) {
resolvedBaseClasses.add(baseClassFqn);
if (JSInheritanceUtil.isParentClass((JSClass) resolved, (JSClass) baseClass, false, scope)) {
correctClass = true;
break;
}
}
}
if (!correctClass) {
final String classesForMessage = resolvedBaseClasses.isEmpty() ? StringUtil.replace(baseClassFqns, ",", ", ") : StringUtil.join(resolvedBaseClasses, ", ");
myHolder.createErrorAnnotation(calcRangeForReferences(lastReference), JSBundle.message("javascript.expected.class.or.descendant", classesForMessage));
}
} else if (resolved != attributeNameValuePair) {
// for some reason int and uint are resolved to self-reference JSResolveUtil.MyResolveResult() instead of usual JSClass
myHolder.createErrorAnnotation(attributeNameValuePair.getValueNode(), JSBundle.message("javascript.qualified.class.name.expected"));
}
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair in project intellij-plugins by JetBrains.
the class FlexCssPropertyDescriptor method findStyleAttributesInClassOrSuper.
private boolean findStyleAttributesInClassOrSuper(@NotNull JSClass c, @NotNull Set<JSClass> visited, @NotNull Map<PsiElement, PairInfo> navElement2pair) {
if (!visited.add(c))
return false;
JSAttributeNameValuePair result = null;
String qName = c.getQualifiedName();
if (myClassNames.contains(qName) || checkIncludes(c)) {
MyMetaDataProcessor processor = new MyMetaDataProcessor();
FlexUtils.processMetaAttributesForClass(c, processor);
result = processor.myResult;
}
PsiElement navElement = result != null ? result.getNavigationElement() : null;
if (result == null || navElement == null) {
boolean found = false;
for (JSClass superClass : c.getSupers()) {
found = found || findStyleAttributesInClassOrSuper(superClass, visited, navElement2pair);
}
if (found)
return true;
}
if (result != null) {
navElement2pair.put(navElement != null ? navElement : result, new PairInfo(result, qName));
return true;
}
return false;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair in project intellij-plugins by JetBrains.
the class FlexCssPropertyDescriptor method findStyleAttributesInFile.
private boolean findStyleAttributesInFile(@NotNull JSFile jsFile, @NotNull Set<JSFile> visited, @NotNull Map<PsiElement, PairInfo> navElement2pair) {
if (!visited.add(jsFile))
return false;
JSAttributeNameValuePair result = null;
String fileName = jsFile.getName();
if (myFileNames.contains(fileName)) {
MyMetaDataProcessor processor = new MyMetaDataProcessor();
FlexUtils.processMetaAttributesForClass(jsFile, processor);
result = processor.myResult;
}
PsiElement navElement = result != null ? result.getNavigationElement() : null;
if (result != null) {
navElement2pair.put(navElement != null ? navElement : result, new PairInfo(result, fileName));
return true;
}
return false;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair 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