use of com.intellij.struts2.dom.struts.action.Result 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.action.Result 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;
}
use of com.intellij.struts2.dom.struts.action.Result in project intellij-plugins by JetBrains.
the class StrutsDataModel method updateDataModel.
private void updateDataModel() {
final StrutsModel model = StrutsManager.getInstance(myProject).getModelByFile(myFile);
if (model == null) {
return;
}
for (final StrutsPackage strutsPackage : model.getStrutsPackages()) {
for (final Action action : strutsPackage.getActions()) {
final ActionNode actionNode = new ActionNode(action, action.getName().getStringValue());
addNode(actionNode);
for (final Result result : action.getResults()) {
final PathReference pathReference = result.getValue();
final String path = pathReference != null ? pathReference.getPath() : UNKNOWN;
final ResultNode resultNode = new ResultNode(result, path);
addNode(resultNode);
final String resultName = result.getName().getStringValue();
addEdge(new BasicStrutsEdge(actionNode, resultNode, resultName != null ? resultName : Result.DEFAULT_NAME));
}
}
}
}
use of com.intellij.struts2.dom.struts.action.Result in project intellij-plugins by JetBrains.
the class Struts2UrlConverter method getTargetPaths.
public Collection<String> getTargetPaths(@NotNull final PsiFile sourceFile, @NotNull final WebFacet webFacet) {
final StrutsModel combinedModel = StrutsManager.getInstance(sourceFile.getProject()).getCombinedModel(webFacet.getModule());
if (combinedModel == null) {
return Collections.emptyList();
}
final List<String> actionExtensions = StrutsConstantHelper.getActionExtensions(sourceFile);
if (actionExtensions.isEmpty()) {
return Collections.emptyList();
}
final String actionExtension = actionExtensions.get(0);
@NonNls final ArrayList<String> list = new ArrayList<>();
combinedModel.processActions(action -> {
for (final Result result : action.getResults()) {
final PathReference pathReference = result.getValue();
if (pathReference != null) {
final PsiElement psiElement = pathReference.resolve();
if (psiElement != null && psiElement.equals(sourceFile)) {
String namespace = action.getNamespace();
if (!Comparing.equal(namespace, StrutsPackage.DEFAULT_NAMESPACE)) {
namespace += "/";
}
list.add(namespace + action.getName().getStringValue() + actionExtension);
}
}
}
return true;
});
return list;
}
use of com.intellij.struts2.dom.struts.action.Result 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