List of usage examples for com.google.common.collect ImmutableSet contains
boolean contains(Object o);
From source file:org.apache.flex.compiler.internal.parsing.as.BaseASParser.java
/** * Consume until a keyword, EOF or specified token types. * //w w w. java2 s .c om * @param types Stop if the next token's type is one of these. */ protected void consumeUntilKeywordOr(final Integer... types) { final ImmutableSet<Integer> stopSet = new ImmutableSet.Builder<Integer>().add(types).add(ASTokenTypes.EOF) .build(); while (!stopSet.contains(buffer.LA(1)) && !LT(1).isKeywordOrContextualReservedWord()) { consume(); } }
From source file:dagger.internal.codegen.AbstractComponentWriter.java
/** * Adds the methods that set each of parameters on the builder. If the {@link BuilderSpec} is * present, it will tailor the methods to match the spec. *///from w w w . j a v a 2 s .c o m private void addBuilderMethods(TypeSpec.Builder componentBuilder, Optional<BuilderSpec> builderSpec) { ImmutableSet<ComponentRequirement> componentRequirements = graph.componentRequirements(); if (builderSpec.isPresent()) { UniqueNameSet parameterNames = new UniqueNameSet(); for (BuilderRequirementMethod requirementMethod : builderSpec.get().requirementMethods()) { ComponentRequirement builderRequirement = requirementMethod.requirement(); ExecutableElement specMethod = requirementMethod.method(); MethodSpec.Builder builderMethod = addBuilderMethodFromSpec(specMethod); VariableElement parameterElement = Iterables.getOnlyElement(specMethod.getParameters()); String parameterName = parameterNames.getUniqueName(parameterElement.getSimpleName()); TypeName argType = parameterElement.asType().getKind().isPrimitive() // Primitives need to use the original (unresolved) type to avoid boxing. ? TypeName.get(parameterElement.asType()) // Otherwise we use the full resolved type. : TypeName.get(builderRequirement.type()); builderMethod.addParameter(argType, parameterName); if (componentRequirements.contains(builderRequirement)) { // required type builderMethod.addStatement("this.$N = $L", builderFields.get(builderRequirement), builderRequirement.nullPolicy(elements, types) .equals(ComponentRequirement.NullPolicy.ALLOW) ? parameterName : CodeBlock.of("$T.checkNotNull($L)", Preconditions.class, parameterName)); addBuilderMethodReturnStatementForSpec(specMethod, builderMethod); } else if (graph.ownedModuleTypes().contains(builderRequirement.typeElement())) { // owned, but not required builderMethod.addJavadoc(NOOP_BUILDER_METHOD_JAVADOC); addBuilderMethodReturnStatementForSpec(specMethod, builderMethod); } else { // neither owned nor required, so it must be an inherited module builderMethod.addStatement("throw new $T($T.format($S, $T.class.getCanonicalName()))", UnsupportedOperationException.class, String.class, "%s cannot be set because it is inherited from the enclosing component", TypeNames.rawTypeName(TypeName.get(builderRequirement.type()))); } componentBuilder.addMethod(builderMethod.build()); } } else { for (ComponentRequirement componentRequirement : graph.availableDependencies()) { String componentRequirementName = simpleVariableName(componentRequirement.typeElement()); MethodSpec.Builder builderMethod = methodBuilder(componentRequirementName) .returns(builderName.get()).addModifiers(PUBLIC) .addParameter(ClassName.get(componentRequirement.type()), componentRequirementName); if (componentRequirements.contains(componentRequirement)) { builderMethod.addStatement("this.$N = $T.checkNotNull($L)", builderFields.get(componentRequirement), Preconditions.class, componentRequirementName); } else { builderMethod.addStatement("$T.checkNotNull($L)", Preconditions.class, componentRequirementName); builderMethod.addJavadoc("@deprecated " + NOOP_BUILDER_METHOD_JAVADOC); builderMethod.addAnnotation(Deprecated.class); } builderMethod.addStatement("return this"); componentBuilder.addMethod(builderMethod.build()); } } }
From source file:com.facebook.buck.features.apple.project.ProjectGenerator.java
/** Add all source files of genrules in a group "Other". */ private void addGenruleFiles() { ImmutableSet<SourcePath> filesAdded = filesAddedBuilder.build(); PBXGroup group = project.getMainGroup(); ImmutableList<SourcePath> files = genruleFiles.build(); if (files.size() > 0) { PBXGroup otherGroup = group.getOrCreateChildGroupByName("Other"); for (SourcePath sourcePath : files) { // Make sure we don't add duplicates of existing files in this section. if (filesAdded.contains(sourcePath)) { continue; }// w w w .j a v a 2s.c o m Path path = pathRelativizer.outputPathToSourcePath(sourcePath); ImmutableList<String> targetGroupPath = null; PBXGroup sourceGroup = otherGroup; if (path.getParent() != null) { targetGroupPath = RichStream.from(path.getParent()).map(Object::toString).toImmutableList(); sourceGroup = otherGroup.getOrCreateDescendantGroupByPath(targetGroupPath); } sourceGroup.getOrCreateFileReferenceBySourceTreePath( new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, path, Optional.empty())); } } }
From source file:com.facebook.buck.features.apple.project.ProjectGenerator.java
public void createXcodeProjects() throws IOException { LOG.debug("Creating projects for targets %s", initialTargets); boolean hasAtLeastOneTarget = false; try (SimplePerfEvent.Scope scope = SimplePerfEvent.scope(buckEventBus, PerfEventId.of("xcode_project_generation"), ImmutableMap.of("Path", getProjectPath()))) { // Filter out nodes that aren't included in project. ImmutableSet.Builder<TargetNode<?>> projectTargetsBuilder = ImmutableSet.builder(); for (TargetNode<?> targetNode : targetGraph.getNodes()) { if (isBuiltByCurrentProject(targetNode.getBuildTarget())) { LOG.debug("Including rule %s in project", targetNode); projectTargetsBuilder.add(targetNode); if (focusModules.isFocusedOn(targetNode.getBuildTarget())) { // If the target is not included, we still need to do other operations to generate // the required header maps. hasAtLeastOneTarget = true; }/*from ww w . ja va 2 s .c o m*/ } else { LOG.verbose("Excluding rule %s (not built by current project)", targetNode); } } final ImmutableSet<TargetNode<?>> projectTargets = projectTargetsBuilder.build(); // Trigger the loading cache for the workspace target if it's in the project. This ensures the // workspace target isn't filtered later by loading it first. final Optional<TargetNode<?>> workspaceTargetNode = workspaceTarget .map(target -> targetGraph.get(target)); workspaceTargetNode.filter(targetNode -> projectTargets.contains(targetNode)) .ifPresent(targetNode -> triggerLoadingCache(targetNode)); // Trigger the loading cache to call the generateProjectTarget function on all other targets. // Exclude the workspace target since it's loaded above. RichStream.from(projectTargets) .filter(input -> !workspaceTargetNode.isPresent() || !input.equals(workspaceTargetNode.get())) .forEach(input -> triggerLoadingCache(input)); addGenruleFiles(); if (!hasAtLeastOneTarget && focusModules.hasFocus()) { return; } if (shouldMergeHeaderMaps() && isMainProject) { createMergedHeaderMap(); } for (String configName : targetConfigNamesBuilder.build()) { XCBuildConfiguration outputConfig = project.getBuildConfigurationList() .getBuildConfigurationsByName().getUnchecked(configName); outputConfig.setBuildSettings(new NSDictionary()); } if (!options.shouldGenerateHeaderSymlinkTreesOnly()) { writeProjectFile(project); } projectGenerated = true; } catch (UncheckedExecutionException e) { // if any code throws an exception, they tend to get wrapped in LoadingCache's // UncheckedExecutionException. Unwrap it if its cause is HumanReadable. UncheckedExecutionException originalException = e; while (e.getCause() instanceof UncheckedExecutionException) { e = (UncheckedExecutionException) e.getCause(); } if (e.getCause() instanceof HumanReadableException) { throw (HumanReadableException) e.getCause(); } else { throw originalException; } } }
From source file:dagger2.internal.codegen.ComponentGenerator.java
private void writeInterfaceMethods(BindingGraph input, ClassWriter componentWriter, ImmutableMap<BindingKey, MemberSelect> memberSelectSnippets, ImmutableSet<BindingKey> enumBindingKeys) throws AssertionError { Set<MethodSignature> interfaceMethods = Sets.newHashSet(); for (ComponentMethodDescriptor componentMethod : input.componentDescriptor().componentMethods()) { if (componentMethod.dependencyRequest().isPresent()) { DependencyRequest interfaceRequest = componentMethod.dependencyRequest().get(); ExecutableElement requestElement = MoreElements.asExecutable(interfaceRequest.requestElement()); ExecutableType requestType = MoreTypes.asExecutable(types.asMemberOf( MoreTypes.asDeclared(input.componentDescriptor().componentDefinitionType().asType()), requestElement));// w w w.j ava 2 s . co m MethodSignature signature = MethodSignature .fromExecutableType(requestElement.getSimpleName().toString(), requestType); if (!interfaceMethods.contains(signature)) { interfaceMethods.add(signature); MethodWriter interfaceMethod = requestType.getReturnType().getKind().equals(VOID) ? componentWriter.addMethod(VoidName.VOID, requestElement.getSimpleName().toString()) : componentWriter.addMethod(requestType.getReturnType(), requestElement.getSimpleName().toString()); interfaceMethod.annotate(Override.class); interfaceMethod.addModifiers(PUBLIC); BindingKey bindingKey = interfaceRequest.bindingKey(); switch (interfaceRequest.kind()) { case MEMBERS_INJECTOR: MemberSelect membersInjectorSelect = memberSelectSnippets.get(bindingKey); List<? extends VariableElement> parameters = requestElement.getParameters(); if (parameters.isEmpty()) { // we're returning the framework type interfaceMethod.body().addSnippet("return %s;", membersInjectorSelect.getSnippetFor(componentWriter.name())); } else { VariableElement parameter = Iterables.getOnlyElement(parameters); Name parameterName = parameter.getSimpleName(); interfaceMethod.addParameter( TypeNames.forTypeMirror( Iterables.getOnlyElement(requestType.getParameterTypes())), parameterName.toString()); interfaceMethod.body().addSnippet("%s.injectMembers(%s);", // in this case we know we won't need the cast because we're never going to pass // the reference to anything membersInjectorSelect.getSnippetFor(componentWriter.name()), parameterName); if (!requestType.getReturnType().getKind().equals(VOID)) { interfaceMethod.body().addSnippet("return %s;", parameterName); } } break; case INSTANCE: if (enumBindingKeys.contains(bindingKey) && (bindingKey.key().type().getKind() .equals(DECLARED) && !((DeclaredType) bindingKey.key().type()).getTypeArguments().isEmpty())) { // If using a parameterized enum type, then we need to store the factory // in a temporary variable, in order to help javac be able to infer // the generics of the Factory.create methods. TypeName factoryType = ParameterizedTypeName.create(Provider.class, TypeNames.forTypeMirror(requestType.getReturnType())); interfaceMethod.body().addSnippet("%s factory = %s;", factoryType, memberSelectSnippets.get(bindingKey).getSnippetFor(componentWriter.name())); interfaceMethod.body().addSnippet("return factory.get();"); break; } // fall through in the else case. case LAZY: case PRODUCED: case PRODUCER: case PROVIDER: case FUTURE: interfaceMethod.body().addSnippet("return %s;", frameworkTypeUsageStatement( memberSelectSnippets.get(bindingKey).getSnippetFor(componentWriter.name()), interfaceRequest.kind())); break; default: throw new AssertionError(); } } } } }