use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class ResourceBundleManager method getManager.
@Nullable
public static ResourceBundleManager getManager(PsiFile context) throws ResourceBundleNotFoundException {
final Project project = context.getProject();
final ResourceBundleManager[] managers = project.getExtensions(RESOURCE_BUNDLE_MANAGER);
for (ResourceBundleManager manager : managers) {
if (manager.isActive(context)) {
return manager;
}
}
final DefaultResourceBundleManager manager = new DefaultResourceBundleManager(project);
return manager.isActive(context) ? manager : null;
}
use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class DuplicateStringLiteralInspection method getDuplicateLiterals.
@NotNull
private List<PsiLiteralExpression> getDuplicateLiterals(String stringToFind, PsiLiteralExpression place) {
Project project = place.getProject();
Map<String, List<PsiLiteralExpression>> map = CachedValuesManager.getManager(project).getCachedValue(project, () -> {
Map<String, List<PsiLiteralExpression>> value = ConcurrentFactoryMap.createConcurrentMap(s -> Collections.unmodifiableList(findDuplicateLiterals(s, project)));
return CachedValueProvider.Result.create(value, PsiModificationTracker.MODIFICATION_COUNT);
});
return ContainerUtil.filter(map.get(stringToFind), literal -> literal != place);
}
use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class I18nInspection method isArgOfJUnitAssertion.
private static boolean isArgOfJUnitAssertion(PsiExpression expression) {
final PsiElement parent = expression.getParent();
if (!(parent instanceof PsiExpressionList)) {
return false;
}
final PsiElement grandparent = parent.getParent();
if (!(grandparent instanceof PsiMethodCallExpression)) {
return false;
}
final PsiMethodCallExpression call = (PsiMethodCallExpression) grandparent;
final PsiReferenceExpression methodExpression = call.getMethodExpression();
@NonNls final String methodName = methodExpression.getReferenceName();
if (methodName == null) {
return false;
}
if (!methodName.startsWith("assert") && !methodName.equals("fail")) {
return false;
}
final PsiMethod method = call.resolveMethod();
if (method == null) {
return false;
}
final PsiClass containingClass = method.getContainingClass();
if (containingClass == null) {
return false;
}
final Project project = expression.getProject();
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
final PsiClass junitAssert = JavaPsiFacade.getInstance(project).findClass("junit.framework.Assert", scope);
return junitAssert != null && !containingClass.isInheritor(junitAssert, true);
}
use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class I18nizeQuickFix method performI18nization.
@Override
public void performI18nization(final PsiFile psiFile, final Editor editor, PsiLiteralExpression literalExpression, Collection<PropertiesFile> propertiesFiles, String key, String value, String i18nizedText, PsiExpression[] parameters, final PropertyCreationHandler propertyCreationHandler) throws IncorrectOperationException {
Project project = psiFile.getProject();
propertyCreationHandler.createProperty(project, propertiesFiles, key, value, parameters);
try {
final PsiElement newExpression = doReplacementInJava(psiFile, editor, literalExpression, i18nizedText);
reformatAndCorrectReferences(newExpression);
} catch (IncorrectOperationException e) {
Messages.showErrorDialog(project, CodeInsightBundle.message("inspection.i18n.expression.is.invalid.error.message"), CodeInsightBundle.message("inspection.error.dialog.title"));
}
}
use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class MavenActionUtil method getMavenProjects.
public static List<MavenProject> getMavenProjects(DataContext context) {
Project project = CommonDataKeys.PROJECT.getData(context);
if (project == null)
return Collections.emptyList();
VirtualFile[] virtualFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(context);
if (virtualFiles == null || virtualFiles.length == 0)
return Collections.emptyList();
MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(project);
if (!projectsManager.isMavenizedProject())
return Collections.emptyList();
Set<MavenProject> res = new LinkedHashSet<>();
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
for (VirtualFile file : virtualFiles) {
MavenProject mavenProject;
if (file.isDirectory()) {
VirtualFile contentRoot = fileIndex.getContentRootForFile(file);
if (!file.equals(contentRoot))
return Collections.emptyList();
Module module = fileIndex.getModuleForFile(file);
if (module == null || !projectsManager.isMavenizedModule(module))
return Collections.emptyList();
mavenProject = projectsManager.findProject(module);
} else {
mavenProject = projectsManager.findProject(file);
}
if (mavenProject == null)
return Collections.emptyList();
res.add(mavenProject);
}
return new ArrayList<>(res);
}
Aggregations