use of com.intellij.struts2.dom.struts.model.StrutsModel 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.model.StrutsModel in project intellij-plugins by JetBrains.
the class GoToActionSymbolProvider method addNames.
protected void addNames(@NotNull final Module module, final Set<String> result) {
final StrutsModel strutsModel = StrutsManager.getInstance(module.getProject()).getCombinedModel(module);
if (strutsModel == null) {
return;
}
strutsModel.processActions(action -> {
result.add(action.getName().getStringValue());
return true;
});
}
use of com.intellij.struts2.dom.struts.model.StrutsModel in project intellij-plugins by JetBrains.
the class GoToActionSymbolProvider method addItems.
protected void addItems(@NotNull final Module module, final String name, final List<NavigationItem> result) {
final StrutsModel strutsModel = StrutsManager.getInstance(module.getProject()).getCombinedModel(module);
if (strutsModel == null) {
return;
}
final List<Action> actions = strutsModel.findActionsByName(name, null);
for (final Action action : actions) {
final NavigationItem item = createNavigationItem(action.getXmlTag(), action.getName().getStringValue() + " [" + action.getNamespace() + "]", Struts2Icons.Action);
result.add(item);
}
}
use of com.intellij.struts2.dom.struts.model.StrutsModel in project intellij-plugins by JetBrains.
the class GoToPackageSymbolProvider method addNames.
protected void addNames(@NotNull final Module module, final Set<String> result) {
final StrutsModel strutsModel = StrutsManager.getInstance(module.getProject()).getCombinedModel(module);
if (strutsModel == null) {
return;
}
final Set<String> packageNames = ContainerUtil.map2Set(strutsModel.getStrutsPackages(), STRUTS_PACKAGE_NAME_FUNCTION);
result.addAll(packageNames);
}
use of com.intellij.struts2.dom.struts.model.StrutsModel 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;
}
Aggregations