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);
}
});
}
use of com.intellij.openapi.util.Trinity in project intellij-plugins by JetBrains.
the class MxmlUtil method computeEffectiveClass.
static Trinity<Integer, String, Condition<AnnotationBackedDescriptor>> computeEffectiveClass(final PsiElement element, final PsiElement declaration, final ProjectComponentReferenceCounter projectComponentReferenceCounter, final boolean computePropertyFilter) throws InvalidPropertyException {
PsiFile psiFile = declaration.getContainingFile();
VirtualFile virtualFile = psiFile.getVirtualFile();
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(psiFile.getProject()).getFileIndex();
LOG.assertTrue(virtualFile != null);
if (!projectFileIndex.isInSourceContent(virtualFile)) {
return NON_PROJECT_CLASS;
}
if (psiFile instanceof XmlFile) {
return new Trinity<>(DocumentFactoryManager.getInstance().getId(virtualFile, (XmlFile) psiFile, projectComponentReferenceCounter), null, null);
}
final Set<PsiFile> filteredFiles;
if (computePropertyFilter) {
filteredFiles = new THashSet<>();
filteredFiles.add(psiFile);
} else {
filteredFiles = null;
}
final JSClass aClass = (JSClass) declaration;
JSClass[] classes;
while ((classes = aClass.getSuperClasses()).length > 0) {
JSClass parentClass = classes[0];
PsiFile containingFile = parentClass.getContainingFile();
//noinspection ConstantConditions
if (!projectFileIndex.isInSourceContent(containingFile.getVirtualFile())) {
return new Trinity<>(-1, parentClass.getQualifiedName(), computePropertyFilter ? new CustomComponentPropertyFilter(filteredFiles) : null);
} else if (computePropertyFilter) {
filteredFiles.add(containingFile);
}
}
// well, it must be at least mx.core.UIComponent or spark.primitives.supportClasses.GraphicElement
throw new InvalidPropertyException(element, "unresolved.class", aClass.getQualifiedName());
}
use of com.intellij.openapi.util.Trinity in project intellij-community by JetBrains.
the class PackageFileWorker method packageFile.
public static void packageFile(@NotNull VirtualFile file, @NotNull Project project, final Artifact[] artifacts, final boolean packIntoArchives) throws IOException {
LOG.debug("Start packaging file: " + file.getPath());
final Collection<Trinity<Artifact, PackagingElementPath, String>> items = ArtifactUtil.findContainingArtifactsWithOutputPaths(file, project, artifacts);
File ioFile = VfsUtilCore.virtualToIoFile(file);
for (Trinity<Artifact, PackagingElementPath, String> item : items) {
final Artifact artifact = item.getFirst();
final String outputPath = artifact.getOutputPath();
if (!StringUtil.isEmpty(outputPath)) {
PackageFileWorker worker = new PackageFileWorker(ioFile, item.getThird(), packIntoArchives);
LOG.debug(" package to " + outputPath);
worker.packageFile(outputPath, item.getSecond().getParents());
}
}
}
use of com.intellij.openapi.util.Trinity in project intellij-community by JetBrains.
the class JsonSchemaWalker method extractSchemaVariants.
public static void extractSchemaVariants(@NotNull final Project project, @NotNull final CompletionSchemesConsumer consumer, @NotNull VirtualFile rootSchemaFile, @NotNull JsonSchemaObject rootSchema, boolean isName, List<Step> position, boolean acceptAdditionalPropertiesSchemas) {
final Set<Trinity<JsonSchemaObject, VirtualFile, List<Step>>> control = new HashSet<>();
final JsonSchemaServiceEx serviceEx = JsonSchemaServiceEx.Impl.getEx(project);
final ArrayDeque<Trinity<JsonSchemaObject, VirtualFile, List<Step>>> queue = new ArrayDeque<>();
queue.add(Trinity.create(rootSchema, rootSchemaFile, position));
while (!queue.isEmpty()) {
final Trinity<JsonSchemaObject, VirtualFile, List<Step>> trinity = queue.removeFirst();
if (!control.add(trinity))
break;
final JsonSchemaObject object = trinity.getFirst();
final VirtualFile schemaFile = trinity.getSecond();
final List<Step> path = trinity.getThird();
if (path.isEmpty()) {
consumer.consume(isName, object, schemaFile, path);
continue;
}
final DefinitionsResolver definitionsResolver = new DefinitionsResolver(path);
extractSchemaVariants(definitionsResolver, object, path, acceptAdditionalPropertiesSchemas);
if (definitionsResolver.isFound()) {
final List<JsonSchemaObject> matchedSchemas = definitionsResolver.getSchemaObjects();
matchedSchemas.forEach(matchedSchema -> {
final List<JsonSchemaObject> list = gatherSchemas(matchedSchema);
for (JsonSchemaObject schemaObject : list) {
if (schemaObject.getDefinitionAddress() != null && !schemaObject.getDefinitionAddress().startsWith("#/")) {
final List<Step> steps = new ArrayList<>();
if (!isName)
steps.add(new Step(StateType._value, null));
visitSchemaByDefinitionAddress(serviceEx, queue, schemaFile, schemaObject.getDefinitionAddress(), steps);
}
}
});
if (matchedSchemas.size() == 1)
consumer.consume(isName, matchedSchemas.get(0), schemaFile, path);
else {
if (definitionsResolver.isOneOf()) {
consumer.oneOf(isName, matchedSchemas, schemaFile, path);
} else {
consumer.anyOf(isName, matchedSchemas, schemaFile, path);
}
}
} else {
final List<Pair<JsonSchemaObject, List<Step>>> variants = definitionsResolver.getVariants();
for (Pair<JsonSchemaObject, List<Step>> variant : variants) {
if (variant.getFirst().getDefinitionAddress() == null)
continue;
visitSchemaByDefinitionAddress(serviceEx, queue, schemaFile, variant.getFirst().getDefinitionAddress(), variant.getSecond());
}
}
}
}
use of com.intellij.openapi.util.Trinity in project intellij-community by JetBrains.
the class ShowRunningListAction method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent e) {
final Project project = e.getProject();
if (project == null || project.isDisposed())
return;
final Ref<Pair<? extends JComponent, String>> stateRef = new Ref<>();
final Ref<Balloon> balloonRef = new Ref<>();
final Timer timer = UIUtil.createNamedTimer("runningLists", 250);
ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
Balloon balloon = balloonRef.get();
if (project.isDisposed() || (balloon != null && balloon.isDisposed())) {
timer.stop();
return;
}
ArrayList<Project> projects = new ArrayList<>(Arrays.asList(ProjectManager.getInstance().getOpenProjects()));
//List should begin with current project
projects.remove(project);
projects.add(0, project);
Pair<? extends JComponent, String> state = getCurrentState(projects);
Pair<? extends JComponent, String> prevState = stateRef.get();
if (prevState != null && prevState.getSecond().equals(state.getSecond()))
return;
stateRef.set(state);
BalloonBuilder builder = JBPopupFactory.getInstance().createBalloonBuilder(state.getFirst());
builder.setShowCallout(false).setTitle(ExecutionBundle.message("show.running.list.balloon.title")).setBlockClicksThroughBalloon(true).setDialogMode(true).setHideOnKeyOutside(false);
IdeFrame frame = IdeFrame.KEY.getData(e.getDataContext());
if (frame == null) {
frame = WindowManagerEx.getInstanceEx().getFrame(project);
}
if (balloon != null) {
balloon.hide();
}
builder.setClickHandler(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof MouseEvent) {
MouseEvent mouseEvent = (MouseEvent) e.getSource();
Component component = mouseEvent.getComponent();
component = SwingUtilities.getDeepestComponentAt(component, mouseEvent.getX(), mouseEvent.getY());
Object value = ((JComponent) component).getClientProperty(KEY);
if (value instanceof Trinity) {
Project aProject = (Project) ((Trinity) value).first;
JFrame aFrame = WindowManager.getInstance().getFrame(aProject);
if (aFrame != null && !aFrame.isActive()) {
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(aFrame, true);
});
}
ExecutionManagerImpl.getInstance(aProject).getContentManager().toFrontRunContent((Executor) ((Trinity) value).second, (RunContentDescriptor) ((Trinity) value).third);
}
}
}
}, false);
balloon = builder.createBalloon();
balloonRef.set(balloon);
JComponent component = frame.getComponent();
RelativePoint point = new RelativePoint(component, new Point(component.getWidth(), 0));
balloon.show(point, Balloon.Position.below);
}
};
timer.addActionListener(actionListener);
timer.setInitialDelay(0);
timer.start();
}
Aggregations