Search in sources :

Example 66 with Project

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;
}
Also used : Project(com.intellij.openapi.project.Project) Nullable(org.jetbrains.annotations.Nullable)

Example 67 with Project

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);
}
Also used : Project(com.intellij.openapi.project.Project) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 68 with Project

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);
}
Also used : NonNls(org.jetbrains.annotations.NonNls) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Example 69 with Project

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"));
    }
}
Also used : Project(com.intellij.openapi.project.Project) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 70 with Project

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Project(com.intellij.openapi.project.Project) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Module(com.intellij.openapi.module.Module)

Aggregations

Project (com.intellij.openapi.project.Project)3623 VirtualFile (com.intellij.openapi.vfs.VirtualFile)874 NotNull (org.jetbrains.annotations.NotNull)580 Nullable (org.jetbrains.annotations.Nullable)478 Module (com.intellij.openapi.module.Module)368 PsiFile (com.intellij.psi.PsiFile)334 Editor (com.intellij.openapi.editor.Editor)301 PsiElement (com.intellij.psi.PsiElement)292 ArrayList (java.util.ArrayList)214 File (java.io.File)212 Document (com.intellij.openapi.editor.Document)180 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)172 List (java.util.List)158 IOException (java.io.IOException)107 TextRange (com.intellij.openapi.util.TextRange)99 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)96 IncorrectOperationException (com.intellij.util.IncorrectOperationException)95 Presentation (com.intellij.openapi.actionSystem.Presentation)94 DataContext (com.intellij.openapi.actionSystem.DataContext)92 PsiDirectory (com.intellij.psi.PsiDirectory)90