Java Code Examples for java.util.LinkedHashSet#forEach()

The following examples show how to use java.util.LinkedHashSet#forEach() . 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: ImportDepsChecker.java    From bazel with Apache License 2.0 6 votes vote down vote up
private void outputMissingMembers(
    StringBuilder builder, ImmutableList<MissingMember> missingMembers) {
  LinkedHashSet<ClassInfo> classesWithMissingMembers = new LinkedHashSet<>();
  for (MissingMember missing : missingMembers) {
    builder
        .append("Missing member '")
        .append(missing.memberName())
        .append("' in class ")
        .append(missing.owner().internalName().replace('/', '.'))
        .append(" : name=")
        .append(missing.memberName())
        .append(", descriptor=")
        .append(missing.descriptor())
        .append('\n');
    classesWithMissingMembers.add(missing.owner());
  }
  if (!classesWithMissingMembers.isEmpty()) {
    builder.append("The class hierarchies of the classes with missing members:").append("\n");
    classesWithMissingMembers.forEach(
        missingClass -> printClassHierarchy(missingClass, builder, "    "));
  }
}
 
Example 2
Source File: StateCopyCommand.java    From gyro with Apache License 2.0 4 votes vote down vote up
public static boolean copyBackends(
    FileBackend inputBackend,
    FileBackend outputBackend,
    boolean deleteInput,
    boolean displayMessaging) {
    GyroUI ui = GyroCore.ui();
    LinkedHashSet<String> files = list(inputBackend)
        .filter(f -> f.endsWith(".gyro") && !f.contains(GyroCore.INIT_FILE))
        .collect(Collectors.toCollection(LinkedHashSet::new));

    if (files.isEmpty()) {
        if (displayMessaging) {
            ui.write("\n@|bold,green No state files found.|@\n");
        }
        return false;
    }

    if (displayMessaging) {
        files.forEach(file -> ui.write("@|green + Copy file: %s|@\n", file));

        if (!ui.readBoolean(
            Boolean.FALSE,
            "\nAre you sure you want to copy all files? @|red This will overwrite existing files!|@")) {
            return false;
        }
    }

    files.forEach(file -> {
        if (displayMessaging) {
            ui.write("@|magenta + Copying file: %s|@\n", file);
        }

        try (OutputStream out = new GyroOutputStream(outputBackend, file)) {
            InputStream in = new GyroInputStream(inputBackend, file);
            IoUtils.copy(in, out);
        } catch (IOException error) {
            throw new Bug(error);
        }

        if (deleteInput) {
            delete(inputBackend, file);
        }
    });

    return true;
}
 
Example 3
Source File: FrozerPlugin.java    From pro with GNU General Public License v3.0 4 votes vote down vote up
private static void rewrite(ModuleReference rootModule, LinkedHashSet<String> dependencies, LinkedHashSet<String> requires, Set<String> packages, ModuleFinder finder, Path destination) throws IOException {
  // create a map old package name -> new package name
  var rootModuleName = rootModule.descriptor().name();
  var internalRootModuleName = rootModuleName.replace('.', '/');
  var internalPackageNameMap = packages.stream()
      .map(name -> name.replace('.', '/'))
      .collect(toUnmodifiableMap(name -> name, name -> internalRootModuleName + '/' + name));
  //System.out.println(internalPackageNameMap);
  
  var newPackages = new HashSet<String>();
  
  Path path = destination.resolve(rootModuleName + ".jar");
  Files.createDirectories(path.getParent());
  try(var output = Files.newOutputStream(path);
      var outputStream = new JarOutputStream(output)) {
    
    // rewrite all the classes of the dependencies
    var entryNames = new HashSet<>();
    for(var dependency: dependencies) {
      var reference = finder.find(dependency).orElseThrow();
      try(var reader = reference.open()) {
        for(String filename: (Iterable<String>)reader.list()::iterator) {
          //System.out.println("filename " + filename);
          
          if (filename.equals("module-info.class") ||  // skip module-info
              filename.endsWith("/") ||                // skip all directories
              filename.startsWith("META-INF")) {       // skip META-INF
            continue;
          }
          
          if (!entryNames.add(filename)) {
            System.out.println("duplicate entry " + filename + " skip it !");
            continue;
          }
          
          try(var inputStream = reader.open(filename).orElseThrow(() -> new IOException("can not read " + filename))) {
            if (!filename.endsWith(".class")) {  // only rewrite .class
                                                 // otherwise copy the resources
              
              getPackage(filename).ifPresent(newPackages::add);
              
              outputStream.putNextEntry(new JarEntry(filename));
              inputStream.transferTo(outputStream);
              continue;
            }
          
            var newFilename = interpolateInternalName(internalPackageNameMap, filename);
            getPackage(newFilename).ifPresent(newPackages::add);
            outputStream.putNextEntry(new JarEntry(newFilename));
            outputStream.write(rewriteBytecode(internalPackageNameMap, inputStream.readAllBytes()));
          }
        }
      }
    }
    
    // then insert the new module-info and interpolate it
    outputStream.putNextEntry(new JarEntry("module-info.class"));
    
    var builder = ModuleDescriptor.newOpenModule(rootModuleName);
    var rootModuleDescriptor = rootModule.descriptor();
    
    rootModuleDescriptor.version().ifPresent(builder::version);
    requires.forEach(builder::requires);
    rootModuleDescriptor.exports().forEach(builder::exports);
    rootModuleDescriptor.opens().forEach(builder::opens);
    builder.packages(rootModuleDescriptor.packages());
    
    dependencies.stream()
      .flatMap(name -> finder.find(name).stream())
      .map(ModuleReference::descriptor)
      .forEach(descriptor -> {
        descriptor.provides().forEach(provides -> {
          builder.provides(
              interpolateClassName(internalPackageNameMap, provides.service()),
              provides.providers().stream().map(provider -> interpolateClassName(internalPackageNameMap, provider)).collect(toUnmodifiableList())
              );
        });
        descriptor.uses().forEach(uses -> builder.uses(interpolateClassName(internalPackageNameMap, uses)));
      });
    builder.packages(newPackages);
    var moduleDescriptor = builder.build();
    
    outputStream.write(ModuleHelper.moduleDescriptorToBinary(moduleDescriptor));
  }
}