use of com.intellij.struts2.dom.struts.model.StrutsModel 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.model.StrutsModel in project intellij-plugins by JetBrains.
the class StrutsConstantManagerImpl method getConvertedValue.
@Override
@Nullable
public <T> T getConvertedValue(@NotNull final PsiElement context, @NotNull final StrutsConstantKey<T> strutsConstantKey) {
final PsiFile containingFile = context.getContainingFile();
final StrutsModel strutsModel = getStrutsModel(containingFile);
if (strutsModel == null) {
return null;
}
final String stringValue = getStringValue(containingFile, strutsModel, strutsConstantKey.getKey());
if (stringValue == null) {
return null;
}
final Converter<T> converter = findConverter(context, strutsConstantKey);
if (converter == null) {
//noinspection unchecked
return (T) stringValue;
}
final DomFileElement<StrutsRoot> first = strutsModel.getRoots().iterator().next();
final ConvertContext convertContext = ConvertContextFactory.createConvertContext(first);
//noinspection unchecked
return converter.fromString(stringValue, convertContext);
}
use of com.intellij.struts2.dom.struts.model.StrutsModel in project intellij-plugins by JetBrains.
the class StrutsConstantManagerImpl method getStrutsModel.
/**
* Determines best matching StrutsModel.
*
* @param psiFile Context file.
* @return {@code null} if no model could be determined.
*/
@Nullable
private static StrutsModel getStrutsModel(final PsiFile psiFile) {
final StrutsManager strutsManager = StrutsManager.getInstance(psiFile.getProject());
final StrutsModel model;
if (psiFile instanceof XmlFile && strutsManager.isStruts2ConfigFile((XmlFile) psiFile)) {
model = strutsManager.getModelByFile((XmlFile) psiFile);
} else {
model = strutsManager.getCombinedModel(psiFile);
}
return model;
}
use of com.intellij.struts2.dom.struts.model.StrutsModel 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()));
}
use of com.intellij.struts2.dom.struts.model.StrutsModel 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;
}
Aggregations