use of com.intellij.openapi.util.Computable in project intellij-community by JetBrains.
the class MatcherImpl method prepareMatching.
private CompiledPattern prepareMatching(final MatchResultSink sink, final MatchOptions options) {
CompiledPattern savedPattern = null;
if (matchContext.getOptions() == options && matchContext.getPattern() != null && matchContext.getOptions().hashCode() == matchContext.getPattern().getOptionsHashStamp()) {
savedPattern = matchContext.getPattern();
}
matchContext.clear();
matchContext.setSink(new DuplicateFilteringResultSink(sink));
matchContext.setOptions(options);
matchContext.setMatcher(visitor);
visitor.setMatchContext(matchContext);
CompiledPattern compiledPattern = savedPattern;
if (compiledPattern == null) {
synchronized (lastMatchDataLock) {
final LastMatchData data = com.intellij.reference.SoftReference.dereference(lastMatchData);
if (data != null && options == data.lastOptions) {
compiledPattern = data.lastPattern;
}
lastMatchData = null;
}
if (compiledPattern == null) {
compiledPattern = ApplicationManager.getApplication().runReadAction(new Computable<CompiledPattern>() {
@Override
public CompiledPattern compute() {
return PatternCompiler.compilePattern(project, options);
}
});
}
}
cacheCompiledPattern(options, compiledPattern);
return compiledPattern;
}
use of com.intellij.openapi.util.Computable in project android by JetBrains.
the class AndroidGotoRelatedProvider method getLazyItemsForClass.
@Nullable
static Computable<List<GotoRelatedItem>> getLazyItemsForClass(@NotNull PsiClass aClass, @NotNull AndroidFacet facet, boolean addDeclarationInManifest) {
final GotoRelatedItem item = findDeclarationInManifest(aClass);
final boolean isContextClass = isInheritorOfContextClass(aClass, facet.getModule());
if (!isContextClass && item == null) {
return null;
}
final List<GotoRelatedItem> items;
if (isContextClass) {
items = new ArrayList<GotoRelatedItem>(collectRelatedLayoutFiles(facet, aClass));
if (addDeclarationInManifest) {
if (item != null) {
items.add(item);
}
}
if (items.isEmpty()) {
return null;
}
} else {
items = Collections.singletonList(item);
}
return new Computable<List<GotoRelatedItem>>() {
@Override
public List<GotoRelatedItem> compute() {
return items;
}
};
}
use of com.intellij.openapi.util.Computable in project android by JetBrains.
the class LayoutlibCallbackImpl method getXmlFileParser.
@Nullable
@Override
public XmlPullParser getXmlFileParser(String fileName) {
// layoutlib built-in directories
if (fileName.contains(EXPLODED_AAR) || fileName.contains(FD_LAYOUTLIB)) {
return null;
}
boolean token = RenderSecurityManager.enterSafeRegion(myCredential);
try {
VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(fileName);
if (virtualFile != null) {
PsiFile psiFile = AndroidPsiUtils.getPsiFileSafely(myModule.getProject(), virtualFile);
if (psiFile != null) {
try {
XmlPullParser parser = getParserFactory().createParser(fileName);
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
String psiText = ApplicationManager.getApplication().isReadAccessAllowed() ? psiFile.getText() : ApplicationManager.getApplication().runReadAction((Computable<String>) psiFile::getText);
parser.setInput(new StringReader(psiText));
return parser;
} catch (XmlPullParserException e) {
LOG.warn("Could not create parser for " + fileName);
}
}
}
return null;
} finally {
RenderSecurityManager.exitSafeRegion(token);
}
}
use of com.intellij.openapi.util.Computable in project android by JetBrains.
the class Template method render.
/**
* Executes the template, rendering it to output files under the directory context.getModuleRoot()
*
* @return true if the template was rendered without finding any errors and there are no warnings
* or the user selected to proceed with warnings.
*/
public boolean render(@NotNull final RenderingContext context) {
final Project project = context.getProject();
boolean success = runWriteCommandAction(project, context.getCommandName(), new Computable<Boolean>() {
@Override
public Boolean compute() {
if (project.isInitialized()) {
return doRender(context);
} else {
return PostprocessReformattingAspect.getInstance(project).disablePostprocessFormattingInside(new Computable<Boolean>() {
@Override
public Boolean compute() {
return doRender(context);
}
});
}
}
});
String title = myMetadata.getTitle();
if (title != null) {
UsageTracker.getInstance().log(AndroidStudioEvent.newBuilder().setCategory(EventCategory.TEMPLATE).setKind(AndroidStudioEvent.EventKind.TEMPLATE_RENDER).setTemplateRenderer(titleToTemplateRenderer(title)));
}
if (context.shouldReformat()) {
TemplateUtils.reformatAndRearrange(project, context.getTargetFiles());
}
return success;
}
use of com.intellij.openapi.util.Computable in project android by JetBrains.
the class CreateResourceFileAction method createValidatorFactory.
// Or we could pass the action down, the dialog will set the root element, and then it can choose how to
// create the validator on its own. On the other hand this is symmetric with the other dialogs.
@NotNull
private CreateResourceFileDialogBase.ValidatorFactory createValidatorFactory(@NotNull final Project project) {
return new CreateResourceFileDialogBase.ValidatorFactory() {
@Override
@NotNull
public ElementCreatingValidator create(@NotNull final PsiDirectory resourceDirectory, @NotNull final String subdirName, @Nullable String rootElement) {
PsiDirectory resSubdir = resourceDirectory.findSubdirectory(subdirName);
if (resSubdir == null) {
resSubdir = ApplicationManager.getApplication().runWriteAction((Computable<PsiDirectory>) () -> resourceDirectory.createSubdirectory(subdirName));
}
// Stash the chosen rootElement before action is asked to create() the elements.
myRootElement = rootElement;
return new MyInputValidator(project, resSubdir);
}
};
}
Aggregations