use of com.intellij.struts2.dom.struts.model.StrutsManager in project intellij-plugins by JetBrains.
the class Struts2ModelValidator method getFilesToProcess.
public Collection<VirtualFile> getFilesToProcess(final Project project, final CompileContext context) {
final StrutsManager strutsManager = StrutsManager.getInstance(project);
final PsiManager psiManager = PsiManager.getInstance(project);
// cache validation settings per module
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection") final FactoryMap<Module, Boolean> enabledForModule = new FactoryMap<Module, Boolean>() {
protected Boolean create(final Module module) {
return isEnabledForModule(module);
}
};
final Set<VirtualFile> files = new THashSet<>();
for (final VirtualFile file : context.getCompileScope().getFiles(StdFileTypes.XML, false)) {
final Module module = context.getModuleByFile(file);
if (module != null && enabledForModule.get(module)) {
final PsiFile psiFile = psiManager.findFile(file);
if (psiFile instanceof XmlFile) {
final StrutsModel model = strutsManager.getModelByFile((XmlFile) psiFile);
if (model != null) {
for (final XmlFile configFile : model.getConfigFiles()) {
ContainerUtil.addIfNotNull(files, configFile.getVirtualFile());
}
}
}
}
}
InspectionValidatorUtil.expandCompileScopeIfNeeded(files, context);
return files;
}
use of com.intellij.struts2.dom.struts.model.StrutsManager in project intellij-plugins by JetBrains.
the class NamespaceReferenceProvider 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;
}
return new PsiReference[] { new NamespaceReference((XmlAttributeValue) psiElement, strutsModel) };
}
use of com.intellij.struts2.dom.struts.model.StrutsManager in project intellij-plugins by JetBrains.
the class StrutsJamUtils method getStrutsModel.
/**
* Gets the model for the given attribute element.
*
* @param attributeElement Attribute element.
* @return {@code null} if no StrutsModel could be determined.
*/
@Nullable
public static StrutsModel getStrutsModel(final JamAttributeElement attributeElement) {
final PsiElement value = attributeElement.getPsiElement();
if (value == null) {
return null;
}
final StrutsManager instance = StrutsManager.getInstance(value.getProject());
return instance.getCombinedModel(value);
}
use of com.intellij.struts2.dom.struts.model.StrutsManager in project intellij-plugins by JetBrains.
the class StrutsFileSetCheckingAnnotator method annotate.
public void annotate(@NotNull final PsiElement psiElement, @NotNull final AnnotationHolder holder) {
if (!(psiElement instanceof XmlFile)) {
return;
}
if (psiElement instanceof JspFile) {
return;
}
final Module module = ModuleUtilCore.findModuleForPsiElement(psiElement);
if (module == null) {
return;
}
// do not run when facet not enabled
if (StrutsFacet.getInstance(module) == null) {
return;
}
final XmlFile xmlFile = (XmlFile) psiElement;
final Project project = psiElement.getProject();
final StrutsManager strutsManager = StrutsManager.getInstance(project);
if (!strutsManager.isStruts2ConfigFile(xmlFile)) {
return;
}
final VirtualFile currentVirtualFile = xmlFile.getVirtualFile();
assert currentVirtualFile != null;
final Set<StrutsFileSet> allConfigFileSets = strutsManager.getAllConfigFileSets(module);
for (final StrutsFileSet configFileSet : allConfigFileSets) {
if (configFileSet.hasFile(currentVirtualFile)) {
return;
}
}
final boolean fileSetAvailable = allConfigFileSets.size() != 0;
final Annotation annotation = holder.createWarningAnnotation(xmlFile, fileSetAvailable ? StrutsBundle.message("annotators.fileset.file.not.registered") : StrutsBundle.message("annotators.fileset.no.file.sets"));
annotation.setFileLevelAnnotation(true);
if (fileSetAvailable) {
final AddToFileSetFix addToFileSetFix = new AddToFileSetFix(xmlFile.getName());
annotation.registerFix(addToFileSetFix);
} else {
annotation.registerFix(new IntentionAction() {
@SuppressWarnings("DialogTitleCapitalization")
@NotNull
public String getText() {
return StrutsBundle.message("annotators.fileset.edit.facet.settings");
}
@NotNull
public String getFamilyName() {
return StrutsBundle.message("intentions.family.name");
}
public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile psiFile) {
return true;
}
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile psiFile) throws IncorrectOperationException {
final StrutsFacet strutsFacet = StrutsFacet.getInstance(module);
assert strutsFacet != null;
ModulesConfigurator.showFacetSettingsDialog(strutsFacet, null);
}
public boolean startInWriteAction() {
return false;
}
});
}
}
use of com.intellij.struts2.dom.struts.model.StrutsManager in project intellij-plugins by JetBrains.
the class StrutsModelFactory method computeAllModels.
protected List<StrutsModel> computeAllModels(@NotNull final Module module) {
final PsiManager psiManager = PsiManager.getInstance(module.getProject());
final StrutsManager strutsManager = StrutsManager.getInstance(module.getProject());
final Set<StrutsFileSet> fileSets = strutsManager.getAllConfigFileSets(module);
final List<StrutsModel> models = new ArrayList<>(fileSets.size());
for (final StrutsFileSet set : fileSets) {
if (set.isRemoved()) {
continue;
}
final Set<XmlFile> files = new LinkedHashSet<>(set.getFiles().size());
for (final VirtualFilePointer filePointer : set.getFiles()) {
if (!filePointer.isValid())
continue;
final VirtualFile file = filePointer.getFile();
if (file == null) {
continue;
}
final PsiFile psiFile = psiManager.findFile(file);
if (psiFile instanceof XmlFile) {
final StrutsRoot strutsRootDom = getDom((XmlFile) psiFile);
if (strutsRootDom != null) {
files.add((XmlFile) psiFile);
// TODO addIncludes(files, strutsRootDom);
}
}
}
if (!files.isEmpty()) {
final DomFileElement<StrutsRoot> element = createMergedModelRoot(files);
final StrutsModel model;
if (element != null) {
model = new StrutsModelImpl(element, files);
models.add(model);
}
}
}
return models;
}
Aggregations