use of com.intellij.struts2.dom.struts.model.StrutsManager 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.model.StrutsManager 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.StrutsManager in project intellij-plugins by JetBrains.
the class Struts2ProblemFileHighlightFilter method value.
@Override
public boolean value(final VirtualFile virtualFile) {
if (virtualFile.getFileType() != StdFileTypes.XML) {
return false;
}
final Module module = ModuleUtilCore.findModuleForFile(virtualFile, project);
if (module == null) {
return false;
}
if (StrutsFacet.getInstance(module) == null) {
return false;
}
final boolean isStrutsXml = ReadAction.compute(() -> {
final StrutsManager strutsManager = StrutsManager.getInstance(project);
final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
return psiFile instanceof XmlFile && strutsManager.isStruts2ConfigFile((XmlFile) psiFile) && strutsManager.getModelByFile((XmlFile) psiFile) != null;
});
if (isStrutsXml) {
return true;
}
return ReadAction.compute(() -> {
final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
return psiFile instanceof XmlFile && ValidatorManager.getInstance(project).isValidatorsFile((XmlFile) psiFile);
});
}
use of com.intellij.struts2.dom.struts.model.StrutsManager in project intellij-plugins by JetBrains.
the class ActionAnnotatorBase method collectNavigationMarkers.
@Override
protected void collectNavigationMarkers(@NotNull final PsiElement element, final Collection<? super RelatedItemLineMarkerInfo> lineMarkerInfos) {
if (!(element instanceof PsiIdentifier))
return;
final PsiClass clazz = getActionPsiClass(element.getParent());
if (clazz == null || clazz.getNameIdentifier() != element) {
return;
}
// do not run on non-public, abstract classes or interfaces
if (clazz.isInterface() || clazz.isAnnotationType() || !clazz.hasModifierProperty(PsiModifier.PUBLIC) || clazz.hasModifierProperty(PsiModifier.ABSTRACT)) {
return;
}
// short exit if Struts Facet not present
final Module module = ModuleUtilCore.findModuleForPsiElement(clazz);
if (module == null || StrutsFacet.getInstance(module) == null) {
return;
}
final StrutsManager strutsManager = StrutsManager.getInstance(element.getProject());
final StrutsModel strutsModel = strutsManager.getCombinedModel(module);
if (strutsModel == null) {
return;
}
installValidationTargets(element, lineMarkerInfos, clazz);
final List<Action> actions = strutsModel.findActionsByClass(clazz);
if (actions.isEmpty()) {
return;
}
installActionTargets(element, lineMarkerInfos, actions);
installActionMethods(lineMarkerInfos, clazz, actions);
}
use of com.intellij.struts2.dom.struts.model.StrutsManager 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();
}
Aggregations