use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair in project intellij-plugins by JetBrains.
the class FlexFileReferenceHelper method registerFixes.
@NotNull
public List<? extends LocalQuickFix> registerFixes(final FileReference reference) {
final PsiElement element = reference.getElement();
if (!(reference instanceof JSFlexFileReference) || !(element instanceof JSAttributeNameValuePair))
return Collections.emptyList();
final PsiElement parent = element.getParent();
if (!(parent instanceof JSAttribute) || !FlexAnnotationNames.EMBED.equals(((JSAttribute) parent).getName())) {
return Collections.emptyList();
}
final String value = ((JSAttributeNameValuePair) element).getSimpleValue();
if (value.startsWith("/"))
return Collections.emptyList();
final Module module = ModuleUtil.findModuleForPsiElement(element);
if (module == null)
return Collections.emptyList();
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
final VirtualFile virtualFile = element.getContainingFile().getVirtualFile();
final boolean testSourceRoot = virtualFile != null && rootManager.getFileIndex().isInTestSourceContent(virtualFile);
for (VirtualFile sourceRoot : rootManager.getSourceRoots(testSourceRoot)) {
if (sourceRoot.findFileByRelativePath(value) != null) {
return Collections.singletonList(new AddLeadingSlashFix((JSAttributeNameValuePair) element));
}
}
return Collections.emptyList();
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair 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.JSAttributeNameValuePair 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());
}
Aggregations