use of com.intellij.struts2.dom.struts.action.Action in project intellij-plugins by JetBrains.
the class ActionLinkReferenceProviderTest method checkActionReference.
/**
* Checks the Action-reference.
*
* @param filename File to check.
* @param actionName Name of the Action to resolve to.
* @throws Throwable On errors.
*/
private void checkActionReference(@NonNls final String filename, @NonNls final String actionName) {
final PsiReference psiReference = myFixture.getReferenceAtCaretPositionWithAssertion(filename);
final PsiElement psiElement = psiReference.resolve();
assertNotNull("no resolve element " + actionName, psiElement);
assertTrue(psiElement instanceof XmlTag);
final DomElement actionElement = DomManager.getDomManager(getProject()).getDomElement((XmlTag) psiElement);
assertNotNull(actionElement);
assertInstanceOf(actionElement, Action.class);
assertEquals("Action name differs for " + actionName, actionName, ((Action) actionElement).getName().getStringValue());
}
use of com.intellij.struts2.dom.struts.action.Action in project intellij-plugins by JetBrains.
the class ActionPropertyReferenceProvider method getReferencesByElement.
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull final PsiElement psiElement, @NotNull final ProcessingContext processingContext) {
if (TaglibUtil.isDynamicExpression(((XmlAttributeValue) psiElement).getValue())) {
return PsiReference.EMPTY_ARRAY;
}
final XmlTag tag = PsiTreeUtil.getParentOfType(psiElement, XmlTag.class);
assert tag != null;
final XmlTag actionTag = findEnclosingTag(tag, tag.getNamespacePrefix());
if (actionTag == null) {
return PsiReference.EMPTY_ARRAY;
}
final String actionName = Comparing.equal(actionTag.getLocalName(), "action") ? actionTag.getAttributeValue("name") : actionTag.getAttributeValue("action");
if (actionName == null || TaglibUtil.isDynamicExpression(actionName)) {
return PsiReference.EMPTY_ARRAY;
}
final StrutsManager strutsManager = StrutsManager.getInstance(psiElement.getProject());
final StrutsModel strutsModel = strutsManager.getCombinedModel(psiElement);
if (strutsModel == null) {
return PsiReference.EMPTY_ARRAY;
}
final List<Action> actions = strutsModel.findActionsByName(actionName, actionTag.getAttributeValue("namespace"));
if (actions.size() != 1) {
return PsiReference.EMPTY_ARRAY;
}
final Action action = actions.get(0);
return new BeanPropertyPathReferenceSet(psiElement, action.searchActionClass(), supportsReadOnlyProperties) {
// TODO CTOR creates references eagerly, so we have to subclass here
@Override
public boolean isSoft() {
return false;
}
}.getPsiReferences();
}
use of com.intellij.struts2.dom.struts.action.Action in project intellij-plugins by JetBrains.
the class ActionReferenceProvider method getReferencesByElement.
@NotNull
public PsiReference[] getReferencesByElement(@NotNull final PsiElement psiElement, @NotNull final ProcessingContext context) {
final StrutsManager strutsManager = StrutsManager.getInstance(psiElement.getProject());
final StrutsModel strutsModel = strutsManager.getCombinedModel(psiElement);
if (strutsModel == null) {
return PsiReference.EMPTY_ARRAY;
}
final XmlAttributeValue xmlAttributeValue = (XmlAttributeValue) psiElement;
final String path = xmlAttributeValue.getValue();
// resolve to <action>
final String actionName = TaglibUtil.trimActionPath(path);
final String namespace = getNamespace(xmlAttributeValue);
final List<Action> actions = strutsModel.findActionsByName(actionName, namespace);
final Action action = actions.isEmpty() ? null : actions.get(0);
final int bangIndex = path.indexOf(TaglibUtil.BANG_SYMBOL);
if (bangIndex == -1) {
return new PsiReference[] { new ActionReference(xmlAttributeValue, action, namespace, strutsModel) };
}
return new PsiReference[] { new ActionReference(xmlAttributeValue, action, namespace, strutsModel), new ActionMethodReference(xmlAttributeValue, action, bangIndex) };
}
use of com.intellij.struts2.dom.struts.action.Action in project intellij-plugins by JetBrains.
the class ExceptionMappingResultResolveConverter method getVariants.
@NotNull
public Collection<? extends HasResultType> getVariants(final ConvertContext context) {
final DomElement invocationElement = context.getInvocationElement();
final Action action = invocationElement.getParentOfType(Action.class, true);
if (action == null) {
return Collections.emptySet();
}
final List<HasResultType> variants = new ArrayList<>();
// Action-local first
variants.addAll(action.getResults());
final StrutsPackage strutsPackage = action.getStrutsPackage();
final GlobalResults globalResults = strutsPackage.getGlobalResults();
variants.addAll(globalResults.getResults());
return variants;
}
use of com.intellij.struts2.dom.struts.action.Action 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;
}
Aggregations