@Nullable private static Property getPropertyArgument(PsiMethodCallExpression arg) { PsiExpression[] args = arg.getArgumentList().getExpressions(); if (args.length > 0) { PsiReference[] references = args[0].getReferences(); for (PsiReference reference : references) { if (reference instanceof PropertyReference) { ResolveResult[] resolveResults = ((PropertyReference)reference).multiResolve(false); if (resolveResults.length == 1 && resolveResults[0].isValidResult()) { PsiElement element = resolveResults[0].getElement(); if (element instanceof Property) { return (Property) element; } } } } } return null; }
@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; }
@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; }
public boolean canInlineElement(PsiElement element) { if (element instanceof PsiJavaToken && ((PsiJavaToken)element).getTokenType() == JavaTokenType.STRING_LITERAL) { PsiReference[] references = element.getParent().getReferences(); return ContainerUtil.find(references, FilteringIterator.instanceOf(PropertyReference.class)) != null; } return element instanceof IProperty; }
@NotNull public PsiReference[] getReferences() { if (isFileReference()) { return PsiUtil.getFileReferences(getValueText(), this, getFirstChild().getTextLength(), true); } if (isPropertyReference()) { return new PsiReference[]{new PropertyReference(getValueText(), this, null, true)}; } return PsiReference.EMPTY_ARRAY; }
@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<String, Object>(); annotationParams.put(AnnotationUtil.PROPERTY_KEY_RESOURCE_BUNDLE_PARAMETER, null); if (JavaI18nUtil.mustBePropertyKey(element.getProject(), 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, bundleName, soft): new PropertyReference(text, element, bundleName, soft); return new PsiReference[]{reference}; } return PsiReference.EMPTY_ARRAY; }
public void testPropertyReference() throws Throwable { PsiReference ref = myFixture.getReferenceAtCaretPosition(Util.getInputDataFileName(getTestName(true))); assertInstanceOf(ref, PropertyReference.class); }
public void testPropertyReferenceDoublequoted() throws Throwable { PsiReference ref = myFixture.getReferenceAtCaretPosition(Util.getInputDataFileName(getTestName(true))); assertInstanceOf(ref, PropertyReference.class); }