use of com.intellij.lang.properties.references.PropertyReference in project intellij-community by JetBrains.
the class PropertiesReferenceProvider method getReferencesByElement.
@Override
@NotNull
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
Object value = null;
if (element instanceof GrLiteral) {
GrLiteral literalExpression = (GrLiteral) element;
value = literalExpression.getValue();
//final Map<String, Object> annotationParams = new HashMap<String, Object>();
//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 = expr.getManager().getConstantEvaluationHelper().computeConstantExpression(expr);
bundleName = bundleValue == null ? null : bundleValue.toString();
}
}*/
}
if (value instanceof String && !((String) value).contains("\n")) {
return new PsiReference[] { new PropertyReference((String) value, element, null, true) };
}
return PsiReference.EMPTY_ARRAY;
}
use of com.intellij.lang.properties.references.PropertyReference 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