use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class FlexUndefinedElementFixProvider method createFixes.
@Nullable
@Override
public IntentionAction[] createFixes(@NotNull XmlAttribute attribute) {
if (!JavaScriptSupportLoader.isFlexMxmFile(attribute.getContainingFile()))
return null;
final String name = attribute.getName();
if (!JSRefactoringUtil.isValidIdentifier(name, attribute.getProject())) {
return IntentionAction.EMPTY_ARRAY;
}
final XmlElementDescriptor descriptor = attribute.getParent().getDescriptor();
final PsiElement declaration = descriptor instanceof ClassBackedElementDescriptor ? descriptor.getDeclaration() : null;
final VirtualFile virtualFile = declaration == null ? null : declaration.getContainingFile().getVirtualFile();
if (virtualFile == null || ProjectRootManager.getInstance(declaration.getProject()).getFileIndex().getSourceRootForFile(virtualFile) == null) {
return IntentionAction.EMPTY_ARRAY;
}
if (declaration instanceof JSClass || declaration instanceof XmlFile && JavaScriptSupportLoader.isFlexMxmFile((XmlFile) declaration)) {
final String attributeValue = attribute.getValue();
final FixAndIntentionAction fix1 = new CreateFieldByMxmlAttributeFix(name, attributeValue);
fix1.registerElementRefForFix(attribute, null);
final FixAndIntentionAction fix2 = new CreateSetterByMxmlAttributeFix(name, attributeValue);
fix2.registerElementRefForFix(attribute, null);
final FixAndIntentionAction fix3 = new CreateEventMetadataByMxmlAttributeFix(name);
fix3.registerElementRefForFix(attribute, null);
return new IntentionAction[] { fix1, fix2, fix3 };
}
return IntentionAction.EMPTY_ARRAY;
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class FlexMxmlNSDescriptor method getRootElementsDescriptors.
@NotNull
public XmlElementDescriptor[] getRootElementsDescriptors(@Nullable final XmlDocument document) {
XmlElementDescriptor[] elementDescriptors = CodeContext.getContext(namespace, module).getDescriptorsWithAllowedDeclaration();
ArrayList<XmlElementDescriptor> results = new ArrayList<>(elementDescriptors.length);
final XmlTag rootTag = document == null ? null : document.getRootTag();
// sorry for this hacky way to determine if this is root tag name completion or not
final boolean isRootTagCompletion = rootTag != null && rootTag.getName().endsWith(CompletionInitializationContext.DUMMY_IDENTIFIER_TRIMMED);
for (XmlElementDescriptor elementDescriptor : elementDescriptors) {
if (isRootTagCompletion) {
if (!isLegalRootElementDescriptor(elementDescriptor)) {
continue;
}
if (elementDescriptor instanceof MxmlBackedElementDescriptor) {
final PsiElement declaration = elementDescriptor.getDeclaration();
final PsiFile containingFile = document.getContainingFile();
if (declaration != null && containingFile != null && declaration.equals(containingFile.getOriginalFile())) {
// do not suggest root tag referencing to this mxml file itself
continue;
}
}
}
String name = elementDescriptor.getName();
if (name.length() > 0)
/*&& Character.isUpperCase(name.charAt(0))*/
results.add(elementDescriptor);
}
return results.toArray(new XmlElementDescriptor[results.size()]);
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class FlexMxmlNSDescriptor method hasElementDescriptorWithName.
public boolean hasElementDescriptorWithName(String name, String className) {
final CodeContext context = CodeContext.getContext(namespace, module);
XmlElementDescriptor descriptor = context.getElementDescriptor(name, (XmlTag) null);
if (descriptor instanceof ClassBackedElementDescriptor) {
return ((ClassBackedElementDescriptor) descriptor).className.equals(className);
}
return false;
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class FlexAttributeReferenceProvider method valueRefs.
public static PsiReference[] valueRefs(JSAttributeNameValuePairImpl element, String name) {
final JSAttributeImpl jsAttribute = (JSAttributeImpl) element.getParent();
final XmlElementDescriptor descriptor = jsAttribute.getBackedDescriptor();
final XmlAttributeDescriptor attributeDescriptor = descriptor == null ? null : descriptor.getAttributeDescriptor(StringUtil.notNullize(name, JSAttributeNameValuePair.DEFAULT), null);
if (name == null) {
return getDefaultPropertyRefs(element, attributeDescriptor);
}
final String baseClassFqns = attributeDescriptor == null ? null : attributeDescriptor.getDefaultValue();
if (baseClassFqns != null) {
return getClassRefs(element, baseClassFqns);
} else if ("source".equals(name)) {
return getPathRefsCheckingParent(element);
} else if ("key".equals(name)) {
return getPropertyRefsCheckingParent(element);
} else if (BUNDLE_ATTR_NAME.equals(name)) {
return getBundleRefsCheckingParent(element);
} else if (attributeDescriptor != null && attributeDescriptor.isEnumerated()) {
final String[] enumeratedValues = attributeDescriptor.getEnumeratedValues();
final TextRange range = getValueRange(element);
if (enumeratedValues != null && enumeratedValues.length > 0 && range != null) {
return new PsiReference[] { new EnumeratedAttributeValueReference(element, range, enumeratedValues) };
}
}
return PsiReference.EMPTY_ARRAY;
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class FlexCssElementDescriptorProvider method getSimpleSelectors.
@NotNull
public String[] getSimpleSelectors(@NotNull PsiElement context) {
Module module = findModuleForPsiElement(context);
if (module == null) {
return ArrayUtil.EMPTY_STRING_ARRAY;
}
CodeContext codeContext = CodeContext.getContext(JavaScriptSupportLoader.MXML_URI, module);
XmlElementDescriptor[] descriptors = codeContext.getDescriptorsWithAllowedDeclaration();
String[] selectors = new String[descriptors.length + 1];
selectors[0] = "global";
int i = 1;
for (XmlElementDescriptor descriptor : descriptors) {
selectors[i++] = descriptor.getName();
}
return selectors;
}
Aggregations