use of com.intellij.struts2.dom.struts.strutspackage.ResultType in project intellij-plugins by JetBrains.
the class ResultTypeResolvingConverterImpl method fromString.
public ResultType fromString(@Nullable @NonNls final String name, final ConvertContext context) {
if (StringUtil.isEmpty(name)) {
return null;
}
final Condition<ResultType> nameCondition = resultType -> Comparing.equal(name, resultType.getName().getStringValue());
final Ref<ResultType> resolveResult = new Ref<>();
final Processor<StrutsPackage> processor = strutsPackage -> {
final ResultType result = ContainerUtil.find(strutsPackage.getResultTypes(), nameCondition);
if (result != null) {
resolveResult.set(result);
return false;
}
return true;
};
final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(ConverterUtil.getCurrentStrutsPackage(context), processor);
walker.walkUp();
return resolveResult.get();
}
use of com.intellij.struts2.dom.struts.strutspackage.ResultType in project intellij-plugins by JetBrains.
the class Struts2GlobalVariableProvider method getGlobalVariables.
@NotNull
public List<? extends FtlVariable> getGlobalVariables(final FtlFile file) {
final Module module = ModuleUtilCore.findModuleForPsiElement(file);
if (module == null) {
return Collections.emptyList();
}
if (StrutsFacet.getInstance(module) == null) {
return Collections.emptyList();
}
final List<FtlVariable> result = new ArrayList<>();
result.add(new MyFtlLightVariable("stack", file, (FtlType) null));
result.add(new MyFtlLightVariable("response", file, WebCommonClassNames.HTTP_SERVLET_RESPONSE));
result.add(new MyFtlLightVariable("res", file, WebCommonClassNames.HTTP_SERVLET_RESPONSE));
result.add(new MyFtlLightVariable("request", file, WebCommonClassNames.HTTP_SERVLET_REQUEST));
result.add(new MyFtlLightVariable("req", file, WebCommonClassNames.HTTP_SERVLET_REQUEST));
result.add(new MyFtlLightVariable("session", file, WebCommonClassNames.HTTP_SESSION));
result.add(new MyFtlLightVariable("application", file, WebCommonClassNames.SERVLET_CONTEXT));
result.add(new MyFtlLightVariable("base", file, CommonClassNames.JAVA_LANG_STRING));
installTaglibSupport(result, module, StrutsConstants.TAGLIB_STRUTS_UI_URI, StrutsConstants.TAGLIB_STRUTS_UI_PREFIX);
installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_PLUGIN_PREFIX);
installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_RICHTEXT_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_RICHTEXT_PLUGIN_PREFIX);
installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_CHART_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_CHART_PLUGIN_PREFIX);
installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_TREE_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_TREE_PLUGIN_PREFIX);
installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_GRID_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_GRID_PLUGIN_PREFIX);
installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_MOBILE_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_MOBILE_PLUGIN_PREFIX);
installTaglibSupport(result, module, StrutsConstants.TAGLIB_BOOTSTRAP_PLUGIN_URI, StrutsConstants.TAGLIB_BOOTSTRAP_PLUGIN_PREFIX);
final Processor<Action> processor = action -> {
final PsiClass actionClass = action.searchActionClass();
if (actionClass != null) {
for (final Result result1 : action.getResults()) {
final ResultType resultType = result1.getEffectiveResultType();
if (resultType != null && FreeMarkerStrutsResultContributor.FREEMARKER.equals(resultType.getName().getStringValue())) {
final PathReference reference = result1.getValue();
final PsiElement target = reference == null ? null : reference.resolve();
if (target != null && (file.getManager().areElementsEquivalent(file, target) || file.getManager().areElementsEquivalent(file.getOriginalFile(), target))) {
final PsiClassType actionType = PsiTypesUtil.getClassType(actionClass);
final FtlPsiType ftlPsiType = FtlPsiType.wrap(actionType);
result.add(new MyFtlLightVariable("", action.getXmlTag(), ftlPsiType));
result.add(new MyFtlLightVariable("action", action.getXmlTag(), ftlPsiType));
return false;
}
}
}
}
return true;
};
for (final StrutsModel model : StrutsManager.getInstance(file.getProject()).getAllModels(module)) {
model.processActions(processor);
}
return result;
}
use of com.intellij.struts2.dom.struts.strutspackage.ResultType in project intellij-plugins by JetBrains.
the class ResultTypeConverter method convertString.
@Override
protected ResultType convertString(@Nullable final String s, final ConvertContext convertContext) {
if (StringUtil.isEmpty(s)) {
return null;
}
final StrutsModel strutsModel = ConverterUtil.getStrutsModelOrCombined(convertContext);
if (strutsModel == null) {
return null;
}
final List<ResultType> resultTypes = ContainerUtil.concat(strutsModel.getStrutsPackages(), RESULT_TYPE_GETTER);
return ContainerUtil.find(resultTypes, resultType -> Comparing.strEqual(s, resultType.getName().getStringValue()));
}
use of com.intellij.struts2.dom.struts.strutspackage.ResultType in project intellij-plugins by JetBrains.
the class GlobalResultImpl method getEffectiveResultType.
@Nullable
public ResultType getEffectiveResultType() {
final ResultType resultType = getType().getValue();
if (resultType != null) {
return resultType;
}
final StrutsPackage strutsPackage = getParentOfType(StrutsPackage.class, true);
return strutsPackage != null ? strutsPackage.searchDefaultResultType() : null;
}
use of com.intellij.struts2.dom.struts.strutspackage.ResultType 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;
}
Aggregations