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()]);
}
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);
}
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;
}
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();
}
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;
}
Aggregations