use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class InjectedPsiCachedValueProvider method compute.
@Override
public CachedValueProvider.Result<MultiHostRegistrarImpl> compute(PsiElement element) {
PsiFile hostPsiFile = element.getContainingFile();
if (hostPsiFile == null)
return null;
FileViewProvider viewProvider = hostPsiFile.getViewProvider();
final DocumentEx hostDocument = (DocumentEx) viewProvider.getDocument();
if (hostDocument == null)
return null;
PsiManager psiManager = viewProvider.getManager();
final Project project = psiManager.getProject();
InjectedLanguageManagerImpl injectedManager = InjectedLanguageManagerImpl.getInstanceImpl(project);
final MultiHostRegistrarImpl result = doCompute(element, injectedManager, project, hostPsiFile);
return CachedValueProvider.Result.create(result, PsiModificationTracker.MODIFICATION_COUNT, hostDocument);
}
use of com.intellij.psi.PsiManager in project kotlin by JetBrains.
the class BasicTest method createJetFileList.
private static List<KtFile> createJetFileList(@NotNull Project project, @NotNull List<String> list, @Nullable String root) {
List<KtFile> libFiles = Lists.newArrayList();
PsiManager psiManager = PsiManager.getInstance(project);
VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL);
VirtualFile rootFile = root == null ? null : fileSystem.findFileByPath(root);
for (String libFileName : list) {
VirtualFile virtualFile = rootFile == null ? fileSystem.findFileByPath(libFileName) : rootFile.findFileByRelativePath(libFileName);
//TODO logging?
assert virtualFile != null : "virtual file is missing, most likely the file doesn't exist: " + libFileName;
PsiFile psiFile = psiManager.findFile(virtualFile);
libFiles.add((KtFile) psiFile);
}
return libFiles;
}
use of com.intellij.psi.PsiManager 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.psi.PsiManager in project intellij-plugins by JetBrains.
the class ValidatorModelValidator method getFilesToProcess.
public Collection<VirtualFile> getFilesToProcess(final Project project, final CompileContext context) {
final PsiManager psiManager = PsiManager.getInstance(project);
final ValidatorManager validatorManager = ValidatorManager.getInstance(project);
// cache S2facet/validation settings per module
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection") final FactoryMap<Module, Boolean> enabledForModule = new FactoryMap<Module, Boolean>() {
protected Boolean create(final Module module) {
return isEnabledForModule(module) && StrutsFacet.getInstance(module) != null;
}
};
// collect all validation.xml files located in sources of S2-modules
final Set<VirtualFile> files = new THashSet<>();
for (final VirtualFile file : context.getProjectCompileScope().getFiles(StdFileTypes.XML, true)) {
if (StringUtil.endsWith(file.getName(), FILENAME_EXTENSION_VALIDATION_XML)) {
final PsiFile psiFile = psiManager.findFile(file);
if (psiFile instanceof XmlFile && validatorManager.isValidatorsFile((XmlFile) psiFile)) {
final Module module = ModuleUtilCore.findModuleForFile(file, project);
if (module != null && enabledForModule.get(module)) {
files.add(file);
}
}
}
}
// add validator-config.xml if not default one from xwork.jar
final Set<VirtualFile> descriptorFiles = new THashSet<>();
for (final Module module : ModuleManager.getInstance(project).getModules()) {
if (enabledForModule.get(module)) {
final PsiFile psiFile = validatorManager.getValidatorConfigFile(module);
if (psiFile != null && validatorManager.isCustomValidatorConfigFile(psiFile)) {
InspectionValidatorUtil.addFile(descriptorFiles, psiFile);
}
}
}
files.addAll(InspectionValidatorUtil.expandCompileScopeIfNeeded(descriptorFiles, context));
return files;
}
use of com.intellij.psi.PsiManager in project intellij-plugins by JetBrains.
the class Tester method testFiles.
protected void testFiles(final Tester tester, VirtualFile[] files, VirtualFile[] auxiliaryFiles) throws Exception {
VirtualFile[] testFiles = configureByFiles(getRawProjectRoot(), files, auxiliaryFiles);
final PsiManager psiManager = PsiManager.getInstance(myProject);
for (int i = 0, n = testFiles.length; i < n; i++) {
final VirtualFile file = testFiles[i];
if (!file.getName().endsWith(JavaScriptSupportLoader.MXML_FILE_EXTENSION_DOT)) {
continue;
}
final VirtualFile originalVFile = files[i];
final XmlFile xmlFile = (XmlFile) psiManager.findFile(file);
assert xmlFile != null;
final Callable<Void> action = () -> {
tester.test(file, xmlFile, originalVFile);
return null;
};
if (TIMEOUT == 0) {
action.call();
} else {
ApplicationManager.getApplication().executeOnPooledThread(action).get(TIMEOUT, TimeUnit.SECONDS);
}
}
}
Aggregations