Search in sources :

Example 1 with PropertyReference

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;
}
Also used : PropertyReference(com.intellij.lang.properties.references.PropertyReference) PsiReference(com.intellij.psi.PsiReference) GrLiteral(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PropertyReference

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;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) HashMap(java.util.HashMap) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) PropertyReference(com.intellij.lang.properties.references.PropertyReference) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PropertyReference (com.intellij.lang.properties.references.PropertyReference)2 NotNull (org.jetbrains.annotations.NotNull)2 PsiReference (com.intellij.psi.PsiReference)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)1 XmlTag (com.intellij.psi.xml.XmlTag)1 HashMap (java.util.HashMap)1 GrLiteral (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral)1