Search in sources :

Example 1 with PathReference

use of com.intellij.openapi.paths.PathReference in project intellij-community by JetBrains.

the class RegistrationCheckerUtil method checkModule.

@Nullable
private static Set<PsiClass> checkModule(Module module, PsiClass psiClass, @Nullable Set<PsiClass> types, boolean includeActions) {
    final XmlFile pluginXml = PluginModuleType.getPluginXml(module);
    if (pluginXml == null)
        return null;
    final DomFileElement<IdeaPlugin> fileElement = DescriptorUtil.getIdeaPlugin(pluginXml);
    if (fileElement == null)
        return null;
    final String qualifiedName = psiClass.getQualifiedName();
    if (qualifiedName != null) {
        final RegistrationTypeFinder finder = new RegistrationTypeFinder(psiClass, types);
        // "main" plugin.xml
        processPluginXml(pluginXml, finder, includeActions);
        // <depends> plugin.xml files
        for (Dependency dependency : fileElement.getRootElement().getDependencies()) {
            final GenericAttributeValue<PathReference> configFileAttribute = dependency.getConfigFile();
            if (!DomUtil.hasXml(configFileAttribute))
                continue;
            final PathReference configFile = configFileAttribute.getValue();
            if (configFile != null) {
                final PsiElement resolve = configFile.resolve();
                if (!(resolve instanceof XmlFile))
                    continue;
                final XmlFile depPluginXml = (XmlFile) resolve;
                if (DescriptorUtil.isPluginXml(depPluginXml)) {
                    processPluginXml(depPluginXml, finder, includeActions);
                }
            }
        }
        types = finder.getTypes();
    }
    return types;
}
Also used : PathReference(com.intellij.openapi.paths.PathReference) XmlFile(com.intellij.psi.xml.XmlFile) IdeaPlugin(org.jetbrains.idea.devkit.dom.IdeaPlugin) Dependency(org.jetbrains.idea.devkit.dom.Dependency) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PathReference

use of com.intellij.openapi.paths.PathReference in project intellij-plugins by JetBrains.

the class ResultNode method getIcon.

@NotNull
public Icon getIcon() {
    final Result result = getIdentifyingElement();
    if (!result.isValid()) {
        return UNKNOWN_RESULT_ICON;
    }
    final PathReference pathReference = result.getValue();
    if (pathReference == null) {
        return UNKNOWN_RESULT_ICON;
    }
    if (pathReference.resolve() == null) {
        return UNKNOWN_RESULT_ICON;
    }
    final Icon pathReferenceIcon = pathReference.getIcon();
    return pathReferenceIcon != null ? pathReferenceIcon : UNKNOWN_RESULT_ICON;
}
Also used : PathReference(com.intellij.openapi.paths.PathReference) Result(com.intellij.struts2.dom.struts.action.Result) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with PathReference

use of com.intellij.openapi.paths.PathReference in project intellij-plugins by JetBrains.

the class StrutsResultContributor method createDefaultPathReference.

/**
   * Creates PathReference from resolve result.
   *
   * @param path       Path to resolve.
   * @param element    Context element.
   * @param staticIcon Static icon or {@code null} for resolve target's icon.
   * @return PathReference or {@code null} if no references.
   */
@Nullable
protected PathReference createDefaultPathReference(final String path, final PsiElement element, @Nullable final Icon staticIcon) {
    final ArrayList<PsiReference> list = new ArrayList<>(5);
    createReferences(element, list, true);
    if (list.isEmpty()) {
        return null;
    }
    final PsiElement target = list.get(list.size() - 1).resolve();
    if (target == null) {
        return null;
    }
    final Function<PathReference, Icon> iconFunction;
    if (staticIcon == null) {
        iconFunction = webPath -> target.getIcon(Iconable.ICON_FLAG_READ_STATUS);
    } else {
        iconFunction = new ConstantFunction<>(staticIcon);
    }
    return new PathReference(path, iconFunction) {

        public PsiElement resolve() {
            return target;
        }
    };
}
Also used : PathReference(com.intellij.openapi.paths.PathReference) ArrayList(java.util.ArrayList) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with PathReference

use of com.intellij.openapi.paths.PathReference 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 5 with PathReference

use of com.intellij.openapi.paths.PathReference in project intellij-plugins by JetBrains.

the class GotoRelatedActionProvider method getItems.

@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull final PsiElement psiElement) {
    PsiFile psiFile = psiElement.getContainingFile();
    if (psiFile == null)
        return Collections.emptyList();
    final PsiFile containingFile = psiFile.getOriginalFile();
    final String filename = containingFile.getName();
    final String extension = FileUtilRt.getExtension(filename);
    if (!SUPPORTED_EXTENSIONS.contains(extension)) {
        return Collections.emptyList();
    }
    final StrutsManager strutsManager = StrutsManager.getInstance(psiElement.getProject());
    final StrutsModel strutsModel = strutsManager.getCombinedModel(psiElement);
    if (strutsModel == null) {
        return Collections.emptyList();
    }
    final List<PsiFile> allFiles = containingFile.getViewProvider().getAllFiles();
    final Set<Action> actions = new HashSet<>();
    final List<GotoRelatedItem> items = new ArrayList<>();
    strutsModel.processActions(action -> {
        for (final Result result : action.getResults()) {
            final PathReference pathReference = result.getValue();
            if (pathReference == null) {
                continue;
            }
            final String path = pathReference.getPath();
            if (!path.endsWith(filename)) {
                continue;
            }
            final PsiElement resolve = pathReference.resolve();
            if (ContainerUtil.find(allFiles, resolve) == null) {
                continue;
            }
            if (!actions.contains(action)) {
                items.add(new DomGotoRelatedItem(action));
                actions.add(action);
            }
            final PsiClass actionClass = action.searchActionClass();
            if (actionClass == null) {
                continue;
            }
            final PsiMethod actionMethod = action.searchActionMethod();
            items.add(new GotoRelatedItem(actionMethod != null ? actionMethod : actionClass));
        }
        return true;
    });
    return items;
}
Also used : PathReference(com.intellij.openapi.paths.PathReference) Action(com.intellij.struts2.dom.struts.action.Action) PsiMethod(com.intellij.psi.PsiMethod) StrutsManager(com.intellij.struts2.dom.struts.model.StrutsManager) PsiClass(com.intellij.psi.PsiClass) Result(com.intellij.struts2.dom.struts.action.Result) DomGotoRelatedItem(com.intellij.codeInsight.navigation.DomGotoRelatedItem) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) PsiFile(com.intellij.psi.PsiFile) DomGotoRelatedItem(com.intellij.codeInsight.navigation.DomGotoRelatedItem) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PathReference (com.intellij.openapi.paths.PathReference)8 Result (com.intellij.struts2.dom.struts.action.Result)6 Action (com.intellij.struts2.dom.struts.action.Action)4 StrutsModel (com.intellij.struts2.dom.struts.model.StrutsModel)4 PsiElement (com.intellij.psi.PsiElement)3 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 XmlFile (com.intellij.psi.xml.XmlFile)2 StrutsManager (com.intellij.struts2.dom.struts.model.StrutsManager)2 NonNls (org.jetbrains.annotations.NonNls)2 Nullable (org.jetbrains.annotations.Nullable)2 DomGotoRelatedItem (com.intellij.codeInsight.navigation.DomGotoRelatedItem)1 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 FtlLightVariable (com.intellij.freemarker.psi.variables.FtlLightVariable)1 FtlPsiType (com.intellij.freemarker.psi.variables.FtlPsiType)1 FtlVariable (com.intellij.freemarker.psi.variables.FtlVariable)1 WebCommonClassNames (com.intellij.javaee.web.WebCommonClassNames)1