private void writeRunnerProject() throws IOException, XmlException, ParseException {
        // TODO revise whole method
        // TODO now using a newer JAPA (suuports java 8), -> maybe ANTLR supports better
        PathUtils.createDir(getRunnerProjectSettings().getBaseDir().toPath());
        // copy snippets
        PathUtils.copy(getSnippetProject().getSourceDir(),
                getRunnerProjectSettings().getSnippetSourceDirectory().toPath());
        // create INFO file
        writeInfoFile();
        // remove SETTE annotations and imports from file
        Collection<File> filesWritten = Files
                .walk(getRunnerProjectSettings().getSnippetSourceDirectory().toPath())
                .filter(Files::isRegularFile).map(Path::toFile).sorted()
                .collect(Collectors.toList());
        for (File file : filesWritten) {
            // parse source with JavaParser
            log.debug("Parsing with JavaParser: {}", file);
            CompilationUnit compilationUnit = JavaParser.parse(file);
            log.debug("Parsed with JavaParser: {}", file);
            // extract type
            List<TypeDeclaration> types = compilationUnit.getTypes();
            if (types.size() != 1) {
                // NOTE better exception type
                throw new RuntimeException(
                        "Java source files containing more that one types are not supported");
            }
            TypeDeclaration type = types.get(0);
            // skip file if Java version is not supported by the tool (@SetteSnippetContainer)
            // NOTE it can be also done with snippet containers... (and also done in CATG
            // generator!)
            List<AnnotationExpr> classAnnotations = type.getAnnotations();
            JavaVersion reqJavaVer = getRequiredJavaVersion(classAnnotations);
            if (reqJavaVer != null && !getTool().supportsJavaVersion(reqJavaVer)) {
                System.err.println(
                        "Skipping file: " + file + " (required Java version: " + reqJavaVer + ")");
                PathUtils.delete(file.toPath());
            } else {
                // remove SETTE annotations from the class
                Predicate<AnnotationExpr> isSetteAnnotation = (a -> a.getName().getName()
                        .startsWith("Sette"));
                classAnnotations.removeIf(isSetteAnnotation);
                // remove SETTE annotations from the members
                for (BodyDeclaration member : type.getMembers()) {
                    member.getAnnotations().removeIf(isSetteAnnotation);
                }
                // TODO enhance
                List<String> toRemovePrefixes = new ArrayList<>();
                toRemovePrefixes.add("hu.bme.mit.sette.snippets.inputs");
                toRemovePrefixes.add("hu.bme.mit.sette.common");
                // remove SETTE imports
                compilationUnit.getImports().removeIf(importDeclaration -> {
                    String impDecl = importDeclaration.getName().toString();
                    for (String prefix : toRemovePrefixes) {
                        if (impDecl.startsWith(prefix)) {
                            return true;
                        }
                    }
                    return false;
                });
                // save edited source code
                String source = compilationUnit.toString();
                if (type instanceof EnumDeclaration) {
                    // FIXME remove after javaparser bug is fixed
                    source = source.replaceFirst(type.getName() + "\\s+implements\\s*\\{",
                            type.getName() + " {");
                }
                PathUtils.write(file.toPath(), source.getBytes());
            }
        }
        // copy libraries
        if (getSnippetProject().getLibDir().toFile().exists()) {
            PathUtils.copy(getSnippetProject().getLibDir(),
                    getRunnerProjectSettings().getSnippetLibraryDirectory().toPath());
        }
        // create project
        this.eclipseProject.save(getRunnerProjectSettings().getBaseDir().toPath());
    }
private void writeRunnerProject() throws IOException, XmlException, ParseException {
       
       
        PathUtils.createDir(getRunnerProjectSettings().getBaseDir().toPath());
       
        PathUtils.copy(getSnippetProject().getSourceDir(),
                getRunnerProjectSettings().getSnippetSourceDirectory().toPath());
       
        writeInfoFile();
       
        Collection<File> filesWritten = Files
                .walk(getRunnerProjectSettings().getSnippetSourceDirectory().toPath())
                .filter(Files::isRegularFile).map(Path::toFile).sorted()
                .collect(Collectors.toList());
        for (File file : filesWritten) {
           
            log.debug("Parsing with JavaParser: {}", file);
            CompilationUnit compilationUnit = JavaParser.parse(file);
            log.debug("Parsed with JavaParser: {}", file);
           
            List<TypeDeclaration> types = compilationUnit.getTypes();
            if (types.size() != 1) {
               
                throw new RuntimeException(
                        "Java source files containing more that one types are not supported");
            }
            TypeDeclaration type = types.get(0);
           
           
           
            List<AnnotationExpr> classAnnotations = type.getAnnotations();
            JavaVersion reqJavaVer = getRequiredJavaVersion(classAnnotations);
            if (reqJavaVer != null && !getTool().supportsJavaVersion(reqJavaVer)) {
                System.err.println(
                        "Skipping file: " + file + " (required Java version: " + reqJavaVer + ")");
                PathUtils.delete(file.toPath());
            } else {
               
                Predicate<AnnotationExpr> isSetteAnnotation = (a -> a.getName().getName()
                        .startsWith("Sette"));
                classAnnotations.removeIf(isSetteAnnotation);
               
                for (BodyDeclaration member : type.getMembers()) {
                    member.getAnnotations().removeIf(isSetteAnnotation);
                }
               
                List<String> toRemovePrefixes = new ArrayList<>();
                toRemovePrefixes.add("hu.bme.mit.sette.snippets.inputs");
                toRemovePrefixes.add("hu.bme.mit.sette.common");
               
                compilationUnit.getImports().removeIf(importDeclaration -> {
                    String impDecl = importDeclaration.getName().toString();
                    for (String prefix : toRemovePrefixes) {
                        if (impDecl.startsWith(prefix)) {
                            return true;
                        }
                    }
                    return false;
                });
               
                String source = compilationUnit.toString();
                if (type instanceof EnumDeclaration) {
                   
                    source = source.replaceFirst(type.getName() + "\\s+implements\\s*\\{",
                            type.getName() + " {");
                }
                PathUtils.write(file.toPath(), source.getBytes());
            }
        }
       
        if (getSnippetProject().getLibDir().toFile().exists()) {
            PathUtils.copy(getSnippetProject().getLibDir(),
                    getRunnerProjectSettings().getSnippetLibraryDirectory().toPath());
        }
       
        this.eclipseProject.save(getRunnerProjectSettings().getBaseDir().toPath());
    }
private void writerunnerproject() throws ioexception, xmlexception, parseexception { pathutils.createdir(getrunnerprojectsettings().getbasedir().topath()); pathutils.copy(getsnippetproject().getsourcedir(), getrunnerprojectsettings().getsnippetsourcedirectory().topath()); writeinfofile(); collection<file> fileswritten = files .walk(getrunnerprojectsettings().getsnippetsourcedirectory().topath()) .filter(files::isregularfile).map(path::tofile).sorted() .collect(collectors.tolist()); for (file file : fileswritten) { log.debug("parsing with javaparser: {}", file); compilationunit compilationunit = javaparser.parse(file); log.debug("parsed with javaparser: {}", file); list<typedeclaration> types = compilationunit.gettypes(); if (types.size() != 1) { throw new runtimeexception( "java source files containing more that one types are not supported"); } typedeclaration type = types.get(0); list<annotationexpr> classannotations = type.getannotations(); javaversion reqjavaver = getrequiredjavaversion(classannotations); if (reqjavaver != null && !gettool().supportsjavaversion(reqjavaver)) { system.err.println( "skipping file: " + file + " (required java version: " + reqjavaver + ")"); pathutils.delete(file.topath()); } else { predicate<annotationexpr> issetteannotation = (a -> a.getname().getname() .startswith("sette")); classannotations.removeif(issetteannotation); for (bodydeclaration member : type.getmembers()) { member.getannotations().removeif(issetteannotation); } list<string> toremoveprefixes = new arraylist<>(); toremoveprefixes.add("hu.bme.mit.sette.snippets.inputs"); toremoveprefixes.add("hu.bme.mit.sette.common"); compilationunit.getimports().removeif(importdeclaration -> { string impdecl = importdeclaration.getname().tostring(); for (string prefix : toremoveprefixes) { if (impdecl.startswith(prefix)) { return true; } } return false; }); string source = compilationunit.tostring(); if (type instanceof enumdeclaration) { source = source.replacefirst(type.getname() + "\\s+implements\\s*\\{", type.getname() + " {"); } pathutils.write(file.topath(), source.getbytes()); } } if (getsnippetproject().getlibdir().tofile().exists()) { pathutils.copy(getsnippetproject().getlibdir(), getrunnerprojectsettings().getsnippetlibrarydirectory().topath()); } this.eclipseproject.save(getrunnerprojectsettings().getbasedir().topath()); }