use of com.intellij.psi.impl.source.jsp.WebDirectoryUtil in project intellij-plugins by JetBrains.
the class Struts2TilesModelProvider method computeModels.
@NotNull
public Collection<TilesModel> computeModels(@NotNull final Module module) {
final Project project = module.getProject();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
final GlobalSearchScope moduleScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
// struts2-tiles plugin must be available
final PsiClass strutsTilesListenerClass = facade.findClass(STRUTS_TILES_LISTENER_CLASS, moduleScope);
if (strutsTilesListenerClass == null) {
return Collections.emptyList();
}
final PsiClass tilesListenerClass = facade.findClass(TilesConstants.TILES_LISTENER, moduleScope);
final StrutsPluginDomFactory<TilesDefinitions, TilesModel> factory = StrutsProjectComponent.getInstance(project).getTilesFactory();
final Set<TilesModel> struts2TilesModels = new HashSet<>();
final Consumer<Set<XmlFile>> consumer = definitions -> {
final DomFileElement<TilesDefinitions> domFileElement = factory.createMergedModelRoot(definitions);
if (domFileElement != null) {
struts2TilesModels.add(new TilesModelImpl(definitions, domFileElement, STRUTS2_TILES_MODEL));
}
};
final WebDirectoryUtil webDirectoryUtil = WebDirectoryUtil.getWebDirectoryUtil(project);
final Collection<WebFacet> webFacets = WebFacet.getInstances(module);
for (final WebFacet webFacet : webFacets) {
final WebApp webApp = webFacet.getRoot();
if (webApp == null) {
continue;
}
// determine configured tiles config files
@NonNls final Set<String> tilesConfigNames = findConfiguredTilesPaths(webApp);
// no configured paths? use default
if (tilesConfigNames.isEmpty()) {
tilesConfigNames.add(DEFAULT_TILES_XML);
}
// resolve to XmlFile
final Set<XmlFile> tilesFileSet = new HashSet<>();
for (final String tilesPath : tilesConfigNames) {
final PsiElement tilesXmlFile = webDirectoryUtil.findFileByPath(tilesPath, webFacet);
if (tilesXmlFile instanceof XmlFile) {
tilesFileSet.add((XmlFile) tilesXmlFile);
}
}
final List<Listener> listenerList = webApp.getListeners();
for (final Listener listener : listenerList) {
final PsiClass listenerClass = listener.getListenerClass().getValue();
if (strutsTilesListenerClass.equals(listenerClass) || Comparing.equal(tilesListenerClass, listenerClass)) {
consumer.consume(tilesFileSet);
}
}
}
return struts2TilesModels;
}
use of com.intellij.psi.impl.source.jsp.WebDirectoryUtil in project intellij-plugins by JetBrains.
the class FileReferenceSetHelper method addWebDirectoryAndCurrentNamespaceAsRoots.
/**
* Adds all {@link WebDirectoryElement}s as well as web-directory with name of given current namespace
* (if not "root" namespace) as possible content roots.
*
* @param psiElement Current element.
* @param namespace Current namespace.
* @param webFacet Module.
* @param set FRS to patch.
*/
public static void addWebDirectoryAndCurrentNamespaceAsRoots(final PsiElement psiElement, final String namespace, final WebFacet webFacet, final FileReferenceSet set) {
final WebDirectoryUtil directoryUtil = WebDirectoryUtil.getWebDirectoryUtil(psiElement.getProject());
set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, file -> {
final List<PsiFileSystemItem> basePathRoots = new ArrayList<>();
final List<WebRoot> webRoots = webFacet.getWebRoots(true);
for (final WebRoot webRoot : webRoots) {
final String webRootPath = webRoot.getRelativePath();
final WebDirectoryElement webRootBase = directoryUtil.findWebDirectoryElementByPath(webRootPath, webFacet);
ContainerUtil.addIfNotNull(basePathRoots, webRootBase);
}
if (!Comparing.equal(namespace, StrutsPackage.DEFAULT_NAMESPACE)) {
final WebDirectoryElement packageBase = directoryUtil.findWebDirectoryElementByPath(namespace, webFacet);
ContainerUtil.addIfNotNull(basePathRoots, packageBase);
}
return basePathRoots;
});
}
Aggregations