use of com.intellij.openapi.util.Trinity in project kotlin by JetBrains.
the class FrameMap method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (myVarIndex.size() != myVarSizes.size()) {
return "inconsistent";
}
List<Trinity<DeclarationDescriptor, Integer, Integer>> descriptors = Lists.newArrayList();
for (Object descriptor0 : myVarIndex.keys()) {
DeclarationDescriptor descriptor = (DeclarationDescriptor) descriptor0;
int varIndex = myVarIndex.get(descriptor);
int varSize = myVarSizes.get(descriptor);
descriptors.add(Trinity.create(descriptor, varIndex, varSize));
}
Collections.sort(descriptors, new Comparator<Trinity<DeclarationDescriptor, Integer, Integer>>() {
@Override
public int compare(Trinity<DeclarationDescriptor, Integer, Integer> left, Trinity<DeclarationDescriptor, Integer, Integer> right) {
return left.second - right.second;
}
});
sb.append("size=").append(myMaxIndex);
boolean first = true;
for (Trinity<DeclarationDescriptor, Integer, Integer> t : descriptors) {
if (!first) {
sb.append(", ");
}
first = false;
sb.append(t.first).append(",i=").append(t.second).append(",s=").append(t.third);
}
return sb.toString();
}
use of com.intellij.openapi.util.Trinity in project intellij-community by JetBrains.
the class MvcModuleStructureSynchronizer method scheduleRunActions.
private void scheduleRunActions() {
if (myProject.isDisposed())
return;
final Application app = ApplicationManager.getApplication();
if (app.isUnitTestMode()) {
if (ourGrailsTestFlag && !myProject.isInitialized()) {
runActions(computeRawActions(takeOrderSnapshot()));
}
return;
}
final Set<Pair<Object, SyncAction>> orderSnapshot = takeOrderSnapshot();
ReadTask task = new ReadTask() {
@Nullable
@Override
public Continuation performInReadAction(@NotNull final ProgressIndicator indicator) throws ProcessCanceledException {
final Set<Trinity<Module, SyncAction, MvcFramework>> actions = isUpToDate() ? computeRawActions(orderSnapshot) : Collections.<Trinity<Module, SyncAction, MvcFramework>>emptySet();
return new Continuation(() -> {
if (isUpToDate()) {
runActions(actions);
} else if (!indicator.isCanceled()) {
scheduleRunActions();
}
}, ModalityState.NON_MODAL);
}
@Override
public void onCanceled(@NotNull ProgressIndicator indicator) {
scheduleRunActions();
}
private boolean isUpToDate() {
return !myProject.isDisposed() && orderSnapshot.equals(takeOrderSnapshot());
}
};
GuiUtils.invokeLaterIfNeeded(() -> ProgressIndicatorUtils.scheduleWithWriteActionPriority(ourExecutor, task), ModalityState.NON_MODAL);
}
use of com.intellij.openapi.util.Trinity in project intellij-community by JetBrains.
the class AddAnnotationFixTest method testAnnotateLibrary.
public void testAnnotateLibrary() throws Throwable {
addDefaultLibrary();
myFixture.configureByFiles("lib/p/TestPrimitive.java", "content/anno/p/annotations.xml");
myFixture.configureByFiles("lib/p/Test.java");
final PsiFile file = myFixture.getFile();
final Editor editor = myFixture.getEditor();
// expecting other @Nullable annotations to be removed, and default @NotNull to be added
List<Trinity<PsiModifierListOwner, String, Boolean>> expectedSequence = new ArrayList<>();
for (String notNull : NullableNotNullManager.getInstance(myProject).getNullables()) {
expectedSequence.add(Trinity.create(getOwner(), notNull, false));
}
expectedSequence.add(Trinity.create(getOwner(), AnnotationUtil.NOT_NULL, true));
startListening(expectedSequence);
myFixture.launchAction(myFixture.findSingleIntention("Annotate method 'get' as @NotNull"));
FileDocumentManager.getInstance().saveAllDocuments();
final PsiElement psiElement = file.findElementAt(editor.getCaretModel().getOffset());
assertNotNull(psiElement);
final PsiModifierListOwner listOwner = PsiTreeUtil.getParentOfType(psiElement, PsiModifierListOwner.class);
assertNotNull(listOwner);
assertNotNull(ExternalAnnotationsManager.getInstance(myProject).findExternalAnnotation(listOwner, AnnotationUtil.NOT_NULL));
stopListeningAndCheckEvents();
myFixture.checkResultByFile("content/anno/p/annotations.xml", "content/anno/p/annotationsAnnotateLibrary_after.xml", false);
}
use of com.intellij.openapi.util.Trinity in project intellij-community by JetBrains.
the class GroovyConstructorNamedArgumentProvider method processClass.
public static void processClass(@NotNull GrCall call, PsiClassType type, @Nullable String argumentName, final Map<String, NamedArgumentDescriptor> result) {
if (argumentName == null) {
final HashMap<String, Trinity<PsiType, PsiElement, PsiSubstitutor>> map = ContainerUtil.newHashMap();
MyPsiScopeProcessor processor = new MyPsiScopeProcessor() {
@Override
protected void addNamedArgument(String propertyName, PsiType type, PsiElement element, PsiSubstitutor substitutor) {
if (result.containsKey(propertyName))
return;
Trinity<PsiType, PsiElement, PsiSubstitutor> pair = map.get(propertyName);
if (pair != null) {
if (element instanceof PsiMethod && pair.second instanceof PsiField) {
// methods should override fields
} else {
return;
}
}
map.put(propertyName, Trinity.create(type, element, substitutor));
}
};
processor.setResolveTargetKinds(ClassHint.RESOLVE_KINDS_METHOD_PROPERTY);
ResolveUtil.processAllDeclarations(type, processor, ResolveState.initial(), call);
for (Map.Entry<String, Trinity<PsiType, PsiElement, PsiSubstitutor>> entry : map.entrySet()) {
result.put(entry.getKey(), new TypeCondition(entry.getValue().first, entry.getValue().getSecond(), entry.getValue().getThird(), NamedArgumentDescriptor.Priority.AS_LOCAL_VARIABLE));
}
} else {
MyPsiScopeProcessor processor = new MyPsiScopeProcessor() {
@Override
protected void addNamedArgument(String propertyName, PsiType type, PsiElement element, PsiSubstitutor substitutor) {
if (result.containsKey(propertyName))
return;
result.put(propertyName, new TypeCondition(type, element, substitutor, NamedArgumentDescriptor.Priority.AS_LOCAL_VARIABLE));
}
};
processor.setResolveTargetKinds(ClassHint.RESOLVE_KINDS_METHOD);
processor.setNameHint(GroovyPropertyUtils.getSetterName(argumentName));
ResolveUtil.processAllDeclarations(type, processor, ResolveState.initial(), call);
processor.setResolveTargetKinds(ClassHint.RESOLVE_KINDS_PROPERTY);
processor.setNameHint(argumentName);
ResolveUtil.processAllDeclarations(type, processor, ResolveState.initial(), call);
}
}
use of com.intellij.openapi.util.Trinity in project intellij-community by JetBrains.
the class GdkMethodUtil method getClosureMixins.
private static Trinity<PsiClassType, GrReferenceExpression, List<GrMethod>> getClosureMixins(final GrStatement statement) {
if (!(statement instanceof GrAssignmentExpression))
return null;
final GrAssignmentExpression assignment = (GrAssignmentExpression) statement;
return CachedValuesManager.getCachedValue(statement, new CachedValueProvider<Trinity<PsiClassType, GrReferenceExpression, List<GrMethod>>>() {
@Nullable
@Override
public Result<Trinity<PsiClassType, GrReferenceExpression, List<GrMethod>>> compute() {
Pair<PsiClassType, GrReferenceExpression> original = getTypeToMixIn(assignment);
if (original == null)
return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
final Pair<GrSignature, String> signatures = getTypeToMix(assignment);
if (signatures == null)
return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
final String name = signatures.second;
final List<GrMethod> methods = ContainerUtil.newArrayList();
final PsiClass closure = JavaPsiFacade.getInstance(statement.getProject()).findClass(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, statement.getResolveScope());
if (closure == null)
return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
signatures.first.accept(new GrSignatureVisitor() {
@Override
public void visitClosureSignature(GrClosureSignature signature) {
super.visitClosureSignature(signature);
GrMethod method = createMethod(signature, name, assignment, closure);
methods.add(method);
}
});
return Result.create(Trinity.create(original.first, original.second, methods), PsiModificationTracker.MODIFICATION_COUNT);
}
});
}
Aggregations