Пример #1
0
    @Override
    public PlanNode visitUnion(UnionNode node, RewriteContext<Set<Symbol>> context) {
      // Find out which output symbols we need to keep
      ImmutableListMultimap.Builder<Symbol, Symbol> rewrittenSymbolMappingBuilder =
          ImmutableListMultimap.builder();
      for (Symbol symbol : node.getOutputSymbols()) {
        if (context.get().contains(symbol)) {
          rewrittenSymbolMappingBuilder.putAll(symbol, node.getSymbolMapping().get(symbol));
        }
      }
      ListMultimap<Symbol, Symbol> rewrittenSymbolMapping = rewrittenSymbolMappingBuilder.build();

      // Find the corresponding input symbol to the remaining output symbols and prune the subplans
      ImmutableList.Builder<PlanNode> rewrittenSubPlans = ImmutableList.builder();
      for (int i = 0; i < node.getSources().size(); i++) {
        ImmutableSet.Builder<Symbol> expectedInputSymbols = ImmutableSet.builder();
        for (Collection<Symbol> symbols : rewrittenSymbolMapping.asMap().values()) {
          expectedInputSymbols.add(Iterables.get(symbols, i));
        }
        rewrittenSubPlans.add(
            context.rewrite(node.getSources().get(i), expectedInputSymbols.build()));
      }

      return new UnionNode(
          node.getId(),
          rewrittenSubPlans.build(),
          rewrittenSymbolMapping,
          ImmutableList.copyOf(rewrittenSymbolMapping.keySet()));
    }
Пример #2
0
 public Builder concatenate(Term term) {
   if (term instanceof CellCollection) {
     CellCollection cellCollection = (CellCollection) term;
     cellsBuilder.putAll(cellCollection.cells);
     collectionVariablesBuilder.addAll(cellCollection.collectionVariables);
   } else if (term instanceof Variable && term.kind == Kind.CELL_COLLECTION) {
     collectionVariablesBuilder.add((Variable) term);
   } else {
     assert false : "unexpected concatenated term " + term;
   }
   return this;
 }
Пример #3
0
  public static void dumpRegistry(File minecraftDir) {
    if (customItemStacks == null) {
      return;
    }
    if (Boolean.valueOf(System.getProperty("fml.dumpRegistry", "false")).booleanValue()) {
      ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
      for (String modId : customItemStacks.rowKeySet()) {
        builder.putAll(modId, customItemStacks.row(modId).keySet());
      }

      File f = new File(minecraftDir, "itemStackRegistry.csv");
      MapJoiner mapJoiner = Joiner.on("\n").withKeyValueSeparator(",");
      try {
        Files.write(mapJoiner.join(builder.build().entries()), f, Charsets.UTF_8);
        FMLLog.log(Level.INFO, "Dumped item registry data to %s", f.getAbsolutePath());
      } catch (IOException e) {
        FMLLog.log(Level.ERROR, e, "Failed to write registry data to %s", f.getAbsolutePath());
      }
    }
  }
  private void doProcess(RoundEnvironment roundEnv) {
    for (Element element : roundEnv.getElementsAnnotatedWith(Provided.class)) {
      providedChecker.checkProvidedParameter(element);
    }

    ImmutableListMultimap.Builder<String, FactoryMethodDescriptor> indexedMethods =
        ImmutableListMultimap.builder();
    ImmutableSet.Builder<ImplementationMethodDescriptor> implementationMethodDescriptors =
        ImmutableSet.builder();
    for (Element element : roundEnv.getElementsAnnotatedWith(AutoFactory.class)) {
      Optional<AutoFactoryDeclaration> declaration = declarationFactory.createIfValid(element);
      if (declaration.isPresent()) {
        TypeElement extendingType = declaration.get().extendingType();
        List<ExecutableElement> supertypeMethods =
            ElementFilter.methodsIn(elements.getAllMembers(extendingType));
        for (ExecutableElement supertypeMethod : supertypeMethods) {
          if (supertypeMethod.getModifiers().contains(Modifier.ABSTRACT)) {
            ExecutableType methodType =
                Elements2.getExecutableElementAsMemberOf(types, supertypeMethod, extendingType);
            implementationMethodDescriptors.add(
                new ImplementationMethodDescriptor.Builder()
                    .name(supertypeMethod.getSimpleName().toString())
                    .returnType(getAnnotatedType(element).getQualifiedName().toString())
                    .publicMethod()
                    .passedParameters(
                        Parameter.forParameterList(
                            supertypeMethod.getParameters(), methodType.getParameterTypes()))
                    .build());
          }
        }
        for (TypeElement implementingType : declaration.get().implementingTypes()) {
          List<ExecutableElement> interfaceMethods =
              ElementFilter.methodsIn(elements.getAllMembers(implementingType));
          for (ExecutableElement interfaceMethod : interfaceMethods) {
            if (interfaceMethod.getModifiers().contains(Modifier.ABSTRACT)) {
              ExecutableType methodType =
                  Elements2.getExecutableElementAsMemberOf(
                      types, interfaceMethod, implementingType);
              implementationMethodDescriptors.add(
                  new ImplementationMethodDescriptor.Builder()
                      .name(interfaceMethod.getSimpleName().toString())
                      .returnType(getAnnotatedType(element).getQualifiedName().toString())
                      .publicMethod()
                      .passedParameters(
                          Parameter.forParameterList(
                              interfaceMethod.getParameters(), methodType.getParameterTypes()))
                      .build());
            }
          }
        }
      }

      ImmutableSet<FactoryMethodDescriptor> descriptors =
          factoryDescriptorGenerator.generateDescriptor(element);
      indexedMethods.putAll(
          Multimaps.index(
              descriptors,
              new Function<FactoryMethodDescriptor, String>() {
                @Override
                public String apply(FactoryMethodDescriptor descriptor) {
                  return descriptor.factoryName();
                }
              }));
    }

    for (Entry<String, Collection<FactoryMethodDescriptor>> entry :
        indexedMethods.build().asMap().entrySet()) {
      ImmutableSet.Builder<String> extending = ImmutableSet.builder();
      ImmutableSortedSet.Builder<String> implementing = ImmutableSortedSet.naturalOrder();
      boolean publicType = false;
      Boolean allowSubclasses = null;
      boolean skipCreation = false;
      for (FactoryMethodDescriptor methodDescriptor : entry.getValue()) {
        extending.add(methodDescriptor.declaration().extendingType().getQualifiedName().toString());
        for (TypeElement implementingType : methodDescriptor.declaration().implementingTypes()) {
          implementing.add(implementingType.getQualifiedName().toString());
        }
        publicType |= methodDescriptor.publicMethod();
        if (allowSubclasses == null) {
          allowSubclasses = methodDescriptor.declaration().allowSubclasses();
        } else if (!allowSubclasses.equals(methodDescriptor.declaration().allowSubclasses())) {
          skipCreation = true;
          messager.printMessage(
              Kind.ERROR,
              "Cannot mix allowSubclasses=true and allowSubclasses=false in one factory.",
              methodDescriptor.declaration().target(),
              methodDescriptor.declaration().mirror(),
              methodDescriptor.declaration().valuesMap().get("allowSubclasses"));
        }
      }
      if (!skipCreation) {
        try {
          factoryWriter.writeFactory(
              new FactoryDescriptor(
                  entry.getKey(),
                  Iterables.getOnlyElement(extending.build()),
                  implementing.build(),
                  publicType,
                  ImmutableSet.copyOf(entry.getValue()),
                  // TODO(gak): this needs to be indexed too
                  implementationMethodDescriptors.build(),
                  allowSubclasses));
        } catch (IOException e) {
          messager.printMessage(Kind.ERROR, "failed");
        }
      }
    }
  }
Пример #5
0
 public Builder putAll(ListMultimap<CellLabel, Cell> cellMap) {
   cellsBuilder.putAll(cellMap);
   return this;
 }