use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class AntReferenceInjector method inject.
@NotNull
public PsiReference[] inject(@Nullable String unresolvedText, @NotNull PsiElement element, @NotNull ConvertContext context) {
if (element instanceof XmlAttributeValue) {
final XmlAttributeValue xmlAttributeValue = (XmlAttributeValue) element;
final List<PsiReference> refs = PsiReferenceListSpinAllocator.alloc();
try {
addPropertyReferences(context, xmlAttributeValue, refs);
addMacrodefParameterRefs(xmlAttributeValue, refs);
return refs.size() == 0 ? PsiReference.EMPTY_ARRAY : ContainerUtil.toArray(refs, new PsiReference[refs.size()]);
} finally {
PsiReferenceListSpinAllocator.dispose(refs);
}
}
return PsiReference.EMPTY_ARRAY;
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class InspectionDescriptionInfo method doFindExtension.
@Nullable
private static Extension doFindExtension(Module module, PsiClass psiClass) {
// Try search in narrow scopes first
Project project = module.getProject();
Set<DomFileElement<IdeaPlugin>> processed = new HashSet<>();
for (GlobalSearchScope scope : DescriptionCheckerUtil.searchScopes(module)) {
List<DomFileElement<IdeaPlugin>> origElements = DomService.getInstance().getFileElements(IdeaPlugin.class, project, scope);
origElements.removeAll(processed);
List<DomFileElement<IdeaPlugin>> elements = PluginDescriptorChooser.findAppropriateIntelliJModule(module.getName(), origElements);
Query<PsiReference> query = ReferencesSearch.search(psiClass, new LocalSearchScope(elements.stream().map(DomFileElement::getFile).toArray(PsiElement[]::new)));
Ref<Extension> result = Ref.create(null);
query.forEach(ref -> {
PsiElement element = ref.getElement();
if (element instanceof XmlAttributeValue) {
PsiElement parent = element.getParent();
if (parent instanceof XmlAttribute && "implementationClass".equals(((XmlAttribute) parent).getName())) {
DomElement domElement = DomUtil.getDomElement(parent.getParent());
if (domElement instanceof Extension) {
Extension extension = (Extension) domElement;
ExtensionPoint extensionPoint = extension.getExtensionPoint();
if (extensionPoint != null && InheritanceUtil.isInheritor(extensionPoint.getBeanClass().getValue(), InspectionEP.class.getName())) {
result.set(extension);
return false;
}
}
}
}
return true;
});
Extension extension = result.get();
if (extension != null)
return extension;
processed.addAll(origElements);
}
return null;
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class ResolveUtil method resolveFile.
@Nullable
public static PsiFile resolveFile(XmlAttribute location, PsiFile baseFile) {
if (location == null)
return null;
final XmlAttributeValue valueElement = location.getValueElement();
if (valueElement == null)
return null;
// prefer direct relative path
final String value = valueElement.getValue();
final PsiFile file = resolveFile(value, baseFile);
if (file != baseFile && file instanceof XmlFile) {
return file;
}
final PsiReference[] references = valueElement.getReferences();
for (PsiReference reference : references) {
final PsiElement target = reference.resolve();
if (target == null && reference instanceof PsiPolyVariantReference) {
final ResolveResult[] results = ((PsiPolyVariantReference) reference).multiResolve(false);
for (ResolveResult result : results) {
if (result.isValidResult()) {
// TODO: how to weigh/prioritize the results?
final PsiElement element = result.getElement();
if (element != baseFile && element instanceof XmlFile) {
return (PsiFile) target;
}
}
}
} else if (target != baseFile && target instanceof XmlFile) {
return (PsiFile) target;
}
}
return null;
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class TemplateInvocationInspection method checkTemplateInvocation.
private static void checkTemplateInvocation(XsltTemplateInvocation call, ProblemsHolder holder, boolean onTheFly) {
final XsltWithParam[] arguments = call.getArguments();
final Map<String, XsltWithParam> argNames = new HashMap<>();
for (XsltWithParam arg : arguments) {
final XmlAttribute attr = arg.getNameAttribute();
if (attr != null) {
final String name = attr.getValue();
if (argNames.containsKey(name)) {
final PsiElement token = arg.getNameIdentifier();
assert token != null;
holder.registerProblem(token, "Duplicate Argument '" + name + "'");
}
argNames.put(name, arg);
}
}
if (call instanceof XsltCallTemplate) {
final XsltCallTemplate ct = ((XsltCallTemplate) call);
final PsiElement nameToken = ct.getNameIdentifier();
final XsltTemplate template = ct.getTemplate();
if (template != null) {
if (nameToken != null) {
final XsltParameter[] parameters = template.getParameters();
for (XsltParameter parameter : parameters) {
if (!argNames.containsKey(parameter.getName()) && !parameter.hasDefault()) {
final LocalQuickFix fix = new AddWithParamFix(parameter, call.getTag()).createQuickFix(onTheFly);
holder.registerProblem(nameToken, "Missing template parameter: " + parameter.getName(), AbstractFix.createFixes(fix));
}
}
}
for (String s : argNames.keySet()) {
final XmlAttribute argAttribute = argNames.get(s).getNameAttribute();
assert argAttribute != null;
final XmlAttributeValue valueElement = argAttribute.getValueElement();
final PsiElement valueToken = XsltSupport.getAttValueToken(argAttribute);
if (valueToken != null && s.trim().length() > 0) {
if (template.getParameter(s) == null) {
final LocalQuickFix fix1 = new AddParameterFix(s, template).createQuickFix(onTheFly);
final LocalQuickFix fix2 = new RemoveParamFix(argNames.get(s).getTag(), s).createQuickFix(onTheFly);
holder.registerProblem(valueToken, "Undeclared template parameter: " + s, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, AbstractFix.createFixes(fix1, fix2));
}
} else if (valueElement != null) {
holder.registerProblem(valueElement, "Parameter name expected");
}
}
}
}
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class PropertiesReferenceProvider method getReferencesByElement.
@NotNull
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
Object value = null;
String bundleName = null;
boolean propertyRefWithPrefix = false;
boolean soft = myDefaultSoft;
if (element instanceof PsiLiteralExpression) {
PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
value = literalExpression.getValue();
final Map<String, Object> annotationParams = new HashMap<>();
annotationParams.put(AnnotationUtil.PROPERTY_KEY_RESOURCE_BUNDLE_PARAMETER, null);
if (JavaI18nUtil.mustBePropertyKey(literalExpression, annotationParams)) {
soft = false;
final Object resourceBundleName = annotationParams.get(AnnotationUtil.PROPERTY_KEY_RESOURCE_BUNDLE_PARAMETER);
if (resourceBundleName instanceof PsiExpression) {
PsiExpression expr = (PsiExpression) resourceBundleName;
final Object bundleValue = JavaPsiFacade.getInstance(expr.getProject()).getConstantEvaluationHelper().computeConstantExpression(expr);
bundleName = bundleValue == null ? null : bundleValue.toString();
}
}
} else if (element instanceof XmlAttributeValue && isNonDynamicAttribute(element)) {
if (element.getTextLength() < 2) {
return PsiReference.EMPTY_ARRAY;
}
value = ((XmlAttributeValue) element).getValue();
final XmlAttribute attribute = (XmlAttribute) element.getParent();
if ("key".equals(attribute.getName())) {
final XmlTag parent = attribute.getParent();
if ("message".equals(parent.getLocalName()) && Arrays.binarySearch(XmlUtil.JSTL_FORMAT_URIS, parent.getNamespace()) >= 0) {
propertyRefWithPrefix = true;
}
}
}
if (value instanceof String) {
String text = (String) value;
PsiReference reference = propertyRefWithPrefix ? new PrefixBasedPropertyReference(text, element, null, soft) : new PropertyReference(text, element, bundleName, soft);
return new PsiReference[] { reference };
}
return PsiReference.EMPTY_ARRAY;
}
Aggregations