Search in sources :

Example 6 with Computable

use of com.intellij.openapi.util.Computable in project intellij-community by JetBrains.

the class RegExResponseHandler method parseIssues.

@NotNull
@Override
public Task[] parseIssues(@NotNull String response, int max) throws Exception {
    final List<String> placeholders = getPlaceholders(myTaskRegex);
    if (!placeholders.contains(ID_PLACEHOLDER) || !placeholders.contains(SUMMARY_PLACEHOLDER)) {
        throw new Exception("Incorrect Task Pattern");
    }
    final String taskPatternWithoutPlaceholders = myTaskRegex.replaceAll("\\{.+?\\}", "");
    Matcher matcher = Pattern.compile(taskPatternWithoutPlaceholders, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL | Pattern.UNICODE_CASE | Pattern.CANON_EQ).matcher(response);
    List<Task> tasks = new ArrayList<>();
    for (int i = 0; i < max && matcher.find(); i++) {
        String id = matcher.group(placeholders.indexOf(ID_PLACEHOLDER) + 1);
        String summary = matcher.group(placeholders.indexOf(SUMMARY_PLACEHOLDER) + 1);
        // temporary workaround to make AssemblaIntegrationTestPass
        final String finalSummary = summary;
        summary = ApplicationManager.getApplication().runReadAction(new Computable<String>() {

            @Override
            public String compute() {
                XmlElementFactory factory = XmlElementFactory.getInstance(ProjectManager.getInstance().getDefaultProject());
                XmlTag text = factory.createTagFromText("<a>" + finalSummary + "</a>");
                String trimmedText = text.getValue().getTrimmedText();
                return XmlUtil.decode(trimmedText);
            }
        });
        tasks.add(new GenericTask(id, summary, myRepository));
    }
    return tasks.toArray(new Task[tasks.size()]);
}
Also used : Task(com.intellij.tasks.Task) Matcher(java.util.regex.Matcher) XmlElementFactory(com.intellij.psi.XmlElementFactory) ArrayList(java.util.ArrayList) Computable(com.intellij.openapi.util.Computable) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with Computable

use of com.intellij.openapi.util.Computable in project smali by JesusFreke.

the class SmaliPositionManager method createPrepareRequest.

@Override
public ClassPrepareRequest createPrepareRequest(@NotNull final ClassPrepareRequestor requestor, @NotNull final SourcePosition position) throws NoDataException {
    Computable<Boolean> isSmaliFile = new Computable<Boolean>() {

        @Override
        public Boolean compute() {
            return position.getFile() instanceof SmaliFile;
        }
    };
    ApplicationManager.getApplication().runReadAction(isSmaliFile);
    if (!isSmaliFile.compute()) {
        throw NoDataException.INSTANCE;
    }
    String className = getClassFromPosition(position);
    return debugProcess.getRequestsManager().createClassPrepareRequest(new ClassPrepareRequestor() {

        @Override
        public void processClassPrepare(DebugProcess debuggerProcess, ReferenceType referenceType) {
            requestor.processClassPrepare(debuggerProcess, referenceType);
        }
    }, className);
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) ClassPrepareRequestor(com.intellij.debugger.requests.ClassPrepareRequestor) DebugProcess(com.intellij.debugger.engine.DebugProcess) Computable(com.intellij.openapi.util.Computable) ReferenceType(com.sun.jdi.ReferenceType)

Example 8 with Computable

use of com.intellij.openapi.util.Computable in project intellij-community by JetBrains.

the class RequestHint method getNextStepDepth.

public int getNextStepDepth(final SuspendContextImpl context) {
    try {
        final StackFrameProxyImpl frameProxy = context.getFrameProxy();
        // smart step feature stop check
        if (myMethodFilter != null && frameProxy != null && !(myMethodFilter instanceof BreakpointStepMethodFilter) && myMethodFilter.locationMatches(context.getDebugProcess(), frameProxy.location()) && !isTheSameFrame(context)) {
            myTargetMethodMatched = true;
            return myMethodFilter.onReached(context, this);
        }
        if ((myDepth == StepRequest.STEP_OVER || myDepth == StepRequest.STEP_INTO) && myPosition != null) {
            SourcePosition locationPosition = ContextUtil.getSourcePosition(context);
            if (locationPosition != null) {
                Integer resultDepth = ApplicationManager.getApplication().runReadAction(new Computable<Integer>() {

                    public Integer compute() {
                        if (myPosition.getFile().equals(locationPosition.getFile()) && isTheSameFrame(context) && !mySteppedOut) {
                            return isOnTheSameLine(locationPosition) ? myDepth : STOP;
                        }
                        return null;
                    }
                });
                if (resultDepth != null) {
                    return resultDepth.intValue();
                }
            }
        }
        // Now check filters
        final DebuggerSettings settings = DebuggerSettings.getInstance();
        if ((myMethodFilter != null || (settings.SKIP_SYNTHETIC_METHODS && !myIgnoreFilters)) && frameProxy != null) {
            final Location location = frameProxy.location();
            if (location != null) {
                if (DebuggerUtils.isSynthetic(location.method())) {
                    return myDepth;
                }
            }
        }
        if (!myIgnoreFilters) {
            if (settings.SKIP_GETTERS) {
                boolean isGetter = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {

                    public Boolean compute() {
                        PsiElement contextElement = ContextUtil.getContextElement(context);
                        return contextElement != null && DebuggerUtils.isInsideSimpleGetter(contextElement);
                    }
                }).booleanValue();
                if (isGetter) {
                    return StepRequest.STEP_OUT;
                }
            }
            if (frameProxy != null) {
                if (settings.SKIP_CONSTRUCTORS) {
                    final Location location = frameProxy.location();
                    if (location != null) {
                        final Method method = location.method();
                        if (method != null && method.isConstructor()) {
                            return StepRequest.STEP_OUT;
                        }
                    }
                }
                if (settings.SKIP_CLASSLOADERS) {
                    final Location location = frameProxy.location();
                    if (location != null && DebuggerUtilsEx.isAssignableFrom("java.lang.ClassLoader", location.declaringType())) {
                        return StepRequest.STEP_OUT;
                    }
                }
            }
            for (ExtraSteppingFilter filter : ExtraSteppingFilter.EP_NAME.getExtensions()) {
                try {
                    if (filter.isApplicable(context))
                        return filter.getStepRequestDepth(context);
                } catch (Exception | AssertionError e) {
                    LOG.error(e);
                }
            }
        }
        // smart step feature
        if (myMethodFilter != null && !mySteppedOut) {
            return StepRequest.STEP_OUT;
        }
    } catch (VMDisconnectedException ignored) {
    } catch (EvaluateException e) {
        LOG.error(e);
    }
    return STOP;
}
Also used : StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) DebuggerSettings(com.intellij.debugger.settings.DebuggerSettings) Method(com.sun.jdi.Method) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) VMDisconnectedException(com.sun.jdi.VMDisconnectedException) VMDisconnectedException(com.sun.jdi.VMDisconnectedException) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) SourcePosition(com.intellij.debugger.SourcePosition) Computable(com.intellij.openapi.util.Computable) PsiElement(com.intellij.psi.PsiElement) Location(com.sun.jdi.Location)

Example 9 with Computable

use of com.intellij.openapi.util.Computable in project intellij-community by JetBrains.

the class ModuleChunk method getChunkSpecificCompileOptions.

public String getChunkSpecificCompileOptions() {
    final StringBuilder options = new StringBuilder();
    final Charset encoding = CompilerEncodingService.getInstance(getProject()).getPreferredModuleEncoding(myMainModule);
    if (encoding != null) {
        appendOption(options, "-encoding", encoding.name());
    }
    final String languageLevel = getLanguageLevelOption(ApplicationManager.getApplication().runReadAction(new Computable<LanguageLevel>() {

        @Override
        public LanguageLevel compute() {
            return EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(myMainModule);
        }
    }));
    appendOption(options, "-source", languageLevel);
    String bytecodeTarget = CompilerConfiguration.getInstance(getProject()).getBytecodeTargetLevel(myMainModule);
    if (StringUtil.isEmpty(bytecodeTarget)) {
        // according to IDEA rule: if not specified explicitly, set target to be the same as source language level
        bytecodeTarget = languageLevel;
    }
    appendOption(options, "-target", bytecodeTarget);
    return options.toString();
}
Also used : Charset(java.nio.charset.Charset) Computable(com.intellij.openapi.util.Computable)

Example 10 with Computable

use of com.intellij.openapi.util.Computable in project intellij-community by JetBrains.

the class ModuleCompileScope method belongs.

public boolean belongs(final String url) {
    if (myScopeModules.isEmpty()) {
        // optimization
        return false;
    }
    Module candidateModule = null;
    int maxUrlLength = 0;
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
    for (final Module module : myModules) {
        final String[] contentRootUrls = getModuleContentUrls(module);
        for (final String contentRootUrl : contentRootUrls) {
            if (contentRootUrl.length() < maxUrlLength) {
                continue;
            }
            if (!isUrlUnderRoot(url, contentRootUrl)) {
                continue;
            }
            if (contentRootUrl.length() == maxUrlLength) {
                if (candidateModule == null) {
                    candidateModule = module;
                } else {
                    // the same content root exists in several modules
                    if (!candidateModule.equals(module)) {
                        candidateModule = ApplicationManager.getApplication().runReadAction(new Computable<Module>() {

                            public Module compute() {
                                final VirtualFile contentRootFile = VirtualFileManager.getInstance().findFileByUrl(contentRootUrl);
                                if (contentRootFile != null) {
                                    return projectFileIndex.getModuleForFile(contentRootFile);
                                }
                                return null;
                            }
                        });
                    }
                }
            } else {
                maxUrlLength = contentRootUrl.length();
                candidateModule = module;
            }
        }
    }
    if (candidateModule != null && myScopeModules.contains(candidateModule)) {
        final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(candidateModule);
        final String[] excludeRootUrls = moduleRootManager.getExcludeRootUrls();
        for (String excludeRootUrl : excludeRootUrls) {
            if (isUrlUnderRoot(url, excludeRootUrl)) {
                return false;
            }
        }
        final String[] sourceRootUrls = moduleRootManager.getSourceRootUrls();
        for (String sourceRootUrl : sourceRootUrls) {
            if (isUrlUnderRoot(url, sourceRootUrl)) {
                return true;
            }
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Module(com.intellij.openapi.module.Module) Computable(com.intellij.openapi.util.Computable)

Aggregations

Computable (com.intellij.openapi.util.Computable)49 VirtualFile (com.intellij.openapi.vfs.VirtualFile)15 NotNull (org.jetbrains.annotations.NotNull)11 Nullable (org.jetbrains.annotations.Nullable)11 Project (com.intellij.openapi.project.Project)10 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)8 PsiFile (com.intellij.psi.PsiFile)6 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)6 IncorrectOperationException (com.intellij.util.IncorrectOperationException)6 Application (com.intellij.openapi.application.Application)5 Task (com.intellij.openapi.progress.Task)5 IOException (java.io.IOException)5 ApplicationManager (com.intellij.openapi.application.ApplicationManager)4 Editor (com.intellij.openapi.editor.Editor)4 Ref (com.intellij.openapi.util.Ref)4 Module (com.intellij.openapi.module.Module)3 PsiDirectory (com.intellij.psi.PsiDirectory)3 PsiElement (com.intellij.psi.PsiElement)3 UsageInfo (com.intellij.usageView.UsageInfo)3 Logger (com.intellij.openapi.diagnostic.Logger)2