use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class BackwardReferenceIndexUtil method registerFile.
static void registerFile(String filePath, Collection<? extends JavacRef> refs, List<JavacDef> defs, final BackwardReferenceIndexWriter writer) {
try {
final int fileId = writer.enumeratePath(filePath);
int funExprId = 0;
final Map<LightRef, Void> definitions = new HashMap<>(defs.size());
final Map<LightRef, Collection<LightRef>> backwardHierarchyMap = new HashMap<>();
for (JavacDef def : defs) {
if (def instanceof JavacDef.JavacClassDef) {
JavacRef.JavacClass sym = (JavacRef.JavacClass) def.getDefinedElement();
final LightRef.JavaLightClassRef aClass = writer.asClassUsage(sym);
definitions.put(aClass, null);
final JavacRef[] superClasses = ((JavacDef.JavacClassDef) def).getSuperClasses();
for (JavacRef superClass : superClasses) {
LightRef.JavaLightClassRef superClassRef = writer.asClassUsage(superClass);
Collection<LightRef> children = backwardHierarchyMap.get(superClassRef);
if (children == null) {
backwardHierarchyMap.put(superClassRef, children = new SmartList<>());
}
children.add(aClass);
}
} else if (def instanceof JavacDef.JavacFunExprDef) {
final LightRef.JavaLightClassRef functionalType = writer.asClassUsage(def.getDefinedElement());
int id = funExprId++;
LightRef.JavaLightFunExprDef result = new LightRef.JavaLightFunExprDef(id);
definitions.put(result, null);
ContainerUtil.getOrCreate(backwardHierarchyMap, functionalType, (Factory<Collection<LightRef>>) () -> new SmartList<>()).add(result);
}
}
Map<LightRef, Void> convertedRefs = new HashMap<>(refs.size());
for (JavacRef ref : refs) {
LightRef key = writer.enumerateNames(ref);
if (key != null) {
convertedRefs.put(key, null);
}
}
writer.writeData(fileId, new CompiledFileData(backwardHierarchyMap, convertedRefs, definitions));
} catch (IOException e) {
writer.setRebuildCause(e);
}
}
use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class DocumentCommitThread method commitUnderProgress.
// returns (finish commit Runnable (to be invoked later in EDT), null) on success or (null, failure reason) on failure
@NotNull
private Pair<Runnable, Object> commitUnderProgress(@NotNull final CommitTask task, final boolean synchronously) {
if (synchronously) {
assert !task.indicator.isCanceled();
}
final Document document = task.getDocument();
final Project project = task.project;
final PsiDocumentManagerBase documentManager = (PsiDocumentManagerBase) PsiDocumentManager.getInstance(project);
final List<Processor<Document>> finishProcessors = new SmartList<>();
Runnable runnable = () -> {
myApplication.assertReadAccessAllowed();
if (project.isDisposed())
return;
Lock lock = getDocumentLock(document);
if (!lock.tryLock()) {
task.cancel("Can't obtain document lock", this);
return;
}
boolean canceled = false;
try {
if (documentManager.isCommitted(document))
return;
if (!task.isStillValid()) {
canceled = true;
return;
}
FileViewProvider viewProvider = documentManager.getCachedViewProvider(document);
if (viewProvider == null) {
finishProcessors.add(handleCommitWithoutPsi(documentManager, task));
return;
}
for (Pair<PsiFileImpl, FileASTNode> pair : task.myOldFileNodes) {
PsiFileImpl file = pair.first;
if (file.isValid()) {
FileASTNode oldFileNode = pair.second;
Processor<Document> finishProcessor = doCommit(task, file, oldFileNode);
if (finishProcessor != null) {
finishProcessors.add(finishProcessor);
}
} else {
// file became invalid while sitting in the queue
if (task.reason.equals(SYNC_COMMIT_REASON)) {
throw new PsiInvalidElementAccessException(file, "File " + file + " invalidated during sync commit");
}
commitAsynchronously(project, document, "File " + file + " invalidated during background commit; task: " + task, task.myCreationContext);
}
}
} finally {
lock.unlock();
if (canceled) {
task.cancel("Task invalidated", this);
}
}
};
if (synchronously) {
runnable.run();
} else if (!myApplication.tryRunReadAction(runnable)) {
log(project, "Could not start read action", task, myApplication.isReadAccessAllowed(), Thread.currentThread());
return new Pair<>(null, "Could not start read action");
}
boolean canceled = task.indicator.isCanceled();
assert !synchronously || !canceled;
if (canceled) {
return new Pair<>(null, "Indicator was canceled");
}
Runnable result = createEdtRunnable(task, synchronously, finishProcessors);
return Pair.create(result, null);
}
use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class ToggleTaskActivationAction method getTasks.
@NotNull
private static List<TaskData> getTasks(AnActionEvent e) {
final List<ExternalSystemNode> selectedNodes = ExternalSystemDataKeys.SELECTED_NODES.getData(e.getDataContext());
if (selectedNodes == null)
return Collections.emptyList();
List<TaskData> tasks = new SmartList<>();
for (ExternalSystemNode node : selectedNodes) {
if (node instanceof TaskNode && !node.isIgnored()) {
tasks.add((TaskData) node.getData());
} else if (node instanceof RunConfigurationNode) {
final RunnerAndConfigurationSettings configurationSettings = ((RunConfigurationNode) node).getSettings();
final ExternalSystemRunConfiguration runConfiguration = (ExternalSystemRunConfiguration) configurationSettings.getConfiguration();
final ExternalSystemTaskExecutionSettings taskExecutionSettings = runConfiguration.getSettings();
tasks.add(new TaskData(taskExecutionSettings.getExternalSystemId(), RUN_CONFIGURATION_TASK_PREFIX + configurationSettings.getName(), taskExecutionSettings.getExternalProjectPath(), null));
} else {
return Collections.emptyList();
}
}
return tasks;
}
use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class PatternValidator method checkExpression.
private void checkExpression(PsiExpression expression, final PsiAnnotation[] annotations, ProblemsHolder holder) {
if (annotations.length == 0)
return;
final PsiAnnotation psiAnnotation = annotations[0];
// cache compiled pattern with annotation
CachedValue<Pattern> p = psiAnnotation.getUserData(COMPLIED_PATTERN);
if (p == null) {
final CachedValueProvider<Pattern> provider = () -> {
final String pattern = AnnotationUtilEx.calcAnnotationValue(psiAnnotation, "value");
Pattern p1 = null;
if (pattern != null) {
try {
p1 = Pattern.compile(pattern);
} catch (PatternSyntaxException e) {
// pattern stays null
}
}
return CachedValueProvider.Result.create(p1, (Object[]) annotations);
};
p = CachedValuesManager.getManager(expression.getProject()).createCachedValue(provider, false);
psiAnnotation.putUserData(COMPLIED_PATTERN, p);
}
final Pattern pattern = p.getValue();
if (pattern == null)
return;
List<PsiExpression> nonConstantElements = new SmartList<>();
final Object result = new SubstitutedExpressionEvaluationHelper(expression.getProject()).computeExpression(expression, myConfiguration.getAdvancedConfiguration().getDfaOption(), false, nonConstantElements);
final String o = result == null ? null : String.valueOf(result);
if (o != null) {
if (!pattern.matcher(o).matches()) {
if (annotations.length > 1) {
// the last element contains the element's actual annotation
final String fqn = annotations[annotations.length - 1].getQualifiedName();
assert fqn != null;
final String name = StringUtil.getShortName(fqn);
holder.registerProblem(expression, MessageFormat.format("Expression ''{0}'' doesn''t match ''{1}'' pattern: {2}", o, name, pattern.pattern()));
} else {
holder.registerProblem(expression, MessageFormat.format("Expression ''{0}'' doesn''t match pattern: {1}", o, pattern.pattern()));
}
}
} else if (CHECK_NON_CONSTANT_VALUES) {
for (PsiExpression expr : nonConstantElements) {
final PsiElement e;
if (expr instanceof PsiReferenceExpression) {
e = ((PsiReferenceExpression) expr).resolve();
} else if (expr instanceof PsiMethodCallExpression) {
e = ((PsiMethodCallExpression) expr).getMethodExpression().resolve();
} else {
e = expr;
}
final PsiModifierListOwner owner = e instanceof PsiModifierListOwner ? (PsiModifierListOwner) e : null;
LocalQuickFix quickFix;
if (owner != null && PsiUtilEx.isLanguageAnnotationTarget(owner)) {
PsiAnnotation[] resolvedAnnos = AnnotationUtilEx.getAnnotationFrom(owner, myConfiguration.getAdvancedConfiguration().getPatternAnnotationPair(), true);
if (resolvedAnnos.length == 2 && annotations.length == 2 && Comparing.strEqual(resolvedAnnos[1].getQualifiedName(), annotations[1].getQualifiedName())) {
// both target and source annotated indirectly with the same anno
return;
}
final String classname = myConfiguration.getAdvancedConfiguration().getSubstAnnotationPair().first;
quickFix = AnnotateFix.canApplyOn(owner) ? new AnnotateFix(classname) : new IntroduceVariableFix();
} else {
quickFix = new IntroduceVariableFix();
}
holder.registerProblem(expr, "Unsubstituted expression", quickFix);
}
}
}
use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class IPPTestCase method assertIntentionNotAvailable.
protected void assertIntentionNotAvailable(Class<? extends IntentionAction> intentionClass) {
myFixture.configureByFile(getTestName(false) + ".java");
final List<IntentionAction> result = new SmartList<>();
for (final IntentionAction intention : myFixture.getAvailableIntentions()) {
if (intentionClass.isInstance(intention)) {
result.add(intention);
} else if (intention instanceof IntentionActionWrapper) {
final IntentionActionWrapper wrapper = (IntentionActionWrapper) intention;
if (intentionClass.isInstance(wrapper.getDelegate())) {
result.add(intention);
}
}
}
assertEmpty("Intention of class \'" + intentionClass + "\' is available but should not", result);
}
Aggregations