List of usage examples for com.google.common.collect ImmutableList get
E get(int index);
From source file:org.immutables.generator.processor.TemplateWriter.java
@Override public BoundAccessExpression transform(Context context, BoundAccessExpression value) { ImmutableList<Accessors.BoundAccess> accessList = TypeResolver.asBoundAccess(value.accessor()); StringBuilder expressionBuilder = new StringBuilder(); for (int i = 0; i < accessList.size(); i++) { boolean first = i == 0; boolean last = i != accessList.size() - 1; Accessors.BoundAccess access = accessList.get(i); if (!first) { expressionBuilder.append("."); }//from www .j a va 2 s . c o m String name = access.name; if (first) { name = context.accessMapper(name); } expressionBuilder.append(name).append(access.callable ? "()" : ""); if (access.boxed && last) { expressionBuilder.insert(0, "$("); expressionBuilder.append(")"); } } context.out(expressionBuilder); return value; }
From source file:org.locationtech.geogig.geotools.plumbing.ImportOp.java
/** * Translates a feature pointed by a node from its original feature type to a given one, using * values from those attributes that exist in both original and destination feature type. New * attributes are populated with null values * /*from w w w . j a v a2s.c om*/ * @param node The node that points to the feature. No checking is performed to ensure the node * points to a feature instead of other type * @param featureType the destination feature type * @return a feature with the passed feature type and data taken from the input feature */ private Feature alter(NodeRef node, RevFeatureType featureType) { RevFeature oldFeature = command(RevObjectParse.class).setObjectId(node.objectId()).call(RevFeature.class) .get(); RevFeatureType oldFeatureType; oldFeatureType = command(RevObjectParse.class).setObjectId(node.getMetadataId()).call(RevFeatureType.class) .get(); ImmutableList<PropertyDescriptor> oldAttributes = oldFeatureType.sortedDescriptors(); ImmutableList<PropertyDescriptor> newAttributes = featureType.sortedDescriptors(); ImmutableList<Optional<Object>> oldValues = oldFeature.getValues(); List<Optional<Object>> newValues = Lists.newArrayList(); for (int i = 0; i < newAttributes.size(); i++) { int idx = oldAttributes.indexOf(newAttributes.get(i)); if (idx != -1) { Optional<Object> oldValue = oldValues.get(idx); newValues.add(oldValue); } else { newValues.add(Optional.absent()); } } RevFeature newFeature = RevFeatureImpl.build(ImmutableList.copyOf(newValues)); FeatureBuilder featureBuilder = new FeatureBuilder(featureType); Feature feature = featureBuilder.build(node.name(), newFeature); return feature; }
From source file:com.microsoft.thrifty.schema.parser.ThriftListener.java
@Override public void exitUnionDef(AntlrThriftParser.UnionDefContext ctx) { String name = ctx.IDENTIFIER().getText(); ImmutableList<FieldElement> fields = parseFieldList(ctx.field()); int numFieldsWithDefaultValues = 0; for (int i = 0; i < fields.size(); ++i) { FieldElement element = fields.get(i); if (element.requiredness() == Requiredness.REQUIRED) { AntlrThriftParser.FieldContext fieldContext = ctx.field(i); errorReporter.error(locationOf(fieldContext), "unions cannot have required fields"); }//w w w .j a v a2 s . c o m if (element.constValue() != null) { ++numFieldsWithDefaultValues; } } if (numFieldsWithDefaultValues > 1) { errorReporter.error(locationOf(ctx), "unions can have at most one default value"); } StructElement element = StructElement.builder(locationOf(ctx)).name(name).fields(fields) .type(StructElement.Type.UNION).documentation(formatJavadoc(ctx)) .annotations(annotationsFromAntlr(ctx.annotationList())).build(); unions.add(element); }
From source file:com.facebook.buck.json.PythonDslProjectBuildFileParser.java
@SuppressWarnings("unchecked") private BuildFileManifest toBuildFileManifest(ImmutableList<Map<String, Object>> values) { return BuildFileManifest.builder().setTargets(values.subList(0, values.size() - 3)) .setIncludes(ImmutableSortedSet.copyOf(Preconditions .checkNotNull((List<String>) values.get(values.size() - 3).get("__includes")))) .setConfigs(Preconditions/*from www . j a va2s. c o m*/ .checkNotNull((Map<String, Object>) values.get(values.size() - 2).get("__configs"))) .setEnv(ImmutableMap.copyOf(Maps.transformValues( Preconditions .checkNotNull((Map<String, String>) values.get(values.size() - 1).get("__env")), Optional::ofNullable))) .build(); }
From source file:com.google.javascript.jscomp.TypeTransformation.java
private JSType evalMaprecord(Node ttlAst, NameResolver nameResolver) { ImmutableList<Node> params = getCallParams(ttlAst); JSType type = evalInternal(params.get(0), nameResolver); // If it is an empty record type (Object) then return if (type.isEquivalentTo(getObjectType())) { return getObjectType(); }/*from w w w .j a v a 2s .c o m*/ // The parameter must be a valid record type if (!type.isRecordType()) { // TODO(lpino): Decide how to handle non-record types reportWarning(params.get(0), RECTYPE_INVALID, type.toString()); return getUnknownType(); } // Obtain the elements in the record type. Note that the block // above guarantees the casting to be safe RecordType recType = ((RecordType) type); Set<String> ownPropsNames = recType.getOwnPropertyNames(); // Fetch the information of the map function Node mapFunction = params.get(1); String paramKey = getFunctionParameter(mapFunction, 0); String paramValue = getFunctionParameter(mapFunction, 1); // The maprecord variables must not be defined in the environment if (nameResolver.nameVars.containsKey(paramKey)) { reportWarning(ttlAst, DUPLICATE_VARIABLE, paramKey); return getUnknownType(); } if (nameResolver.typeVars.containsKey(paramValue)) { reportWarning(ttlAst, DUPLICATE_VARIABLE, paramValue); return getUnknownType(); } // Compute the new properties using the map function Node mapFnBody = getFunctionBody(mapFunction); Map<String, JSType> newProps = new HashMap<>(); for (String propName : ownPropsNames) { // The value of the current property JSType propValue = recType.getSlot(propName).getType(); // Evaluate the map function body with paramValue and paramKey replaced // by the values of the current property NameResolver newNameResolver = new NameResolver( addNewEntry(nameResolver.typeVars, paramValue, propValue), addNewEntry(nameResolver.nameVars, paramKey, propName)); JSType body = evalInternal(mapFnBody, newNameResolver); // If the body returns unknown then the whole expression returns unknown if (body.isUnknownType()) { return getUnknownType(); } // Skip the property when the body evaluates to NO_TYPE // or the empty record (Object) if (body.isNoType() || body.isEquivalentTo(getObjectType())) { continue; } // Otherwise the body must evaluate to a record type if (!body.isRecordType()) { reportWarning(ttlAst, MAPRECORD_BODY_INVALID, body.toString()); return getUnknownType(); } // Add the properties of the resulting record type to the original one RecordType bodyAsRecType = ((RecordType) body); for (String newPropName : bodyAsRecType.getOwnPropertyNames()) { JSType newPropValue = bodyAsRecType.getSlot(newPropName).getType(); // If the key already exists then we have to mix it with the current // property value putNewPropInPropertyMap(newProps, newPropName, newPropValue); } } return createRecordType(ImmutableMap.copyOf(newProps)); }
From source file:com.facebook.buck.rust.RustLinkable.java
@VisibleForTesting Path getCrateRoot() {/* w w w .j a v a 2 s.com*/ ImmutableList<Path> candidates = ImmutableList .copyOf(FluentIterable.from(getResolver().deprecatedAllPaths(srcs)).filter(new Predicate<Path>() { @Override public boolean apply(Path path) { return path.endsWith("main.rs") || path.endsWith(String.format("%s.rs", getBuildTarget().getShortName())); } })); if (candidates.size() != 1) { throw new HumanReadableException("srcs of %s must contain either main.rs or %s.rs!", getBuildTarget().getFullyQualifiedName(), getBuildTarget().getShortName()); } // We end up creating a symlink tree to ensure that the crate only uses the files that it // declares in the BUCK file. return scratchDir.resolve(candidates.get(0)); }
From source file:com.google.caliper.runner.options.ParsedOptions.java
@Leftovers private void setLeftovers(ImmutableList<String> leftovers) throws InvalidCommandException { if (requireBenchmarkClassName) { if (leftovers.isEmpty()) { throw new InvalidCommandException("No benchmark class specified"); }/*w w w. j av a 2s . c om*/ if (leftovers.size() > 1) { throw new InvalidCommandException("Extra stuff, expected only class name: " + leftovers); } this.benchmarkClassName = leftovers.get(0); } else { if (!leftovers.isEmpty()) { throw new InvalidCommandException("Extra stuff, did not expect non-option arguments: " + leftovers); } } }
From source file:com.facebook.buck.cli.TargetPatternEvaluator.java
ImmutableMap<String, ImmutableSet<QueryTarget>> resolveBuildTargetPatterns(List<String> patterns, ListeningExecutorService executor) throws InterruptedException, BuildFileParseException, BuildTargetException, IOException { // Build up an ordered list of patterns and pass them to the parse to get resolved in one go. // The returned list of nodes maintains the spec list ordering. List<TargetNodeSpec> specs = new ArrayList<>(); for (String pattern : patterns) { specs.addAll(targetNodeSpecParser.parse(rootCell.getCellPathResolver(), pattern)); }/*from www .j ava 2 s . c om*/ ImmutableList<ImmutableSet<BuildTarget>> buildTargets = parser.resolveTargetSpecs(eventBus, rootCell, enableProfiling, executor, specs, SpeculativeParsing.of(false), // We disable mapping //path/to:lib to //path/to:lib#default,static // because the query engine doesn't handle flavors very well. ParserConfig.ApplyDefaultFlavorsMode.DISABLED); LOG.verbose("Resolved target patterns %s -> targets %s", patterns, buildTargets); // Convert the ordered result into a result map of pattern to set of resolved targets. ImmutableMap.Builder<String, ImmutableSet<QueryTarget>> queryTargets = ImmutableMap.builder(); for (int index = 0; index < buildTargets.size(); index++) { ImmutableSet<BuildTarget> targets = buildTargets.get(index); // Sorting to have predictable results across different java libraries implementations. ImmutableSet.Builder<QueryTarget> builder = ImmutableSortedSet.naturalOrder(); for (BuildTarget target : targets) { builder.add(QueryBuildTarget.of(target)); } queryTargets.put(patterns.get(index), builder.build()); } return queryTargets.build(); }
From source file:com.google.template.soy.types.ast.TypeNodeConverter.java
@Override public SoyType visit(GenericTypeNode node) { ImmutableList<TypeNode> args = node.arguments(); String name = node.name();/*from w w w . j a v a 2s.c o m*/ GenericTypeInfo genericType = GENERIC_TYPES.get(name); if (genericType == null) { errorReporter.report(node.sourceLocation(), NOT_A_GENERIC_TYPE, name); return ErrorType.getInstance(); } if (args.size() < genericType.numParams) { errorReporter.report( // blame the '>' node.sourceLocation().getEndLocation(), EXPECTED_TYPE_PARAM, name, genericType.formatNumTypeParams()); return ErrorType.getInstance(); } else if (args.size() > genericType.numParams) { errorReporter.report( // blame the first unexpected argument args.get(genericType.numParams).sourceLocation(), UNEXPECTED_TYPE_PARAM, name, genericType.formatNumTypeParams()); return ErrorType.getInstance(); } SoyType type = genericType.create(Lists.transform(args, this), typeRegistry); node.setResolvedType(type); return type; }
From source file:com.google.javascript.jscomp.TypeTransformation.java
/** * Merges a list of record types./* w w w .j a va2 s . c o m*/ * Example * {r:{s:string, n:number}} and {a:boolean} * is transformed into {r:{s:string, n:number}, a:boolean} */ private JSType joinRecordTypes(ImmutableList<RecordType> recTypes) { Map<String, JSType> props = new HashMap<>(); for (int i = 0; i < recTypes.size(); i++) { addNewPropsFromRecordType(props, recTypes.get(i)); } return createRecordType(ImmutableMap.copyOf(props)); }