Search in sources :

Example 1 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.

the class MavenModuleImporter method configDependencies.

private void configDependencies() {
    THashSet<String> dependencyTypesFromSettings = new THashSet<>();
    AccessToken accessToken = ReadAction.start();
    try {
        if (myModule.getProject().isDisposed())
            return;
        dependencyTypesFromSettings.addAll(MavenProjectsManager.getInstance(myModule.getProject()).getImportingSettings().getDependencyTypesAsSet());
    } finally {
        accessToken.finish();
    }
    for (MavenArtifact artifact : myMavenProject.getDependencies()) {
        String dependencyType = artifact.getType();
        if (!dependencyTypesFromSettings.contains(dependencyType) && !myMavenProject.getDependencyTypesFromImporters(SupportedRequestType.FOR_IMPORT).contains(dependencyType)) {
            continue;
        }
        DependencyScope scope = selectScope(artifact.getScope());
        MavenProject depProject = myMavenTree.findProject(artifact.getMavenId());
        if (depProject != null) {
            if (depProject == myMavenProject)
                continue;
            String moduleName = myMavenProjectToModuleName.get(depProject);
            if (moduleName == null || myMavenTree.isIgnored(depProject)) {
                MavenArtifact projectsArtifactInRepository = new MavenArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getBaseVersion(), dependencyType, artifact.getClassifier(), artifact.getScope(), artifact.isOptional(), artifact.getExtension(), null, myMavenProject.getLocalRepository(), false, false);
                myRootModelAdapter.addLibraryDependency(projectsArtifactInRepository, scope, myModifiableModelsProvider, myMavenProject);
            } else {
                boolean isTestJar = MavenConstants.TYPE_TEST_JAR.equals(dependencyType) || "tests".equals(artifact.getClassifier());
                myRootModelAdapter.addModuleDependency(moduleName, scope, isTestJar);
                Element buildHelperCfg = depProject.getPluginGoalConfiguration("org.codehaus.mojo", "build-helper-maven-plugin", "attach-artifact");
                if (buildHelperCfg != null) {
                    addAttachArtifactDependency(buildHelperCfg, scope, depProject, artifact);
                }
                if (IMPORTED_CLASSIFIERS.contains(artifact.getClassifier()) && !isTestJar && !"system".equals(artifact.getScope()) && !"false".equals(System.getProperty("idea.maven.classifier.dep"))) {
                    MavenArtifact a = new MavenArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getBaseVersion(), dependencyType, artifact.getClassifier(), artifact.getScope(), artifact.isOptional(), artifact.getExtension(), null, myMavenProject.getLocalRepository(), false, false);
                    myRootModelAdapter.addLibraryDependency(a, scope, myModifiableModelsProvider, myMavenProject);
                }
            }
        } else if ("system".equals(artifact.getScope())) {
            myRootModelAdapter.addSystemDependency(artifact, scope);
        } else {
            myRootModelAdapter.addLibraryDependency(artifact, scope, myModifiableModelsProvider, myMavenProject);
        }
    }
    configSurefirePlugin();
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) Element(org.jdom.Element) MavenArtifact(org.jetbrains.idea.maven.model.MavenArtifact) THashSet(gnu.trove.THashSet)

Example 2 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.

the class MavenRootModelAdapter method addModuleDependency.

public void addModuleDependency(@NotNull String moduleName, @NotNull DependencyScope scope, boolean testJar) {
    Module m = findModuleByName(moduleName);
    ModuleOrderEntry e;
    if (m != null) {
        e = myRootModel.addModuleOrderEntry(m);
    } else {
        AccessToken accessToken = ReadAction.start();
        try {
            e = myRootModel.addInvalidModuleEntry(moduleName);
        } finally {
            accessToken.finish();
        }
    }
    e.setScope(scope);
    if (testJar) {
        ((ModuleOrderEntryImpl) e).setProductionOnTestDependency(true);
    }
    if (myOrderEntriesBeforeJdk.contains(moduleName)) {
        moveLastOrderEntryBeforeJdk();
    }
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) Module(com.intellij.openapi.module.Module) ModuleOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleOrderEntryImpl)

Example 3 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.

the class MavenJDOMUtil method read.

@Nullable
public static Element read(final VirtualFile file, @Nullable final ErrorHandler handler) {
    String text;
    AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
    try {
        if (!file.isValid())
            return null;
        try {
            text = VfsUtilCore.loadText(file);
        } catch (IOException e) {
            if (handler != null)
                handler.onReadError(e);
            return null;
        }
    } finally {
        accessToken.finish();
    }
    return doRead(text, handler);
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.

the class PyInitReferenceSearchExecutor method processQuery.

public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull final Processor<PsiReference> consumer) {
    PsiElement element = queryParameters.getElementToSearch();
    if (!(element instanceof PyFunction)) {
        return;
    }
    final AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
    String className;
    SearchScope searchScope;
    PyFunction function;
    try {
        function = (PyFunction) element;
        if (!PyNames.INIT.equals(function.getName())) {
            return;
        }
        final PyClass pyClass = function.getContainingClass();
        if (pyClass == null) {
            return;
        }
        className = pyClass.getName();
        if (className == null) {
            return;
        }
        searchScope = queryParameters.getEffectiveSearchScope();
        if (searchScope instanceof GlobalSearchScope) {
            searchScope = GlobalSearchScope.getScopeRestrictedByFileTypes((GlobalSearchScope) searchScope, PythonFileType.INSTANCE);
        }
    } finally {
        accessToken.finish();
    }
    queryParameters.getOptimizer().searchWord(className, searchScope, UsageSearchContext.IN_CODE, true, function);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyFunction(com.jetbrains.python.psi.PyFunction) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) AccessToken(com.intellij.openapi.application.AccessToken) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) PsiElement(com.intellij.psi.PsiElement)

Example 5 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.

the class PyOverridingMethodsSearchExecutor method execute.

public boolean execute(@NotNull final PyOverridingMethodsSearch.SearchParameters queryParameters, @NotNull final Processor<PyFunction> consumer) {
    final PyFunction baseMethod = queryParameters.getFunction();
    final PyClass containingClass = ApplicationManager.getApplication().runReadAction(new Computable<PyClass>() {

        @Override
        public PyClass compute() {
            return baseMethod.getContainingClass();
        }
    });
    return PyClassInheritorsSearch.search(containingClass, queryParameters.isCheckDeep()).forEach(pyClass -> {
        final AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
        PyFunction overridingMethod;
        try {
            overridingMethod = pyClass.findMethodByName(baseMethod.getName(), false, null);
            if (overridingMethod != null) {
                final Property baseProperty = baseMethod.getProperty();
                final Property overridingProperty = overridingMethod.getProperty();
                if (baseProperty != null && overridingProperty != null) {
                    final AccessDirection direction = PyUtil.getPropertyAccessDirection(baseMethod);
                    final PyCallable callable = overridingProperty.getByDirection(direction).valueOrNull();
                    overridingMethod = (callable instanceof PyFunction) ? (PyFunction) callable : null;
                }
            }
        } finally {
            accessToken.finish();
        }
        if (overridingMethod != null) {
            return consumer.process(overridingMethod);
        }
        return true;
    });
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken)

Aggregations

AccessToken (com.intellij.openapi.application.AccessToken)97 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 Nullable (org.jetbrains.annotations.Nullable)15 Module (com.intellij.openapi.module.Module)13 Project (com.intellij.openapi.project.Project)12 Document (com.intellij.openapi.editor.Document)10 GitRepository (git4idea.repo.GitRepository)9 ArrayList (java.util.ArrayList)9 PsiElement (com.intellij.psi.PsiElement)7 NotNull (org.jetbrains.annotations.NotNull)6 File (java.io.File)5 IOException (java.io.IOException)5 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)4 PsiFile (com.intellij.psi.PsiFile)4 List (java.util.List)4 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)4 ReadAction (com.intellij.openapi.application.ReadAction)3 CompileContext (com.intellij.openapi.compiler.CompileContext)3 CompileTask (com.intellij.openapi.compiler.CompileTask)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3