use of com.intellij.struts2.dom.params.ParamsElement 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.dom.params.ParamsElement in project intellij-plugins by JetBrains.
the class Struts2ModelInspection method shouldCheckResolveProblems.
protected boolean shouldCheckResolveProblems(final GenericDomValue value) {
final Converter converter = value.getConverter();
// we roll our own checking for "class" in Struts2ModelInspectionVisitor
if (converter instanceof ExtendableClassConverter) {
return false;
}
// hack for STRPL-85: suppress <param>-highlighting within <result> for certain result-types
if (converter instanceof ParamNameConverter) {
final Result result = DomUtil.getParentOfType(value, Result.class, false);
if (result != null) {
final ResultType resultType = result.getEffectiveResultType();
if (resultType == null) {
// error
return false;
}
final String resultTypeValue = resultType.getName().getStringValue();
if (resultTypeValue != null && ResultTypeResolver.isChainOrRedirectType(resultTypeValue)) {
return false;
}
}
}
final String stringValue = value.getStringValue();
// suppress <action> "method" when using wildcards
if (converter instanceof ActionMethodConverter && ConverterUtil.hasWildcardReference(stringValue)) {
return false;
}
// suppress <result> path
if (converter instanceof StrutsPathReferenceConverter) {
if (stringValue == null) {
return false;
}
// nested <param>-tags are present
if (!((ParamsElement) value).getParams().isEmpty()) {
return false;
}
// unsupported result-type
final ResultType resultType = ((HasResultType) value).getEffectiveResultType();
if (resultType == null) {
return false;
}
if (!ResultTypeResolver.hasResultTypeContributor(resultType.getName().getStringValue())) {
return false;
}
// suppress paths with wildcard reference
if (ConverterUtil.hasWildcardReference(stringValue)) {
final Action action = DomUtil.getParentOfType(value, Action.class, true);
return action != null && !action.isWildcardMapping();
}
// "${actionProperty}"
if (StringUtil.startsWith(stringValue, "${")) {
return false;
}
// global URLs
if (URLUtil.containsScheme(stringValue)) {
return false;
}
}
return true;
}
use of com.intellij.struts2.dom.params.ParamsElement 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.dom.params.ParamsElement in project intellij-plugins by JetBrains.
the class ResultParamNameCustomConverter method getCustomReferences.
@NotNull
@Override
public PsiReference[] getCustomReferences(XmlAttributeValue nameAttributeValue, DomElement paramsElement) {
if (!(paramsElement instanceof Result)) {
return PsiReference.EMPTY_ARRAY;
}
Result result = (Result) paramsElement;
Action action = DomUtil.getParentOfType(result, Action.class, true);
assert action != null;
return new PsiReference[] { new MergingBeanPropertyPathReference(nameAttributeValue, action, result) };
}
Aggregations