Search in sources :

Example 1 with ResultType

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();
}
Also used : StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Comparing(com.intellij.openapi.util.Comparing) SmartList(com.intellij.util.SmartList) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) Processor(com.intellij.util.Processor) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) ConverterUtil(com.intellij.struts2.dom.ConverterUtil) ResultTypeResolvingConverter(com.intellij.struts2.dom.struts.action.ResultTypeResolvingConverter) ConvertContext(com.intellij.util.xml.ConvertContext) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) Condition(com.intellij.openapi.util.Condition) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Ref(com.intellij.openapi.util.Ref) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType)

Example 2 with ResultType

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;
}
Also used : PsiTypesUtil(com.intellij.psi.util.PsiTypesUtil) PathReference(com.intellij.openapi.paths.PathReference) XmlFile(com.intellij.psi.xml.XmlFile) StrutsManager(com.intellij.struts2.dom.struts.model.StrutsManager) NonNls(org.jetbrains.annotations.NonNls) Action(com.intellij.struts2.dom.struts.action.Action) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) FtlPsiType(com.intellij.freemarker.psi.variables.FtlPsiType) Result(com.intellij.struts2.dom.struts.action.Result) FtlFile(com.intellij.freemarker.psi.files.FtlFile) ArrayList(java.util.ArrayList) StrutsFacet(com.intellij.struts2.facet.StrutsFacet) FtlXmlNamespaceType(com.intellij.freemarker.psi.files.FtlXmlNamespaceType) FtlGlobalVariableProvider(com.intellij.freemarker.psi.files.FtlGlobalVariableProvider) XmlDocument(com.intellij.psi.xml.XmlDocument) FtlLightVariable(com.intellij.freemarker.psi.variables.FtlLightVariable) Module(com.intellij.openapi.module.Module) StrutsConstants(com.intellij.struts2.StrutsConstants) FtlVariable(com.intellij.freemarker.psi.variables.FtlVariable) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) StrutsIcons(com.intellij.struts2.StrutsIcons) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) WebCommonClassNames(com.intellij.javaee.web.WebCommonClassNames) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) Processor(com.intellij.util.Processor) FtlType(com.intellij.freemarker.psi.FtlType) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) JspManager(com.intellij.psi.impl.source.jsp.JspManager) javax.swing(javax.swing) PathReference(com.intellij.openapi.paths.PathReference) Action(com.intellij.struts2.dom.struts.action.Action) ArrayList(java.util.ArrayList) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) Result(com.intellij.struts2.dom.struts.action.Result) FtlVariable(com.intellij.freemarker.psi.variables.FtlVariable) FtlPsiType(com.intellij.freemarker.psi.variables.FtlPsiType) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) FtlType(com.intellij.freemarker.psi.FtlType) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ResultType

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()));
}
Also used : StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType)

Example 4 with ResultType

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;
}
Also used : StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with ResultType

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;
}
Also used : ParamNameConverter(com.intellij.struts2.dom.params.ParamNameConverter) Action(com.intellij.struts2.dom.struts.action.Action) HasResultType(com.intellij.struts2.dom.struts.HasResultType) ParamsElement(com.intellij.struts2.dom.params.ParamsElement) ActionMethodConverter(com.intellij.struts2.dom.struts.action.ActionMethodConverter) StrutsPathReferenceConverter(com.intellij.struts2.dom.struts.action.StrutsPathReferenceConverter) ExtendableClassConverter(com.intellij.struts2.dom.ExtendableClassConverter) ParamNameConverter(com.intellij.struts2.dom.params.ParamNameConverter) HasResultType(com.intellij.struts2.dom.struts.HasResultType) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) StrutsPathReferenceConverter(com.intellij.struts2.dom.struts.action.StrutsPathReferenceConverter) ActionMethodConverter(com.intellij.struts2.dom.struts.action.ActionMethodConverter) ExtendableClassConverter(com.intellij.struts2.dom.ExtendableClassConverter) Result(com.intellij.struts2.dom.struts.action.Result)

Aggregations

ResultType (com.intellij.struts2.dom.struts.strutspackage.ResultType)9 Nullable (org.jetbrains.annotations.Nullable)7 StrutsPackage (com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)6 Processor (com.intellij.util.Processor)4 List (java.util.List)4 NotNull (org.jetbrains.annotations.NotNull)4 Ref (com.intellij.openapi.util.Ref)3 StrutsPackageHierarchyWalker (com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker)3 NonNls (org.jetbrains.annotations.NonNls)3 Comparing (com.intellij.openapi.util.Comparing)2 Condition (com.intellij.openapi.util.Condition)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 HasResultType (com.intellij.struts2.dom.struts.HasResultType)2 Action (com.intellij.struts2.dom.struts.action.Action)2 Result (com.intellij.struts2.dom.struts.action.Result)2 StrutsModel (com.intellij.struts2.dom.struts.model.StrutsModel)2 FtlType (com.intellij.freemarker.psi.FtlType)1 FtlFile (com.intellij.freemarker.psi.files.FtlFile)1 FtlGlobalVariableProvider (com.intellij.freemarker.psi.files.FtlGlobalVariableProvider)1 FtlXmlNamespaceType (com.intellij.freemarker.psi.files.FtlXmlNamespaceType)1