Exemplo n.º 1
0
 public Stream<MethodInfo> getMethodStream() {
   return type.get()
       .getMembers()
       .stream()
       .map(this::getMethodInfoWrapper)
       .filter(Objects::nonNull);
 }
Exemplo n.º 2
0
 public Stream<FieldInfo> getFieldStream() {
   return type.get()
       .getMembers()
       .stream()
       .filter(x -> x instanceof FieldDeclaration)
       .map(x -> new FieldDeclarationWrapper((FieldDeclaration) x));
 }
Exemplo n.º 3
0
 @Override
 public List<Type> getInterfaceTypes() {
   return type.get()
       .getImplements()
       .stream()
       .map(getContext()::resolve)
       .collect(Collectors.toList());
 }
Exemplo n.º 4
0
  @Override
  public Type getSuperType() {
    val extends_ = type.get().getExtends();

    if (extends_ == null || extends_.isEmpty()) return null;

    return getContext().resolve(extends_.get(0));
  }
Exemplo n.º 5
0
 @Override
 public void setName(String name) {
   String packageName = getPackageName();
   if (name.startsWith(packageName)) {
     type.get().setName(name.replace(packageName, ""));
   } else {
     throw new TransformationException("Name '" + name + "' must be in package: " + packageName);
   }
 }
Exemplo n.º 6
0
  public static void main(String[] args) {
    // how many sales?
    long saleCount = saleStream().count();
    System.out.println("Count of sales: " + saleCount);

    // any sales over $100?
    Supplier<DoubleStream> totalStream = () -> saleStream().mapToDouble(Sale::total);
    boolean bigSaleDay = totalStream.get().anyMatch(total -> total > 100.00);
    System.out.println("Big sale day? " + bigSaleDay);

    // maximum sale amount?
    DoubleSummaryStatistics stats = totalStream.get().summaryStatistics();
    System.out.println("Max sale amount: " + stats.getMax());
    System.out.println("Stats on total: " + stats);

    // how many items were sold today?
    Supplier<Stream<Item>> itemStream = () -> saleStream().flatMap(sale -> sale.items.stream());
    long itemCount = itemStream.get().count();
    System.out.println("Count of items: " + itemCount);

    // which different items were sold today?
    String uniqueItems =
        itemStream.get().map(item -> item.identity).distinct().collect(Collectors.joining(" & "));
    System.out.println("Distinct items: " + uniqueItems);

    // summarize sales by store
    ConcurrentMap<String, DoubleSummaryStatistics> summary =
        saleStream()
            .parallel()
            .collect(
                Collectors.groupingByConcurrent(
                    sale -> Thread.currentThread().getName(),
                    Collectors.summarizingDouble(Sale::total)));
    System.out.println("Summary by thread: " + summary);
    summary
        .keySet()
        .stream()
        .sorted()
        .forEach(store -> System.out.println(store + " stats: " + summary.get(store)));
  }
Exemplo n.º 7
0
  @Override
  public void remove(FieldInfo field) {
    FieldDeclarationWrapper fieldDeclarationWrapper =
        !(field instanceof FieldDeclarationWrapper)
            ? (FieldDeclarationWrapper) get(field)
            : (FieldDeclarationWrapper) field;

    if (fieldDeclarationWrapper == null)
      throw new TransformationException(
          "Field " + field + " can not be removed as it is not present");

    type.get().getMembers().remove(fieldDeclarationWrapper.declaration);
  }
Exemplo n.º 8
0
  @Override
  public void remove(MethodInfo method) {
    MethodDeclarationWrapper methodDeclarationWrapper =
        !(method instanceof MethodDeclarationWrapper)
            ? (MethodDeclarationWrapper) get(method)
            : (MethodDeclarationWrapper) method;

    if (methodDeclarationWrapper == null)
      throw new TransformationException(
          "Method " + method + " can not be removed as it is not present");

    type.get().getMembers().remove(methodDeclarationWrapper.declaration);
  }
Exemplo n.º 9
0
 @Override
 public void setAccessFlags(AccessFlags accessFlags) {
   type.get().setModifiers(accessFlags.access);
 }
Exemplo n.º 10
0
 @Override
 public AccessFlags getAccessFlags() {
   return new AccessFlags(type.get().getModifiers());
 }
Exemplo n.º 11
0
 private ResolutionContext getContextInternal() {
   return ResolutionContext.of(type.get());
 }
Exemplo n.º 12
0
 private String getPackageNameInternal() {
   return NodeUtil.qualifiedName(
       NodeUtil.getParentNode(type.get(), CompilationUnit.class).getPackage().getName());
 }
Exemplo n.º 13
0
 private List<Annotation> getAnnotationsInternal() {
   return getAnnotationsInternal(type.get().getAnnotations());
 }
Exemplo n.º 14
0
 private void addMember(BodyDeclaration bodyDeclaration) {
   bodyDeclaration.setParentNode(type.get());
   type.get().getMembers().add(bodyDeclaration);
 }