use of com.intellij.struts2.facet.ui.StrutsFileSet in project intellij-plugins by JetBrains.
the class Struts2ModelInspection method checkFileElement.
/**
* Only inspect struts.xml files configured in fileset.
*
* @param strutsRootDomFileElement Root element of file to inspect.
* @param holder Holder.
*/
public void checkFileElement(final DomFileElement<StrutsRoot> strutsRootDomFileElement, final DomElementAnnotationHolder holder) {
final Module module = strutsRootDomFileElement.getModule();
if (module == null) {
return;
}
final XmlFile xmlFile = strutsRootDomFileElement.getFile();
final VirtualFile virtualFile = xmlFile.getVirtualFile();
final Set<StrutsFileSet> fileSets = StrutsManager.getInstance(xmlFile.getProject()).getAllConfigFileSets(module);
for (final StrutsFileSet strutsFileSet : fileSets) {
if (strutsFileSet.hasFile(virtualFile)) {
super.checkFileElement(strutsRootDomFileElement, holder);
break;
}
}
}
use of com.intellij.struts2.facet.ui.StrutsFileSet in project intellij-plugins by JetBrains.
the class BasicLightHighlightingTestCase method createStrutsFileSet.
/**
* For files located in JAR: {@code [PATH_TO_JAR]!/[PATH_TO_STRUTS_XML]}.
*
* @param strutsXmlPaths Paths to files.
*/
protected void createStrutsFileSet(@NonNls final String... strutsXmlPaths) {
final StrutsFacet strutsFacet = StrutsFacet.getInstance(myModule);
assertNotNull(strutsFacet);
final StrutsFacetConfiguration facetConfiguration = strutsFacet.getConfiguration();
final StrutsFileSet fileSet = new StrutsFileSet("test", "test", facetConfiguration);
for (final String fileName : strutsXmlPaths) {
final VirtualFile file;
final String path;
if (fileName.contains("!")) {
path = PathManager.getHomePath() + TEST_DATA_PATH + "/" + fileName;
file = JarFileSystem.getInstance().refreshAndFindFileByPath(path);
} else {
path = fileName;
file = myFixture.copyFileToProject(fileName);
}
assertNotNull("could not find file: '" + path + "'", file);
fileSet.addFile(file);
}
final Set<StrutsFileSet> strutsFileSetSet = facetConfiguration.getFileSets();
strutsFileSetSet.add(fileSet);
}
use of com.intellij.struts2.facet.ui.StrutsFileSet 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.facet.ui.StrutsFileSet 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;
}
use of com.intellij.struts2.facet.ui.StrutsFileSet in project intellij-plugins by JetBrains.
the class StrutsFacetConfiguration method readExternal.
public void readExternal(final Element element) throws InvalidDataException {
for (final Object setElement : element.getChildren(FILESET)) {
final String setName = ((Element) setElement).getAttributeValue(SET_NAME);
final String setId = ((Element) setElement).getAttributeValue(SET_ID);
final String removed = ((Element) setElement).getAttributeValue(SET_REMOVED);
if (setName != null && setId != null) {
final StrutsFileSet fileSet = new StrutsFileSet(setId, setName, this);
final List files = ((Element) setElement).getChildren(FILE);
for (final Object fileElement : files) {
final String text = ((Element) fileElement).getText();
fileSet.addFile(text);
}
fileSet.setRemoved(Boolean.valueOf(removed));
myFileSets.add(fileSet);
}
}
// new in X
final Element propertiesElement = element.getChild(PROPERTIES_KEYS);
if (propertiesElement != null) {
final String disabled = propertiesElement.getAttributeValue(PROPERTIES_KEYS_DISABLED);
myPropertiesKeysDisabled = Boolean.valueOf(disabled);
}
}
Aggregations