use of com.intellij.struts2.reference.common.BeanPropertyPathReferenceSet in project intellij-plugins by JetBrains.
the class InterceptorRefInStackParamNameCustomConverter method getCustomReferences.
@NotNull
@Override
public PsiReference[] getCustomReferences(final XmlAttributeValue nameAttributeValue, final DomElement paramsElement) {
if (!(paramsElement instanceof InterceptorRef)) {
return PsiReference.EMPTY_ARRAY;
}
InterceptorRef interceptorRef = (InterceptorRef) paramsElement;
final InterceptorOrStackBase value = interceptorRef.getName().getValue();
if (!(value instanceof InterceptorStack)) {
return PsiReference.EMPTY_ARRAY;
}
final String text = nameAttributeValue.getValue();
final boolean hasDot = StringUtil.containsChar(text, '.');
final int idx = hasDot ? text.indexOf('.') : text.length();
final String refName = text.substring(0, idx);
final InterceptorStack stack = (InterceptorStack) value;
final InterceptorRef resolvedInterceptorRef = ContainerUtil.find(stack.getInterceptorRefs(), ref -> Comparing.strEqual(refName, ref.getName().getStringValue()));
final List<PsiReference> customReferences = new ArrayList<>(2);
customReferences.add(new InterceptorRefPsiReference(nameAttributeValue, TextRange.from(1, idx), resolvedInterceptorRef, stack));
if (resolvedInterceptorRef == null) {
return ArrayUtil.toObjectArray(customReferences, PsiReference.class);
}
final String propertyText = text.substring(idx + 1, text.length());
final PsiClass paramsClass = resolvedInterceptorRef.getParamsClass();
final BeanPropertyPathReferenceSet beanPropertyPathReferenceSet = new BeanPropertyPathReferenceSet(propertyText, nameAttributeValue, idx + 2, '.', paramsClass, false);
Collections.addAll(customReferences, beanPropertyPathReferenceSet.getPsiReferences());
return ArrayUtil.toObjectArray(customReferences, PsiReference.class);
}
use of com.intellij.struts2.reference.common.BeanPropertyPathReferenceSet in project intellij-plugins by JetBrains.
the class ResultActionPropertyReferenceProvider method getReferencesByElement.
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull final PsiElement psiElement, @NotNull final ProcessingContext processingContext) {
final Result result = (Result) DomUtil.getDomElement(psiElement);
assert result != null : psiElement.getText();
final Action action = result.getParentOfType(Action.class, true);
assert action != null : psiElement.getText();
final PsiClass actionClass = action.searchActionClass();
if (actionClass == null) {
return PsiReference.EMPTY_ARRAY;
}
final int tagValueStartOffset = ElementManipulators.getOffsetInElement(result.getXmlTag());
PsiReference[] references = new PsiReference[1];
final String stringValue = result.getStringValue();
if (!StringUtil.isNotEmpty(stringValue)) {
return PsiReference.EMPTY_ARRAY;
}
final String resultText = StringUtil.replace(stringValue, "&", "&");
final int lastExpressionEnd = // missing '}'
Math.max(// missing '}'
resultText.length(), resultText.lastIndexOf(EXPRESSION_START));
int startOffset = 0;
while (startOffset < lastExpressionEnd) {
startOffset = resultText.indexOf(EXPRESSION_START, startOffset);
if (startOffset == -1) {
break;
}
startOffset += EXPRESSION_START.length();
final int closingBraceIdx = resultText.indexOf(EXPRESSION_END, startOffset);
final int length = (closingBraceIdx != -1 ? closingBraceIdx : resultText.length()) - startOffset;
final String expressionString = resultText.substring(startOffset, startOffset + length);
// we only "fake" OGNL here, skip method call expressions for now
if (StringUtil.containsChar(expressionString, '(')) {
continue;
}
final BeanPropertyPathReferenceSet propertyPathReferenceSet = new BeanPropertyPathReferenceSet(expressionString, psiElement, startOffset, '.', actionClass, true) {
// CTOR creates references eagerly, so we have to subclass here
@Override
public boolean isSoft() {
return false;
}
@NotNull
@Override
protected BeanPropertyPathReference createReference(final TextRange range, final int index) {
final TextRange shift = TextRange.from(range.getStartOffset() + tagValueStartOffset, // shift range to XmlTag value range
range.getLength());
return createBeanPropertyPathReference(shift, index);
}
};
references = ArrayUtil.mergeArrays(references, propertyPathReferenceSet.getPsiReferences());
}
return references;
}
use of com.intellij.struts2.reference.common.BeanPropertyPathReferenceSet in project intellij-plugins by JetBrains.
the class ParamNameConverterImpl method createReferences.
@NotNull
public PsiReference[] createReferences(final GenericDomValue<List<BeanProperty>> listGenericDomValue, final PsiElement psiElement, final ConvertContext convertContext) {
final DomElement paramsElement = findEnclosingTag(convertContext);
if (paramsElement == null) {
return PsiReference.EMPTY_ARRAY;
}
for (ParamNameCustomConverter customConverter : Extensions.getExtensions(EP_NAME)) {
final PsiReference[] customReferences = customConverter.getCustomReferences((XmlAttributeValue) psiElement, paramsElement);
if (customReferences.length > 0) {
return customReferences;
}
}
final PsiClass rootPsiClass = findBeanPropertyClass(paramsElement);
return new BeanPropertyPathReferenceSet(psiElement, rootPsiClass, false).getPsiReferences();
}
use of com.intellij.struts2.reference.common.BeanPropertyPathReferenceSet in project intellij-plugins by JetBrains.
the class ActionPropertyReferenceProvider method getReferencesByElement.
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull final PsiElement psiElement, @NotNull final ProcessingContext processingContext) {
if (TaglibUtil.isDynamicExpression(((XmlAttributeValue) psiElement).getValue())) {
return PsiReference.EMPTY_ARRAY;
}
final XmlTag tag = PsiTreeUtil.getParentOfType(psiElement, XmlTag.class);
assert tag != null;
final XmlTag actionTag = findEnclosingTag(tag, tag.getNamespacePrefix());
if (actionTag == null) {
return PsiReference.EMPTY_ARRAY;
}
final String actionName = Comparing.equal(actionTag.getLocalName(), "action") ? actionTag.getAttributeValue("name") : actionTag.getAttributeValue("action");
if (actionName == null || TaglibUtil.isDynamicExpression(actionName)) {
return PsiReference.EMPTY_ARRAY;
}
final StrutsManager strutsManager = StrutsManager.getInstance(psiElement.getProject());
final StrutsModel strutsModel = strutsManager.getCombinedModel(psiElement);
if (strutsModel == null) {
return PsiReference.EMPTY_ARRAY;
}
final List<Action> actions = strutsModel.findActionsByName(actionName, actionTag.getAttributeValue("namespace"));
if (actions.size() != 1) {
return PsiReference.EMPTY_ARRAY;
}
final Action action = actions.get(0);
return new BeanPropertyPathReferenceSet(psiElement, action.searchActionClass(), supportsReadOnlyProperties) {
// TODO CTOR creates references eagerly, so we have to subclass here
@Override
public boolean isSoft() {
return false;
}
}.getPsiReferences();
}
Aggregations