Search in sources :

Example 6 with AccessToken

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

the class ConvertConcatenationToGstringIntention method processIntention.

@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
    final PsiFile file = element.getContainingFile();
    final int offset = editor.getCaretModel().getOffset();
    final AccessToken accessToken = ReadAction.start();
    final List<GrExpression> expressions;
    try {
        expressions = collectExpressions(file, offset);
    } finally {
        accessToken.finish();
    }
    final Document document = editor.getDocument();
    if (expressions.size() == 1) {
        invokeImpl(expressions.get(0), document);
    } else if (!expressions.isEmpty()) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            invokeImpl(expressions.get(expressions.size() - 1), document);
            return;
        }
        IntroduceTargetChooser.showChooser(editor, expressions, new Pass<GrExpression>() {

            @Override
            public void pass(final GrExpression selectedValue) {
                invokeImpl(selectedValue, document);
            }
        }, grExpression -> grExpression.getText());
    }
}
Also used : TypeConversionUtil(com.intellij.psi.util.TypeConversionUtil) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) WriteAction(com.intellij.openapi.application.WriteAction) GrLiteralImpl(org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.literals.GrLiteralImpl) org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals) Document(com.intellij.openapi.editor.Document) ReadAction(com.intellij.openapi.application.ReadAction) ArrayList(java.util.ArrayList) AccessToken(com.intellij.openapi.application.AccessToken) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) GroovyCommonClassNames(org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames) Intention(org.jetbrains.plugins.groovy.intentions.base.Intention) Project(com.intellij.openapi.project.Project) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) IntroduceTargetChooser(com.intellij.refactoring.IntroduceTargetChooser) GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) PsiElementPredicate(org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate) GroovyTokenTypes(org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes) GrMethodCallExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression) GrStringUtil(org.jetbrains.plugins.groovy.lang.psi.util.GrStringUtil) MethodSignatureUtil(com.intellij.psi.util.MethodSignatureUtil) IncorrectOperationException(com.intellij.util.IncorrectOperationException) GroovyRecursiveElementVisitor(org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor) TypesUtil(org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil) Editor(com.intellij.openapi.editor.Editor) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) CommandProcessor(com.intellij.openapi.command.CommandProcessor) Nullable(org.jetbrains.annotations.Nullable) GrBinaryExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression) List(java.util.List) Pass(com.intellij.openapi.util.Pass) ErrorUtil(org.jetbrains.plugins.groovy.lang.psi.util.ErrorUtil) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) PsiUtil(org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil) Pass(com.intellij.openapi.util.Pass) AccessToken(com.intellij.openapi.application.AccessToken) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) Document(com.intellij.openapi.editor.Document)

Example 7 with AccessToken

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

the class MavenProjectsManager method initComponent.

@Override
public void initComponent() {
    if (!isNormalProject())
        return;
    StartupManagerEx startupManager = StartupManagerEx.getInstanceEx(myProject);
    startupManager.registerStartupActivity(() -> {
        boolean wasMavenized = !myState.originalFiles.isEmpty();
        if (!wasMavenized)
            return;
        initMavenized();
    });
    startupManager.registerPostStartupActivity(() -> {
        if (!isMavenizedProject()) {
            showNotificationOrphanMavenProject(myProject);
        }
        CompilerManager.getInstance(myProject).addBeforeTask(new CompileTask() {

            @Override
            public boolean execute(CompileContext context) {
                AccessToken token = ReadAction.start();
                try {
                    new MavenResourceCompilerConfigurationGenerator(myProject, myProjectsTree).generateBuildConfiguration(context.isRebuild());
                } finally {
                    token.finish();
                }
                return true;
            }
        });
    });
}
Also used : CompileTask(com.intellij.openapi.compiler.CompileTask) StartupManagerEx(com.intellij.ide.startup.StartupManagerEx) AccessToken(com.intellij.openapi.application.AccessToken) CompileContext(com.intellij.openapi.compiler.CompileContext)

Example 8 with AccessToken

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

the class MavenArtifactDownloader method collectArtifactsToDownload.

private Map<MavenId, DownloadData> collectArtifactsToDownload(List<MavenExtraArtifactType> types) {
    Map<MavenId, DownloadData> result = new THashMap<>();
    THashSet<String> dependencyTypesFromSettings = new THashSet<>();
    AccessToken accessToken = ReadAction.start();
    try {
        if (myProject.isDisposed())
            return result;
        dependencyTypesFromSettings.addAll(MavenProjectsManager.getInstance(myProject).getImportingSettings().getDependencyTypesAsSet());
    } finally {
        accessToken.finish();
    }
    for (MavenProject eachProject : myMavenProjects) {
        List<MavenRemoteRepository> repositories = eachProject.getRemoteRepositories();
        for (MavenArtifact eachDependency : eachProject.getDependencies()) {
            if (myArtifacts != null && !myArtifacts.contains(eachDependency))
                continue;
            if (MavenConstants.SCOPE_SYSTEM.equalsIgnoreCase(eachDependency.getScope()))
                continue;
            if (myProjectsTree.findProject(eachDependency.getMavenId()) != null)
                continue;
            String dependencyType = eachDependency.getType();
            if (!dependencyTypesFromSettings.contains(dependencyType) && !eachProject.getDependencyTypesFromImporters(SupportedRequestType.FOR_IMPORT).contains(dependencyType)) {
                continue;
            }
            MavenId id = eachDependency.getMavenId();
            DownloadData data = result.get(id);
            if (data == null) {
                data = new DownloadData();
                result.put(id, data);
            }
            data.repositories.addAll(repositories);
            for (MavenExtraArtifactType eachType : types) {
                Pair<String, String> classifierAndExtension = eachProject.getClassifierAndExtension(eachDependency, eachType);
                String classifier = eachDependency.getFullClassifier(classifierAndExtension.first);
                String extension = classifierAndExtension.second;
                data.classifiersWithExtensions.add(new DownloadElement(classifier, extension, eachType));
            }
        }
    }
    return result;
}
Also used : THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) AccessToken(com.intellij.openapi.application.AccessToken) MavenExtraArtifactType(org.jetbrains.idea.maven.importing.MavenExtraArtifactType)

Example 9 with AccessToken

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

the class SpringLoadedPositionManager method getOuterClassName.

@Nullable
private static String getOuterClassName(final SourcePosition position) {
    AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
    try {
        PsiElement element = findElementAt(position);
        if (element == null)
            return null;
        PsiElement sourceImage = PsiTreeUtil.getParentOfType(element, GrClosableBlock.class, GrTypeDefinition.class, PsiClassImpl.class);
        if (sourceImage instanceof PsiClass) {
            return getClassNameForJvm((PsiClass) sourceImage);
        }
        return null;
    } finally {
        accessToken.finish();
    }
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with AccessToken

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

the class SpringLoadedPositionManager method getAllClasses.

@NotNull
@Override
public List<ReferenceType> getAllClasses(@NotNull final SourcePosition classPosition) throws NoDataException {
    int line;
    String className;
    AccessToken accessToken = ReadAction.start();
    try {
        className = findEnclosingName(classPosition);
        if (className == null)
            throw NoDataException.INSTANCE;
        line = classPosition.getLine();
    } finally {
        accessToken.finish();
    }
    List<ReferenceType> referenceTypes = myDebugProcess.getVirtualMachineProxy().classesByName(className);
    if (referenceTypes.isEmpty())
        throw NoDataException.INSTANCE;
    Set<ReferenceType> res = new HashSet<>();
    for (ReferenceType referenceType : referenceTypes) {
        findNested(res, referenceType, line);
    }
    if (res.isEmpty()) {
        throw NoDataException.INSTANCE;
    }
    return new ArrayList<>(res);
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) ArrayList(java.util.ArrayList) ReferenceType(com.sun.jdi.ReferenceType) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

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