Java Code Examples for com.intellij.util.Consumer#consume()
The following examples show how to use
com.intellij.util.Consumer#consume() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleElementGroupCollectors.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Nonnull @Override protected CSharpElementVisitor createVisitor(@Nonnull final Consumer<CSharpConstructorDeclaration> consumer) { return new CSharpElementVisitor() { @Override public void visitConstructorDeclaration(CSharpConstructorDeclaration declaration) { if(!declaration.isDeConstructor()) { consumer.consume(declaration); } } }; }
Example 2
Source File: MapElementGroupCollectors.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Nonnull @Override protected CSharpElementVisitor createVisitor(@Nonnull final Consumer<CSharpMethodDeclaration> consumer) { return new CSharpElementVisitor() { @Override public void visitMethodDeclaration(CSharpMethodDeclaration declaration) { if(declaration.isOperator()) { consumer.consume(declaration); } } }; }
Example 3
Source File: PantsCompileOptionsExecutor.java From intellij-pants-plugin with Apache License 2.0 | 6 votes |
@NotNull private static String loadProjectStructureFromScript( @NotNull String scriptPath, @NotNull Consumer<String> statusConsumer, @Nullable ProcessAdapter processAdapter ) throws IOException, ExecutionException { final GeneralCommandLine commandLine = PantsUtil.defaultCommandLine(scriptPath); commandLine.setExePath(scriptPath); statusConsumer.consume("Executing " + PathUtil.getFileName(scriptPath)); final ProcessOutput processOutput = PantsUtil.getCmdOutput(commandLine, processAdapter); if (processOutput.checkSuccess(LOG)) { return processOutput.getStdout(); } else { throw new PantsExecutionException("Failed to update the project!", scriptPath, processOutput); } }
Example 4
Source File: PantsCompileOptionsExecutor.java From intellij-pants-plugin with Apache License 2.0 | 6 votes |
@NotNull private String loadProjectStructureFromTargets( @NotNull Consumer<String> statusConsumer, @Nullable ProcessAdapter processAdapter ) throws IOException, ExecutionException { final File outputFile = FileUtil.createTempFile("pants_depmap_run", ".out"); final GeneralCommandLine command = getPantsExportCommand(outputFile, statusConsumer); statusConsumer.consume("Resolving dependencies..."); PantsMetrics.markExportStart(); final ProcessOutput processOutput = getProcessOutput(command); PantsMetrics.markExportEnd(); if (processOutput.getStdout().contains("no such option")) { throw new ExternalSystemException("Pants doesn't have necessary APIs. Please upgrade your pants!"); } if (processOutput.checkSuccess(LOG)) { return FileUtil.loadFile(outputFile); } else { throw new PantsExecutionException("Failed to update the project!", command.getCommandLineString("pants"), processOutput); } }
Example 5
Source File: FileStub.java From Intellij-Plugin with Apache License 2.0 | 6 votes |
@NotNull @Override public FileBasedIndex.InputFilter getInputFilter() { return new FileBasedIndex.FileTypeSpecificInputFilter() { @Override public void registerFileTypesUsedForIndexing(@NotNull Consumer<FileType> consumer) { consumer.consume(SpecFileType.INSTANCE); consumer.consume(ConceptFileType.INSTANCE); } @Override public boolean acceptInput(@NotNull VirtualFile virtualFile) { return virtualFile.getExtension() != null && GaugeUtil.isGaugeFile(virtualFile); } }; }
Example 6
Source File: StructOrGenericParameterConstructorProvider.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction private static void buildDefaultConstructor(@Nonnull DotNetNamedElement element, @Nonnull DotNetGenericExtractor extractor, @Nonnull Consumer<PsiElement> consumer) { String name = element.getName(); if(name == null) { return; } CSharpLightConstructorDeclarationBuilder builder = buildDefaultConstructor(element, name); CSharpMethodDeclaration delegatedMethod = element.getUserData(CSharpResolveUtil.DELEGATE_METHOD_TYPE); if(delegatedMethod != null) { CSharpLightParameterBuilder parameter = new CSharpLightParameterBuilder(element.getProject()); parameter = parameter.withName("p"); CSharpMethodDeclaration extractedMethod = GenericUnwrapTool.extract(delegatedMethod, extractor); parameter = parameter.withTypeRef(new CSharpLambdaTypeRef(extractedMethod)); builder.addParameter(parameter); } consumer.consume(builder); }
Example 7
Source File: FlutterDartAnalysisServer.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Handle the given {@link JsonObject} response. */ private void processResponse(JsonObject response) { final JsonElement eventName = response.get("event"); if (eventName != null && eventName.isJsonPrimitive()) { processNotification(response, eventName); return; } if (response.has("error")) { return; } final JsonObject resultObject = response.getAsJsonObject("result"); if (resultObject == null) { return; } final JsonPrimitive idJsonPrimitive = (JsonPrimitive)response.get("id"); if (idJsonPrimitive == null) { return; } final String idString = idJsonPrimitive.getAsString(); final Consumer<JsonObject> consumer; synchronized (responseConsumers) { consumer = responseConsumers.remove(idString); } if (consumer == null) { return; } consumer.consume(resultObject); }
Example 8
Source File: SimpleElementGroupCollectors.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Nonnull @Override protected CSharpElementVisitor createVisitor(@Nonnull final Consumer<CSharpIndexMethodDeclaration> consumer) { return new CSharpElementVisitor() { @Override public void visitIndexMethodDeclaration(CSharpIndexMethodDeclaration methodDeclaration) { consumer.consume(methodDeclaration); } }; }
Example 9
Source File: FlutterDartAnalysisServer.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Handle the given {@link JsonObject} response. */ private void processResponse(JsonObject response) { final JsonElement eventName = response.get("event"); if (eventName != null && eventName.isJsonPrimitive()) { processNotification(response, eventName); return; } if (response.has("error")) { return; } final JsonObject resultObject = response.getAsJsonObject("result"); if (resultObject == null) { return; } final JsonPrimitive idJsonPrimitive = (JsonPrimitive)response.get("id"); if (idJsonPrimitive == null) { return; } final String idString = idJsonPrimitive.getAsString(); final Consumer<JsonObject> consumer; synchronized (responseConsumers) { consumer = responseConsumers.remove(idString); } if (consumer == null) { return; } consumer.consume(resultObject); }
Example 10
Source File: CSharpOperatorReferenceImpl.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredReadAction private void processImplicitCasts(DotNetTypeRef expressionTypeRef, PsiElement parent, @Nonnull Consumer<DotNetTypeRef> consumer) { for(DotNetExpression dotNetExpression : ((CSharpExpressionWithOperatorImpl) parent).getParameterExpressions()) { List<DotNetTypeRef> implicitOrExplicitTypeRefs = CSharpTypeUtil.getImplicitOrExplicitTypeRefs(dotNetExpression.toTypeRef(true), expressionTypeRef, CSharpCastType.IMPLICIT, this); for(DotNetTypeRef implicitOrExplicitTypeRef : implicitOrExplicitTypeRefs) { consumer.consume(implicitOrExplicitTypeRef); } } }
Example 11
Source File: RollbarErrorReportSubmitter.java From bamboo-soy with Apache License 2.0 | 5 votes |
@Override public boolean submit(@NotNull IdeaLoggingEvent[] events, @Nullable String additionalInfo, @NotNull Component parentComponent, @NotNull Consumer<SubmittedReportInfo> consumer) { log(events, additionalInfo); consumer.consume(new SubmittedReportInfo(null, null, NEW_ISSUE)); Messages.showInfoMessage(parentComponent, DEFAULT_RESPONSE, DEFAULT_RESPONSE_TITLE); return true; }
Example 12
Source File: UnitySpecificMethodCompletion.java From consulo-unity3d with Apache License 2.0 | 5 votes |
@RequiredReadAction @Override public void processCompletion(@Nonnull CompletionParameters completionParameters, @Nonnull ProcessingContext processingContext, @Nonnull Consumer<LookupElement> completionResultSet, @Nonnull CSharpTypeDeclaration typeDeclaration) { Unity3dModuleExtension extension = ModuleUtilCore.getExtension(typeDeclaration, Unity3dModuleExtension.class); if(extension == null) { return; } for(Map.Entry<String, Map<String, UnityFunctionManager.FunctionInfo>> entry : UnityFunctionManager.getInstance().getFunctionsByType().entrySet()) { String typeName = entry.getKey(); if(!DotNetInheritUtil.isParent(typeName, typeDeclaration, true)) { continue; } for(UnityFunctionManager.FunctionInfo functionInfo : entry.getValue().values()) { UnityFunctionManager.FunctionInfo nonParameterListCopy = functionInfo.createNonParameterListCopy(); if(nonParameterListCopy != null) { completionResultSet.consume(buildLookupItem(nonParameterListCopy, typeDeclaration)); } completionResultSet.consume(buildLookupItem(functionInfo, typeDeclaration)); } } }
Example 13
Source File: CSharpNoVariantsDelegator.java From consulo-csharp with Apache License 2.0 | 4 votes |
@RequiredReadAction private static void consumeType(final CompletionParameters completionParameters, CSharpReferenceExpression referenceExpression, Consumer<LookupElement> consumer, boolean insideUsingList, DotNetTypeDeclaration someType) { final String parentQName = someType.getPresentableParentQName(); if(StringUtil.isEmpty(parentQName)) { return; } String presentationText = MsilHelper.cutGenericMarker(someType.getName()); int genericCount; DotNetGenericParameter[] genericParameters = someType.getGenericParameters(); if((genericCount = genericParameters.length) > 0) { presentationText += "<" + StringUtil.join(genericParameters, parameter -> parameter.getName(), ", "); presentationText += ">"; } String lookupString = insideUsingList ? someType.getPresentableQName() : someType.getName(); if(lookupString == null) { return; } lookupString = MsilHelper.cutGenericMarker(lookupString); DotNetQualifiedElement targetElementForLookup = someType; CSharpMethodDeclaration methodDeclaration = someType.getUserData(CSharpResolveUtil.DELEGATE_METHOD_TYPE); if(methodDeclaration != null) { targetElementForLookup = methodDeclaration; } LookupElementBuilder builder = LookupElementBuilder.create(targetElementForLookup, lookupString); builder = builder.withPresentableText(presentationText); builder = builder.withIcon(IconDescriptorUpdaters.getIcon(targetElementForLookup, Iconable.ICON_FLAG_VISIBILITY)); builder = builder.withTypeText(parentQName, true); final InsertHandler<LookupElement> ltGtInsertHandler = genericCount == 0 ? null : LtGtInsertHandler.getInstance(genericCount > 0); if(insideUsingList) { builder = builder.withInsertHandler(ltGtInsertHandler); } else { builder = builder.withInsertHandler(new InsertHandler<LookupElement>() { @Override @RequiredWriteAction public void handleInsert(InsertionContext context, LookupElement item) { if(ltGtInsertHandler != null) { ltGtInsertHandler.handleInsert(context, item); } context.commitDocument(); new AddUsingAction(completionParameters.getEditor(), context.getFile(), Collections.<NamespaceReference>singleton(new NamespaceReference(parentQName, null))).execute(); } }); } if(DotNetAttributeUtil.hasAttribute(someType, DotNetTypes.System.ObsoleteAttribute)) { builder = builder.withStrikeoutness(true); } CSharpTypeLikeLookupElement element = CSharpTypeLikeLookupElement.create(builder, DotNetGenericExtractor.EMPTY, referenceExpression); element.putUserData(CSharpNoVariantsDelegator.NOT_IMPORTED, Boolean.TRUE); consumer.consume(element); }
Example 14
Source File: ConversionMethodsProvider.java From consulo-csharp with Apache License 2.0 | 4 votes |
private static void buildConversionMethods(@Nonnull Project project, GlobalSearchScope resolveScope, @Nonnull DotNetTypeRef selfTypeRef, @Nonnull DotNetElement parent, @Nonnull Collection<OperatorStubsLoader.Operator> operators, @Nonnull Consumer<PsiElement> consumer) { if(operators.isEmpty()) { return; } for(OperatorStubsLoader.Operator operator : operators) { if(operator.myOperatorToken == CSharpTokens.IMPLICIT_KEYWORD || operator.myOperatorToken == CSharpTokens.EXPLICIT_KEYWORD) { CSharpStaticTypeRef staticTypeRef = CSharpStaticTypeRef.IMPLICIT; if(operator.myOperatorToken == CSharpTokens.EXPLICIT_KEYWORD) { staticTypeRef = CSharpStaticTypeRef.EXPLICIT; } CSharpLightLikeMethodDeclarationBuilder builder = new CSharpLightConversionMethodDeclarationBuilder(project, staticTypeRef); builder.withParent(parent); builder.withReturnType(operator.myReturnTypeRef == null ? selfTypeRef : new CSharpTypeRefByQName(project, resolveScope, operator.myReturnTypeRef)); int i = 0; for(OperatorStubsLoader.Operator.Parameter parameter : operator.myParameterTypes) { CSharpLightParameterBuilder parameterBuilder = new CSharpLightParameterBuilder(project); parameterBuilder.withName("p" + i); parameterBuilder.withTypeRef(parameter.myTypeRef == null ? selfTypeRef : new CSharpTypeRefByQName(project, resolveScope, parameter.myTypeRef)); builder.addParameter(parameterBuilder); i++; } consumer.consume(builder); } } }
Example 15
Source File: LambdaLineMarkerCollector.java From consulo-csharp with Apache License 2.0 | 4 votes |
@RequiredReadAction @Override public void collect(PsiElement psiElement, @Nonnull Consumer<LineMarkerInfo> lineMarkerInfos) { IElementType elementType = PsiUtilCore.getElementType(psiElement); if(elementType == CSharpTokens.DARROW) { PsiElement parent = psiElement.getParent(); if(!(parent instanceof CSharpLambdaExpressionImpl)) { return; } MarkerInfo markerInfo = new MarkerInfo(parent, psiElement.getTextRange(), AllIcons.Gutter.ImplementingFunctional, Pass.UPDATE_ALL, new ConstantFunction<>("Navigate to lambda delegate"), new GutterIconNavigationHandler<PsiElement>() { @Override @RequiredUIAccess public void navigate(MouseEvent e, PsiElement elt) { if(!(elt instanceof CSharpLambdaExpressionImpl)) { return; } CSharpLambdaResolveResult lambdaResolveResult = CSharpLambdaExpressionImplUtil.resolveLeftLambdaTypeRef(elt); if(lambdaResolveResult == null) { return; } PsiElement element = lambdaResolveResult.getElement(); if(element instanceof Navigatable) { ((Navigatable) element).navigate(true); } } }, GutterIconRenderer.Alignment.RIGHT); NavigateAction.setNavigateAction(markerInfo, "Navigate to lambda delegate", IdeActions.ACTION_GOTO_SUPER); lineMarkerInfos.consume(markerInfo); } }
Example 16
Source File: GraphQLCompletionContributor.java From js-graphql-intellij-plugin with MIT License | 4 votes |
private void completeFragmentOnTypeName() { CompletionProvider<CompletionParameters> provider = new CompletionProvider<CompletionParameters>() { @Override protected void addCompletions(@NotNull final CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) { final PsiElement completionElement = parameters.getPosition(); // the type condition that the 'on' keyword belongs to GraphQLTypeCondition typeCondition = PsiTreeUtil.getParentOfType(completionElement, GraphQLTypeCondition.class); if (typeCondition == null) { // typeCondition is on the left if the selection set follows typeCondition = PsiTreeUtil.getPrevSiblingOfType(completionElement, GraphQLTypeCondition.class); } final boolean fragmentDefinition = typeCondition != null && typeCondition.getParent() instanceof GraphQLFragmentDefinition; final GraphQLTypeDefinitionRegistryServiceImpl typeDefinitionRegistryService = GraphQLTypeDefinitionRegistryServiceImpl.getService(completionElement.getProject()); final TypeDefinitionRegistry typeDefinitionRegistry = typeDefinitionRegistryService.getRegistry(parameters.getOriginalFile()); final List<Pair<TypeDefinition, Description>> fragmentTypes = Lists.newArrayList(); if (fragmentDefinition) { // completion in a top-level fragment definition, so add all known types, interfaces, unions typeDefinitionRegistry.types().forEach((key, value) -> { final boolean canFragment = value instanceof ObjectTypeDefinition || value instanceof UnionTypeDefinition || value instanceof InterfaceTypeDefinition; if (canFragment) { fragmentTypes.add(Pair.create(value, typeDefinitionRegistryService.getTypeDefinitionDescription(value))); } }); } else { // inline fragment, so get type scope GraphQLTypeScopeProvider typeScopeProvider = PsiTreeUtil.getParentOfType(completionElement, GraphQLTypeScopeProvider.class); if (typeScopeProvider instanceof GraphQLInlineFragment && ((GraphQLInlineFragment) typeScopeProvider).getTypeCondition() == typeCondition) { // if the type condition belongs to the type scope provider, we want the parent scope since that // is the real source of what we can fragment on typeScopeProvider = PsiTreeUtil.getParentOfType(typeScopeProvider, GraphQLTypeScopeProvider.class); } GraphQLType rawTypeScope = typeScopeProvider != null ? typeScopeProvider.getTypeScope() : null; if (rawTypeScope != null) { GraphQLUnmodifiedType typeScope = GraphQLUtil.getUnmodifiedType(rawTypeScope); // unwrap non-null and lists since fragments are about the raw type final TypeDefinition fragmentType = typeDefinitionRegistry.getType(typeScope.getName()).orElse(null); if (fragmentType != null) { final Ref<Consumer<TypeDefinition<?>>> addTypesRecursive = new Ref<>(); final Consumer<TypeDefinition<?>> addTypes = (typeToFragmentOn) -> { if (typeToFragmentOn instanceof ObjectTypeDefinition) { fragmentTypes.add(Pair.create(typeToFragmentOn, typeDefinitionRegistryService.getTypeDefinitionDescription(typeToFragmentOn))); final List<Type> anImplements = ((ObjectTypeDefinition) typeToFragmentOn).getImplements(); if (anImplements != null) { anImplements.forEach(type -> { final TypeDefinition typeDefinition = typeDefinitionRegistry.getType(type).orElse(null); if (typeDefinition instanceof InterfaceTypeDefinition) { fragmentTypes.add(Pair.create(typeDefinition, typeDefinitionRegistryService.getTypeDefinitionDescription(typeDefinition))); } }); } } else if (typeToFragmentOn instanceof InterfaceTypeDefinition) { fragmentTypes.add(Pair.create(typeToFragmentOn, typeDefinitionRegistryService.getTypeDefinitionDescription(typeToFragmentOn))); final List<ObjectTypeDefinition> implementationsOf = typeDefinitionRegistry.getImplementationsOf((InterfaceTypeDefinition) typeToFragmentOn); implementationsOf.forEach(impl -> fragmentTypes.add(Pair.create(impl, typeDefinitionRegistryService.getTypeDefinitionDescription(impl)))); } else if (typeToFragmentOn instanceof UnionTypeDefinition) { final List<Type> memberTypes = ((UnionTypeDefinition) typeToFragmentOn).getMemberTypes(); if (memberTypes != null) { memberTypes.forEach(memberType -> { typeDefinitionRegistry.getType(memberType).ifPresent(memberTypeDefinition -> addTypesRecursive.get().consume(memberTypeDefinition)); }); } } }; addTypesRecursive.set(addTypes); addTypes.consume(fragmentType); } } } fragmentTypes.forEach(fragmentType -> { LookupElementBuilder element = LookupElementBuilder .create(fragmentType.first.getName()) .withBoldness(true); if (fragmentType.second != null) { final String documentation = GraphQLDocumentationMarkdownRenderer.getDescriptionAsPlainText(fragmentType.second.getContent(), true); element = element.withTailText(" - " + documentation, true); } result.addElement(element); }); } }; extend(CompletionType.BASIC, psiElement().afterLeaf(psiElement(GraphQLElementTypes.ON_KEYWORD)), provider); }
Example 17
Source File: CSharpDocTagHighlightUsagesHandler.java From consulo-csharp with Apache License 2.0 | 4 votes |
@Override protected void selectTargets(List<PsiElement> targets, Consumer<List<PsiElement>> selectionConsumer) { selectionConsumer.consume(targets); }
Example 18
Source File: FlutterErrorReportSubmitter.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 4 votes |
private static void fail(@NotNull Consumer<SubmittedReportInfo> consumer) { consumer.consume(new SubmittedReportInfo( null, null, SubmittedReportInfo.SubmissionStatus.FAILED)); }
Example 19
Source File: FlutterErrorReportSubmitter.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 4 votes |
private static void fail(@NotNull Consumer<SubmittedReportInfo> consumer) { consumer.consume(new SubmittedReportInfo( null, null, SubmittedReportInfo.SubmissionStatus.FAILED)); }
Example 20
Source File: HidingOrOverridingElementCollector.java From consulo-csharp with Apache License 2.0 | 4 votes |
@RequiredReadAction @Override public void collect(PsiElement psiElement, @Nonnull Consumer<LineMarkerInfo> consumer) { DotNetVirtualImplementOwner virtualImplementOwner = CSharpLineMarkerUtil.findElementForLineMarker(psiElement); if(virtualImplementOwner != null) { PsiElement parentParent = virtualImplementOwner.getParent(); if(!(parentParent instanceof DotNetTypeDeclaration)) { return; } Collection<DotNetVirtualImplementOwner> overrideElements = OverrideUtil.collectOverridingMembers(virtualImplementOwner); if(overrideElements.isEmpty()) { return; } Image icon = null; if(virtualImplementOwner.getTypeForImplement() != null) { icon = CSharpIcons.Gutter.HidingMethod; } else { icon = AllIcons.Gutter.ImplementingMethod; for(DotNetVirtualImplementOwner overrideElement : overrideElements) { if(!((DotNetModifierListOwner) overrideElement).hasModifier(DotNetModifier.ABSTRACT)) { icon = AllIcons.Gutter.OverridingMethod; break; } } } LineMarkerInfo<PsiElement> lineMarkerInfo = new LineMarkerInfo<>(psiElement, psiElement.getTextRange(), icon, Pass.LINE_MARKERS, new ConstantFunction<>("Searching for overriding"), OurHandler.INSTANCE, GutterIconRenderer.Alignment.RIGHT); consumer.consume(lineMarkerInfo); } }