repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
octopus-platform/octopus
src/main/java/octopus/server/restServer/handlers/DeleteProjectHandler.java
// Path: src/main/java/octopus/api/projects/ProjectManager.java // public class ProjectManager { // // public void create(String projectName) // { // try { // OctopusProjectManager.create(projectName); // } catch (IOException e) { // throw new RuntimeException("Error creating project"); // } // } // // public boolean doesProjectExist(String projectName) // { // return OctopusProjectManager.doesProjectExist(projectName); // } // // public void delete(String projectName) // { // try { // OctopusProjectManager.delete(projectName); // } catch (IOException e) { // throw new RuntimeException("Error deleting project"); // } // } // // public Iterable<String> listProjects() // { // return OctopusProjectManager.listProjects(); // } // // public OctopusProject getProjectByName(String name) // { // return OctopusProjectManager.getProjectByName(name); // } // // } // // Path: src/main/java/octopus/server/restServer/OctopusRestHandler.java // public interface OctopusRestHandler { // // public Object handle(Request req, Response resp); // // }
import octopus.api.projects.ProjectManager; import octopus.server.restServer.OctopusRestHandler; import spark.Request; import spark.Response;
package octopus.server.restServer.handlers; public class DeleteProjectHandler implements OctopusRestHandler { @Override public Object handle(Request req, Response resp) { String projectName = req.params(":projectName");
// Path: src/main/java/octopus/api/projects/ProjectManager.java // public class ProjectManager { // // public void create(String projectName) // { // try { // OctopusProjectManager.create(projectName); // } catch (IOException e) { // throw new RuntimeException("Error creating project"); // } // } // // public boolean doesProjectExist(String projectName) // { // return OctopusProjectManager.doesProjectExist(projectName); // } // // public void delete(String projectName) // { // try { // OctopusProjectManager.delete(projectName); // } catch (IOException e) { // throw new RuntimeException("Error deleting project"); // } // } // // public Iterable<String> listProjects() // { // return OctopusProjectManager.listProjects(); // } // // public OctopusProject getProjectByName(String name) // { // return OctopusProjectManager.getProjectByName(name); // } // // } // // Path: src/main/java/octopus/server/restServer/OctopusRestHandler.java // public interface OctopusRestHandler { // // public Object handle(Request req, Response resp); // // } // Path: src/main/java/octopus/server/restServer/handlers/DeleteProjectHandler.java import octopus.api.projects.ProjectManager; import octopus.server.restServer.OctopusRestHandler; import spark.Request; import spark.Response; package octopus.server.restServer.handlers; public class DeleteProjectHandler implements OctopusRestHandler { @Override public Object handle(Request req, Response resp) { String projectName = req.params(":projectName");
ProjectManager manager = new ProjectManager();
octopus-platform/octopus
src/main/java/octopus/api/projects/ProjectManager.java
// Path: src/main/java/octopus/server/projectmanager/OctopusProjectManager.java // public class OctopusProjectManager // { // // private static Path projectsDir; // private static Map<String, OctopusProject> nameToProject = new HashMap<String, OctopusProject>(); // // private static final Logger logger = LoggerFactory // .getLogger(OctopusProjectManager.class); // // private static boolean initialized = false; // // static // { // try { // initialize(OctopusEnvironment.PROJECTS_DIR); // } catch (IOException e) { // throw new RuntimeException("Error initializing OctopusProjectManager"); // } // } // // public static void initialize(Path projectDir) throws IOException // { // if(initialized) // return; // // setProjectDir(projectDir); // initialized = true; // } // // public static void setProjectDir(Path newProjectsDir) throws IOException // { // if (!newProjectsDir.isAbsolute()) // { // newProjectsDir = newProjectsDir.toAbsolutePath(); // } // projectsDir = newProjectsDir.normalize(); // openProjectsDir(); // loadProjects(); // } // // private static void openProjectsDir() throws IOException // { // if (Files.notExists(projectsDir)) // { // Files.createDirectories(projectsDir); // } // } // // private static void loadProjects() throws IOException // { // try (DirectoryStream<Path> stream = Files.newDirectoryStream(projectsDir)) // { // for (Path path : stream) // { // if (Files.isDirectory(path)) // { // loadProject(path); // } // } // } // } // // private static void loadProject(Path projectDir) throws IOException // { // String projectName = projectDir.getFileName().toString(); // OctopusProject newProject = createOctopusProjectForName(projectName); // logger.debug("Adding project to map: " + projectName); // nameToProject.put(projectName, newProject); // } // // public static boolean doesProjectExist(String name) // { // return nameToProject.containsKey(name); // } // // public static OctopusProject getProjectByName(String name) // { // logger.debug("requesting project: " + name); // return nameToProject.get(name); // } // // public static Path getPathToProject(String name) // { // if (projectsDir == null) // throw new IllegalStateException("Error: projectDir not set"); // // return Paths.get(projectsDir.toString(), name); // } // // public static void create(String name) throws IOException // { // if (projectsDir == null) // throw new IllegalStateException("Error: projectDir not set"); // // if (doesProjectExist(name)) // throw new RuntimeException("Project already exists"); // // OctopusProject project = createOctopusProjectForName(name); // TitanLocalDatabaseManager databaseManager = new TitanLocalDatabaseManager(); // databaseManager.initializeDatabaseForProject(project); // logger.debug("Adding project to map: " + name); // nameToProject.put(name, project); // } // // public static void delete(String name) throws IOException // { // if (projectsDir == null) // throw new IllegalStateException("Error: projectDir not set"); // // deleteProjectWithName(name); // } // // public static Iterable<String> listProjects() // { // return nameToProject.keySet(); // } // // private static OctopusProject createOctopusProjectForName(String name) throws IOException // { // Path pathToProject = getPathToProject(name); // Files.createDirectories(pathToProject); // // OctopusProject newProject = new OctopusProject(name, pathToProject.toString()); // // return newProject; // } // // private static void deleteProjectWithName(String name) throws IOException // { // removeDatabaseIfExists(name); // deleteProjectFiles(name); // nameToProject.remove(name); // } // // private static void deleteProjectFiles(String name) throws IOException // { // Path pathToProject = getPathToProject(name); // Files.walkFileTree(pathToProject, new SimpleFileVisitor<Path>() // { // @Override // public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException // { // Files.delete(file); // return FileVisitResult.CONTINUE; // } // // @Override // public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException // { // Files.delete(dir); // return FileVisitResult.CONTINUE; // } // }); // } // // private static void removeDatabaseIfExists(String name) throws IOException // { // OctopusProject project = new ProjectManager().getProjectByName(name); // // TitanLocalDatabaseManager dbManager = new TitanLocalDatabaseManager(); // dbManager.deleteDatabaseForProject(project); // } // // }
import java.io.IOException; import octopus.server.projectmanager.OctopusProjectManager;
package octopus.api.projects; public class ProjectManager { public void create(String projectName) { try {
// Path: src/main/java/octopus/server/projectmanager/OctopusProjectManager.java // public class OctopusProjectManager // { // // private static Path projectsDir; // private static Map<String, OctopusProject> nameToProject = new HashMap<String, OctopusProject>(); // // private static final Logger logger = LoggerFactory // .getLogger(OctopusProjectManager.class); // // private static boolean initialized = false; // // static // { // try { // initialize(OctopusEnvironment.PROJECTS_DIR); // } catch (IOException e) { // throw new RuntimeException("Error initializing OctopusProjectManager"); // } // } // // public static void initialize(Path projectDir) throws IOException // { // if(initialized) // return; // // setProjectDir(projectDir); // initialized = true; // } // // public static void setProjectDir(Path newProjectsDir) throws IOException // { // if (!newProjectsDir.isAbsolute()) // { // newProjectsDir = newProjectsDir.toAbsolutePath(); // } // projectsDir = newProjectsDir.normalize(); // openProjectsDir(); // loadProjects(); // } // // private static void openProjectsDir() throws IOException // { // if (Files.notExists(projectsDir)) // { // Files.createDirectories(projectsDir); // } // } // // private static void loadProjects() throws IOException // { // try (DirectoryStream<Path> stream = Files.newDirectoryStream(projectsDir)) // { // for (Path path : stream) // { // if (Files.isDirectory(path)) // { // loadProject(path); // } // } // } // } // // private static void loadProject(Path projectDir) throws IOException // { // String projectName = projectDir.getFileName().toString(); // OctopusProject newProject = createOctopusProjectForName(projectName); // logger.debug("Adding project to map: " + projectName); // nameToProject.put(projectName, newProject); // } // // public static boolean doesProjectExist(String name) // { // return nameToProject.containsKey(name); // } // // public static OctopusProject getProjectByName(String name) // { // logger.debug("requesting project: " + name); // return nameToProject.get(name); // } // // public static Path getPathToProject(String name) // { // if (projectsDir == null) // throw new IllegalStateException("Error: projectDir not set"); // // return Paths.get(projectsDir.toString(), name); // } // // public static void create(String name) throws IOException // { // if (projectsDir == null) // throw new IllegalStateException("Error: projectDir not set"); // // if (doesProjectExist(name)) // throw new RuntimeException("Project already exists"); // // OctopusProject project = createOctopusProjectForName(name); // TitanLocalDatabaseManager databaseManager = new TitanLocalDatabaseManager(); // databaseManager.initializeDatabaseForProject(project); // logger.debug("Adding project to map: " + name); // nameToProject.put(name, project); // } // // public static void delete(String name) throws IOException // { // if (projectsDir == null) // throw new IllegalStateException("Error: projectDir not set"); // // deleteProjectWithName(name); // } // // public static Iterable<String> listProjects() // { // return nameToProject.keySet(); // } // // private static OctopusProject createOctopusProjectForName(String name) throws IOException // { // Path pathToProject = getPathToProject(name); // Files.createDirectories(pathToProject); // // OctopusProject newProject = new OctopusProject(name, pathToProject.toString()); // // return newProject; // } // // private static void deleteProjectWithName(String name) throws IOException // { // removeDatabaseIfExists(name); // deleteProjectFiles(name); // nameToProject.remove(name); // } // // private static void deleteProjectFiles(String name) throws IOException // { // Path pathToProject = getPathToProject(name); // Files.walkFileTree(pathToProject, new SimpleFileVisitor<Path>() // { // @Override // public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException // { // Files.delete(file); // return FileVisitResult.CONTINUE; // } // // @Override // public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException // { // Files.delete(dir); // return FileVisitResult.CONTINUE; // } // }); // } // // private static void removeDatabaseIfExists(String name) throws IOException // { // OctopusProject project = new ProjectManager().getProjectByName(name); // // TitanLocalDatabaseManager dbManager = new TitanLocalDatabaseManager(); // dbManager.deleteDatabaseForProject(project); // } // // } // Path: src/main/java/octopus/api/projects/ProjectManager.java import java.io.IOException; import octopus.server.projectmanager.OctopusProjectManager; package octopus.api.projects; public class ProjectManager { public void create(String projectName) { try {
OctopusProjectManager.create(projectName);
octopus-platform/octopus
src/main/java/octopus/server/pluginInterface/PluginLoader.java
// Path: src/main/java/octopus/api/plugin/Plugin.java // public interface Plugin // { // void configure(JSONObject settings); // // void execute() throws Exception; // // default void beforeExecution() throws Exception {} // // default void afterExecution() throws Exception {} // // default Object result() // { // return null; // } // }
import java.nio.file.Path; import octopus.api.plugin.Plugin;
package octopus.server.pluginInterface; public class PluginLoader {
// Path: src/main/java/octopus/api/plugin/Plugin.java // public interface Plugin // { // void configure(JSONObject settings); // // void execute() throws Exception; // // default void beforeExecution() throws Exception {} // // default void afterExecution() throws Exception {} // // default Object result() // { // return null; // } // } // Path: src/main/java/octopus/server/pluginInterface/PluginLoader.java import java.nio.file.Path; import octopus.api.plugin.Plugin; package octopus.server.pluginInterface; public class PluginLoader {
public static Plugin load(Path pathToJar, String pluginClass)
octopus-platform/octopus
src/main/java/octopus/api/projects/OctopusProjectWrapper.java
// Path: src/main/java/octopus/api/database/Database.java // public interface Database { // // // /** // * Return a tinkerpop3 graph instance // * */ // // public Graph getGraph(); // // public void closeInstance(); // // }
import octopus.api.database.Database;
package octopus.api.projects; public class OctopusProjectWrapper { private OctopusProject oProject; public void setWrappedProject(OctopusProject project) { oProject = project; } public OctopusProject unwrap() { return oProject; } public String getPathToProjectDir() { return oProject.getPathToProjectDir(); }
// Path: src/main/java/octopus/api/database/Database.java // public interface Database { // // // /** // * Return a tinkerpop3 graph instance // * */ // // public Graph getGraph(); // // public void closeInstance(); // // } // Path: src/main/java/octopus/api/projects/OctopusProjectWrapper.java import octopus.api.database.Database; package octopus.api.projects; public class OctopusProjectWrapper { private OctopusProject oProject; public void setWrappedProject(OctopusProject project) { oProject = project; } public OctopusProject unwrap() { return oProject; } public String getPathToProjectDir() { return oProject.getPathToProjectDir(); }
public Database getNewDatabaseInstance()
octopus-platform/octopus
src/main/java/octopus/api/decompressor/Decompressor.java
// Path: src/main/java/octopus/server/decompressor/TarballDecompressor.java // public class TarballDecompressor { // // public void decompress(String tarballFilename, String outputDirectory) throws FileNotFoundException, IOException // { // if(!outputDirectory.endsWith(File.separator)) // outputDirectory = outputDirectory + File.separator; // // TarArchiveInputStream tarIn = createTarInputStreamForFile(tarballFilename); // // TarArchiveEntry entry; // while ((entry = (TarArchiveEntry) tarIn.getNextEntry()) != null) // { // String outputFilename = outputDirectory + entry.getName(); // // if(outputFilename.contains("pax_global_header")) // continue; // // if (entry.isDirectory()) { // createOutputSubDirectory(outputFilename); // continue; // } // decompressFileToOutputDirectory(tarIn, outputFilename); // } // tarIn.close(); // } // // private TarArchiveInputStream createTarInputStreamForFile(String tarballFilename) // throws FileNotFoundException, IOException // { // FileInputStream fin = new FileInputStream(tarballFilename); // BufferedInputStream in = new BufferedInputStream(fin); // GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in); // TarArchiveInputStream tarIn = new TarArchiveInputStream(gzIn); // return tarIn; // } // // private void createOutputSubDirectory(String outputFilename) // { // File f = new File(outputFilename); // f.mkdirs(); // } // // private void decompressFileToOutputDirectory(TarArchiveInputStream tarIn, String outputFilename) throws IOException // { // final int BUFFER_SIZE = 2048; // byte data[] = new byte[BUFFER_SIZE]; // int bytesRead; // // FileOutputStream fos = new FileOutputStream(outputFilename); // BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE); // while ((bytesRead = tarIn.read(data, 0, BUFFER_SIZE)) != -1) // { // dest.write(data, 0, bytesRead); // } // dest.close(); // // } // // }
import java.io.FileNotFoundException; import java.io.IOException; import octopus.server.decompressor.TarballDecompressor;
package octopus.api.decompressor; public class Decompressor { public void decompressTarball(String tarballFilename, String outputDirectory) throws FileNotFoundException, IOException {
// Path: src/main/java/octopus/server/decompressor/TarballDecompressor.java // public class TarballDecompressor { // // public void decompress(String tarballFilename, String outputDirectory) throws FileNotFoundException, IOException // { // if(!outputDirectory.endsWith(File.separator)) // outputDirectory = outputDirectory + File.separator; // // TarArchiveInputStream tarIn = createTarInputStreamForFile(tarballFilename); // // TarArchiveEntry entry; // while ((entry = (TarArchiveEntry) tarIn.getNextEntry()) != null) // { // String outputFilename = outputDirectory + entry.getName(); // // if(outputFilename.contains("pax_global_header")) // continue; // // if (entry.isDirectory()) { // createOutputSubDirectory(outputFilename); // continue; // } // decompressFileToOutputDirectory(tarIn, outputFilename); // } // tarIn.close(); // } // // private TarArchiveInputStream createTarInputStreamForFile(String tarballFilename) // throws FileNotFoundException, IOException // { // FileInputStream fin = new FileInputStream(tarballFilename); // BufferedInputStream in = new BufferedInputStream(fin); // GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in); // TarArchiveInputStream tarIn = new TarArchiveInputStream(gzIn); // return tarIn; // } // // private void createOutputSubDirectory(String outputFilename) // { // File f = new File(outputFilename); // f.mkdirs(); // } // // private void decompressFileToOutputDirectory(TarArchiveInputStream tarIn, String outputFilename) throws IOException // { // final int BUFFER_SIZE = 2048; // byte data[] = new byte[BUFFER_SIZE]; // int bytesRead; // // FileOutputStream fos = new FileOutputStream(outputFilename); // BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE); // while ((bytesRead = tarIn.read(data, 0, BUFFER_SIZE)) != -1) // { // dest.write(data, 0, bytesRead); // } // dest.close(); // // } // // } // Path: src/main/java/octopus/api/decompressor/Decompressor.java import java.io.FileNotFoundException; import java.io.IOException; import octopus.server.decompressor.TarballDecompressor; package octopus.api.decompressor; public class Decompressor { public void decompressTarball(String tarballFilename, String outputDirectory) throws FileNotFoundException, IOException {
(new TarballDecompressor()).decompress(tarballFilename, outputDirectory);;
octopus-platform/octopus
src/main/java/octopus/api/csvImporter/CSVImporter.java
// Path: src/main/java/octopus/server/importer/csv/ImportCSVRunnable.java // public class ImportCSVRunnable implements Runnable // { // // private static final Logger logger = LoggerFactory // .getLogger(ImportCSVRunnable.class); // // private final ImportJob importJob; // // public ImportCSVRunnable(ImportJob importJob) // { // this.importJob = importJob; // } // // @Override // public void run() // { // // CSVImporter csvBatchImporter = new CSVImporter(); // // String nodeFilename = importJob.getNodeFilename(); // String edgeFilename = importJob.getEdgeFilename(); // String projectName = importJob.getProjectName(); // // ProjectManager projectManager = new ProjectManager(); // OctopusProject project = projectManager.getProjectByName(projectName); // if(project == null) // throw new RuntimeException("Error: project dos not exist"); // // try // { // Database database = project.getNewDatabaseInstance(); // csvBatchImporter.setGraph(database.getGraph()); // csvBatchImporter.importCSVFiles(nodeFilename, edgeFilename); // database.closeInstance(); // } // catch (IOException e) // { // e.printStackTrace(); // } // // logger.warn("Import finished"); // } // // } // // Path: src/main/java/octopus/server/importer/csv/ImportJob.java // public class ImportJob // { // private final String nodeFilename; // private final String edgeFilename; // private final String projectName; // // public ImportJob(String nodeFilename, String edgeFilename, String projectName) // { // this.nodeFilename = nodeFilename; // this.edgeFilename = edgeFilename; // this.projectName = projectName; // } // // public String getNodeFilename() // { // return nodeFilename; // } // // public String getEdgeFilename() // { // return edgeFilename; // } // // public String getProjectName() // { // return projectName; // } // // }
import octopus.server.importer.csv.ImportCSVRunnable; import octopus.server.importer.csv.ImportJob;
package octopus.api.csvImporter; public class CSVImporter { public void importCSV(ImportJob job) {
// Path: src/main/java/octopus/server/importer/csv/ImportCSVRunnable.java // public class ImportCSVRunnable implements Runnable // { // // private static final Logger logger = LoggerFactory // .getLogger(ImportCSVRunnable.class); // // private final ImportJob importJob; // // public ImportCSVRunnable(ImportJob importJob) // { // this.importJob = importJob; // } // // @Override // public void run() // { // // CSVImporter csvBatchImporter = new CSVImporter(); // // String nodeFilename = importJob.getNodeFilename(); // String edgeFilename = importJob.getEdgeFilename(); // String projectName = importJob.getProjectName(); // // ProjectManager projectManager = new ProjectManager(); // OctopusProject project = projectManager.getProjectByName(projectName); // if(project == null) // throw new RuntimeException("Error: project dos not exist"); // // try // { // Database database = project.getNewDatabaseInstance(); // csvBatchImporter.setGraph(database.getGraph()); // csvBatchImporter.importCSVFiles(nodeFilename, edgeFilename); // database.closeInstance(); // } // catch (IOException e) // { // e.printStackTrace(); // } // // logger.warn("Import finished"); // } // // } // // Path: src/main/java/octopus/server/importer/csv/ImportJob.java // public class ImportJob // { // private final String nodeFilename; // private final String edgeFilename; // private final String projectName; // // public ImportJob(String nodeFilename, String edgeFilename, String projectName) // { // this.nodeFilename = nodeFilename; // this.edgeFilename = edgeFilename; // this.projectName = projectName; // } // // public String getNodeFilename() // { // return nodeFilename; // } // // public String getEdgeFilename() // { // return edgeFilename; // } // // public String getProjectName() // { // return projectName; // } // // } // Path: src/main/java/octopus/api/csvImporter/CSVImporter.java import octopus.server.importer.csv.ImportCSVRunnable; import octopus.server.importer.csv.ImportJob; package octopus.api.csvImporter; public class CSVImporter { public void importCSV(ImportJob job) {
(new ImportCSVRunnable(job)).run();
octopus-platform/octopus
src/main/java/octopus/server/restServer/handlers/ListProjectsHandler.java
// Path: src/main/java/octopus/api/projects/ProjectManager.java // public class ProjectManager { // // public void create(String projectName) // { // try { // OctopusProjectManager.create(projectName); // } catch (IOException e) { // throw new RuntimeException("Error creating project"); // } // } // // public boolean doesProjectExist(String projectName) // { // return OctopusProjectManager.doesProjectExist(projectName); // } // // public void delete(String projectName) // { // try { // OctopusProjectManager.delete(projectName); // } catch (IOException e) { // throw new RuntimeException("Error deleting project"); // } // } // // public Iterable<String> listProjects() // { // return OctopusProjectManager.listProjects(); // } // // public OctopusProject getProjectByName(String name) // { // return OctopusProjectManager.getProjectByName(name); // } // // } // // Path: src/main/java/octopus/server/restServer/OctopusRestHandler.java // public interface OctopusRestHandler { // // public Object handle(Request req, Response resp); // // }
import octopus.api.projects.ProjectManager; import octopus.server.restServer.OctopusRestHandler; import spark.Request; import spark.Response;
package octopus.server.restServer.handlers; public class ListProjectsHandler implements OctopusRestHandler { @Override public Object handle(Request req, Response resp) {
// Path: src/main/java/octopus/api/projects/ProjectManager.java // public class ProjectManager { // // public void create(String projectName) // { // try { // OctopusProjectManager.create(projectName); // } catch (IOException e) { // throw new RuntimeException("Error creating project"); // } // } // // public boolean doesProjectExist(String projectName) // { // return OctopusProjectManager.doesProjectExist(projectName); // } // // public void delete(String projectName) // { // try { // OctopusProjectManager.delete(projectName); // } catch (IOException e) { // throw new RuntimeException("Error deleting project"); // } // } // // public Iterable<String> listProjects() // { // return OctopusProjectManager.listProjects(); // } // // public OctopusProject getProjectByName(String name) // { // return OctopusProjectManager.getProjectByName(name); // } // // } // // Path: src/main/java/octopus/server/restServer/OctopusRestHandler.java // public interface OctopusRestHandler { // // public Object handle(Request req, Response resp); // // } // Path: src/main/java/octopus/server/restServer/handlers/ListProjectsHandler.java import octopus.api.projects.ProjectManager; import octopus.server.restServer.OctopusRestHandler; import spark.Request; import spark.Response; package octopus.server.restServer.handlers; public class ListProjectsHandler implements OctopusRestHandler { @Override public Object handle(Request req, Response resp) {
Iterable<String> projects = (new ProjectManager()).listProjects();
octopus-platform/octopus
src/main/java/octopus/server/ftpserver/OctopusFTPServer.java
// Path: src/main/java/octopus/OctopusEnvironment.java // public class OctopusEnvironment { // // private static final String OCTOPUS_HOME_STR; // private static final String DATA_STR = "data"; // private static final String PROJECTS_STR = "projects"; // private static final String PLUGINS_STR = "plugins"; // private static final String LANGUAGES_STR = "languages"; // // public static final Path PROJECTS_DIR; // public static final Path PLUGINS_DIR; // public static final Path LANGUAGES_DIR; // // static { // // OCTOPUS_HOME_STR = System.getProperty("OCTOPUS_HOME"); // // if (OCTOPUS_HOME_STR == null) // { // throw new RuntimeException("System property OCTOPUS_HOME not defined."); // } // // PROJECTS_DIR = Paths.get(OCTOPUS_HOME_STR, DATA_STR, PROJECTS_STR); // PLUGINS_DIR = Paths.get(OCTOPUS_HOME_STR, PLUGINS_STR); // LANGUAGES_DIR = Paths.get(OCTOPUS_HOME_STR, LANGUAGES_STR); // // } // // }
import java.util.ArrayList; import java.util.List; import org.apache.ftpserver.ConnectionConfigFactory; import org.apache.ftpserver.FtpServer; import org.apache.ftpserver.FtpServerFactory; import org.apache.ftpserver.ftplet.Authority; import org.apache.ftpserver.ftplet.FtpException; import org.apache.ftpserver.listener.ListenerFactory; import org.apache.ftpserver.usermanager.impl.BaseUser; import org.apache.ftpserver.usermanager.impl.WritePermission; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import octopus.OctopusEnvironment;
package octopus.server.ftpserver; public class OctopusFTPServer { private static final Logger logger = LoggerFactory .getLogger(OctopusFTPServer.class); private static final String FTP_SERVER_HOST = "localhost"; private static final int FTP_SERVER_PORT = 23231; FtpServer server; FtpServerFactory serverFactory = new FtpServerFactory(); ListenerFactory factory = new ListenerFactory(); ConnectionConfigFactory connectionConfigFactory = new ConnectionConfigFactory(); public void start() throws FtpException { factory.setPort(FTP_SERVER_PORT); factory.setServerAddress(FTP_SERVER_HOST); configureAnonymousLogin(); serverFactory.addListener("default", factory.createListener()); server = serverFactory.createServer(); server.start(); } private void configureAnonymousLogin() throws FtpException { connectionConfigFactory.setAnonymousLoginEnabled(true); serverFactory.setConnectionConfig(connectionConfigFactory.createConnectionConfig()); BaseUser user = configureAnonymousUser();
// Path: src/main/java/octopus/OctopusEnvironment.java // public class OctopusEnvironment { // // private static final String OCTOPUS_HOME_STR; // private static final String DATA_STR = "data"; // private static final String PROJECTS_STR = "projects"; // private static final String PLUGINS_STR = "plugins"; // private static final String LANGUAGES_STR = "languages"; // // public static final Path PROJECTS_DIR; // public static final Path PLUGINS_DIR; // public static final Path LANGUAGES_DIR; // // static { // // OCTOPUS_HOME_STR = System.getProperty("OCTOPUS_HOME"); // // if (OCTOPUS_HOME_STR == null) // { // throw new RuntimeException("System property OCTOPUS_HOME not defined."); // } // // PROJECTS_DIR = Paths.get(OCTOPUS_HOME_STR, DATA_STR, PROJECTS_STR); // PLUGINS_DIR = Paths.get(OCTOPUS_HOME_STR, PLUGINS_STR); // LANGUAGES_DIR = Paths.get(OCTOPUS_HOME_STR, LANGUAGES_STR); // // } // // } // Path: src/main/java/octopus/server/ftpserver/OctopusFTPServer.java import java.util.ArrayList; import java.util.List; import org.apache.ftpserver.ConnectionConfigFactory; import org.apache.ftpserver.FtpServer; import org.apache.ftpserver.FtpServerFactory; import org.apache.ftpserver.ftplet.Authority; import org.apache.ftpserver.ftplet.FtpException; import org.apache.ftpserver.listener.ListenerFactory; import org.apache.ftpserver.usermanager.impl.BaseUser; import org.apache.ftpserver.usermanager.impl.WritePermission; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import octopus.OctopusEnvironment; package octopus.server.ftpserver; public class OctopusFTPServer { private static final Logger logger = LoggerFactory .getLogger(OctopusFTPServer.class); private static final String FTP_SERVER_HOST = "localhost"; private static final int FTP_SERVER_PORT = 23231; FtpServer server; FtpServerFactory serverFactory = new FtpServerFactory(); ListenerFactory factory = new ListenerFactory(); ConnectionConfigFactory connectionConfigFactory = new ConnectionConfigFactory(); public void start() throws FtpException { factory.setPort(FTP_SERVER_PORT); factory.setServerAddress(FTP_SERVER_HOST); configureAnonymousLogin(); serverFactory.addListener("default", factory.createListener()); server = serverFactory.createServer(); server.start(); } private void configureAnonymousLogin() throws FtpException { connectionConfigFactory.setAnonymousLoginEnabled(true); serverFactory.setConnectionConfig(connectionConfigFactory.createConnectionConfig()); BaseUser user = configureAnonymousUser();
String projectDirStr = OctopusEnvironment.PROJECTS_DIR.toString();
octopus-platform/octopus
src/main/java/octopus/api/plugin/PluginExecutor.java
// Path: src/main/java/octopus/OctopusEnvironment.java // public class OctopusEnvironment { // // private static final String OCTOPUS_HOME_STR; // private static final String DATA_STR = "data"; // private static final String PROJECTS_STR = "projects"; // private static final String PLUGINS_STR = "plugins"; // private static final String LANGUAGES_STR = "languages"; // // public static final Path PROJECTS_DIR; // public static final Path PLUGINS_DIR; // public static final Path LANGUAGES_DIR; // // static { // // OCTOPUS_HOME_STR = System.getProperty("OCTOPUS_HOME"); // // if (OCTOPUS_HOME_STR == null) // { // throw new RuntimeException("System property OCTOPUS_HOME not defined."); // } // // PROJECTS_DIR = Paths.get(OCTOPUS_HOME_STR, DATA_STR, PROJECTS_STR); // PLUGINS_DIR = Paths.get(OCTOPUS_HOME_STR, PLUGINS_STR); // LANGUAGES_DIR = Paths.get(OCTOPUS_HOME_STR, LANGUAGES_STR); // // } // // } // // Path: src/main/java/octopus/server/pluginInterface/PluginLoader.java // public class PluginLoader // { // public static Plugin load(Path pathToJar, String pluginClass) // { // ClassLoader parentClassLoader = PluginClassLoader.class // .getClassLoader(); // PluginClassLoader classLoader = new PluginClassLoader( // parentClassLoader); // classLoader.setJarFilename(pathToJar.toString()); // // return createPluginInstance(classLoader, pluginClass); // } // // public static Plugin load(String pluginClass) // { // ClassLoader parentClassLoader = PluginClassLoader.class // .getClassLoader(); // return createPluginInstance(parentClassLoader, pluginClass); // } // // private static Plugin createPluginInstance(ClassLoader classLoader, String pluginClass) // { // try // { // Class<?> myObjectClass = classLoader.loadClass(pluginClass); // return (Plugin) myObjectClass.newInstance(); // } catch (Exception e) // { // return null; // } // } // // }
import java.nio.file.Path; import java.nio.file.Paths; import org.json.JSONObject; import octopus.OctopusEnvironment; import octopus.server.pluginInterface.PluginLoader;
package octopus.api.plugin; public class PluginExecutor { public Object executePlugin(String pluginName, String pluginClass) { return executePlugin(pluginName, pluginClass, null); } public Object executePlugin(String pluginName, String pluginClass, JSONObject settings) { Plugin plugin; if(!pluginName.equals("")){
// Path: src/main/java/octopus/OctopusEnvironment.java // public class OctopusEnvironment { // // private static final String OCTOPUS_HOME_STR; // private static final String DATA_STR = "data"; // private static final String PROJECTS_STR = "projects"; // private static final String PLUGINS_STR = "plugins"; // private static final String LANGUAGES_STR = "languages"; // // public static final Path PROJECTS_DIR; // public static final Path PLUGINS_DIR; // public static final Path LANGUAGES_DIR; // // static { // // OCTOPUS_HOME_STR = System.getProperty("OCTOPUS_HOME"); // // if (OCTOPUS_HOME_STR == null) // { // throw new RuntimeException("System property OCTOPUS_HOME not defined."); // } // // PROJECTS_DIR = Paths.get(OCTOPUS_HOME_STR, DATA_STR, PROJECTS_STR); // PLUGINS_DIR = Paths.get(OCTOPUS_HOME_STR, PLUGINS_STR); // LANGUAGES_DIR = Paths.get(OCTOPUS_HOME_STR, LANGUAGES_STR); // // } // // } // // Path: src/main/java/octopus/server/pluginInterface/PluginLoader.java // public class PluginLoader // { // public static Plugin load(Path pathToJar, String pluginClass) // { // ClassLoader parentClassLoader = PluginClassLoader.class // .getClassLoader(); // PluginClassLoader classLoader = new PluginClassLoader( // parentClassLoader); // classLoader.setJarFilename(pathToJar.toString()); // // return createPluginInstance(classLoader, pluginClass); // } // // public static Plugin load(String pluginClass) // { // ClassLoader parentClassLoader = PluginClassLoader.class // .getClassLoader(); // return createPluginInstance(parentClassLoader, pluginClass); // } // // private static Plugin createPluginInstance(ClassLoader classLoader, String pluginClass) // { // try // { // Class<?> myObjectClass = classLoader.loadClass(pluginClass); // return (Plugin) myObjectClass.newInstance(); // } catch (Exception e) // { // return null; // } // } // // } // Path: src/main/java/octopus/api/plugin/PluginExecutor.java import java.nio.file.Path; import java.nio.file.Paths; import org.json.JSONObject; import octopus.OctopusEnvironment; import octopus.server.pluginInterface.PluginLoader; package octopus.api.plugin; public class PluginExecutor { public Object executePlugin(String pluginName, String pluginClass) { return executePlugin(pluginName, pluginClass, null); } public Object executePlugin(String pluginName, String pluginClass, JSONObject settings) { Plugin plugin; if(!pluginName.equals("")){
String pluginDir = OctopusEnvironment.PLUGINS_DIR.toString();
octopus-platform/octopus
src/main/java/octopus/api/plugin/PluginExecutor.java
// Path: src/main/java/octopus/OctopusEnvironment.java // public class OctopusEnvironment { // // private static final String OCTOPUS_HOME_STR; // private static final String DATA_STR = "data"; // private static final String PROJECTS_STR = "projects"; // private static final String PLUGINS_STR = "plugins"; // private static final String LANGUAGES_STR = "languages"; // // public static final Path PROJECTS_DIR; // public static final Path PLUGINS_DIR; // public static final Path LANGUAGES_DIR; // // static { // // OCTOPUS_HOME_STR = System.getProperty("OCTOPUS_HOME"); // // if (OCTOPUS_HOME_STR == null) // { // throw new RuntimeException("System property OCTOPUS_HOME not defined."); // } // // PROJECTS_DIR = Paths.get(OCTOPUS_HOME_STR, DATA_STR, PROJECTS_STR); // PLUGINS_DIR = Paths.get(OCTOPUS_HOME_STR, PLUGINS_STR); // LANGUAGES_DIR = Paths.get(OCTOPUS_HOME_STR, LANGUAGES_STR); // // } // // } // // Path: src/main/java/octopus/server/pluginInterface/PluginLoader.java // public class PluginLoader // { // public static Plugin load(Path pathToJar, String pluginClass) // { // ClassLoader parentClassLoader = PluginClassLoader.class // .getClassLoader(); // PluginClassLoader classLoader = new PluginClassLoader( // parentClassLoader); // classLoader.setJarFilename(pathToJar.toString()); // // return createPluginInstance(classLoader, pluginClass); // } // // public static Plugin load(String pluginClass) // { // ClassLoader parentClassLoader = PluginClassLoader.class // .getClassLoader(); // return createPluginInstance(parentClassLoader, pluginClass); // } // // private static Plugin createPluginInstance(ClassLoader classLoader, String pluginClass) // { // try // { // Class<?> myObjectClass = classLoader.loadClass(pluginClass); // return (Plugin) myObjectClass.newInstance(); // } catch (Exception e) // { // return null; // } // } // // }
import java.nio.file.Path; import java.nio.file.Paths; import org.json.JSONObject; import octopus.OctopusEnvironment; import octopus.server.pluginInterface.PluginLoader;
package octopus.api.plugin; public class PluginExecutor { public Object executePlugin(String pluginName, String pluginClass) { return executePlugin(pluginName, pluginClass, null); } public Object executePlugin(String pluginName, String pluginClass, JSONObject settings) { Plugin plugin; if(!pluginName.equals("")){ String pluginDir = OctopusEnvironment.PLUGINS_DIR.toString(); Path pathToJar = Paths.get(pluginDir, pluginName).toAbsolutePath();
// Path: src/main/java/octopus/OctopusEnvironment.java // public class OctopusEnvironment { // // private static final String OCTOPUS_HOME_STR; // private static final String DATA_STR = "data"; // private static final String PROJECTS_STR = "projects"; // private static final String PLUGINS_STR = "plugins"; // private static final String LANGUAGES_STR = "languages"; // // public static final Path PROJECTS_DIR; // public static final Path PLUGINS_DIR; // public static final Path LANGUAGES_DIR; // // static { // // OCTOPUS_HOME_STR = System.getProperty("OCTOPUS_HOME"); // // if (OCTOPUS_HOME_STR == null) // { // throw new RuntimeException("System property OCTOPUS_HOME not defined."); // } // // PROJECTS_DIR = Paths.get(OCTOPUS_HOME_STR, DATA_STR, PROJECTS_STR); // PLUGINS_DIR = Paths.get(OCTOPUS_HOME_STR, PLUGINS_STR); // LANGUAGES_DIR = Paths.get(OCTOPUS_HOME_STR, LANGUAGES_STR); // // } // // } // // Path: src/main/java/octopus/server/pluginInterface/PluginLoader.java // public class PluginLoader // { // public static Plugin load(Path pathToJar, String pluginClass) // { // ClassLoader parentClassLoader = PluginClassLoader.class // .getClassLoader(); // PluginClassLoader classLoader = new PluginClassLoader( // parentClassLoader); // classLoader.setJarFilename(pathToJar.toString()); // // return createPluginInstance(classLoader, pluginClass); // } // // public static Plugin load(String pluginClass) // { // ClassLoader parentClassLoader = PluginClassLoader.class // .getClassLoader(); // return createPluginInstance(parentClassLoader, pluginClass); // } // // private static Plugin createPluginInstance(ClassLoader classLoader, String pluginClass) // { // try // { // Class<?> myObjectClass = classLoader.loadClass(pluginClass); // return (Plugin) myObjectClass.newInstance(); // } catch (Exception e) // { // return null; // } // } // // } // Path: src/main/java/octopus/api/plugin/PluginExecutor.java import java.nio.file.Path; import java.nio.file.Paths; import org.json.JSONObject; import octopus.OctopusEnvironment; import octopus.server.pluginInterface.PluginLoader; package octopus.api.plugin; public class PluginExecutor { public Object executePlugin(String pluginName, String pluginClass) { return executePlugin(pluginName, pluginClass, null); } public Object executePlugin(String pluginName, String pluginClass, JSONObject settings) { Plugin plugin; if(!pluginName.equals("")){ String pluginDir = OctopusEnvironment.PLUGINS_DIR.toString(); Path pathToJar = Paths.get(pluginDir, pluginName).toAbsolutePath();
plugin = PluginLoader.load(pathToJar, pluginClass);
octopus-platform/octopus
src/main/java/octopus/server/restServer/handlers/ListShellsHandler.java
// Path: src/main/java/octopus/api/shell/ShellManager.java // public class ShellManager { // // public List<OctopusGremlinShell> getActiveShells() // { // return OctopusShellManager.getActiveShells(); // } // // public int createNewShellThread(String projectName, String shellName) throws IOException // { // int port = OctopusShellManager.createNewShell(projectName, shellName); // OctopusGremlinShell shell = OctopusShellManager.getShellForPort(port); // startShellThread(shell); // return port; // } // // private void startShellThread(OctopusGremlinShell shell) throws IOException // { // ShellRunnable runnable = new ShellRunnable(shell); // Thread thread = new Thread(runnable); // thread.start(); // } // // } // // Path: src/main/java/octopus/server/gremlinShell/OctopusGremlinShell.java // public class OctopusGremlinShell // { // // private GroovyShell shell; // private int port; // Database database; // private String name; // private boolean occupied = false; // private Graph graph; // private String projectName; // private GraphTraversalSource g; // // static // { // // } // // public OctopusGremlinShell(String projectName) // { // this.projectName = projectName; // } // // private void octopusSugarLoad() // { // String cmd = "GremlinLoader.load();"; // execute(cmd); // // // This is the code responsible for the execution of session steps // cmd = "DefaultGraphTraversal.metaClass.methodMissing = { final String name, final def args -> def closure = getStep(name); if (closure != null) { closure.delegate = delegate; return closure(args); } else { throw new MissingMethodException(name, this.class, args) } }"; // execute(cmd); // } // // public void initShell() // { // this.shell = new GroovyShell(new OctopusCompilerConfiguration()); // openDatabaseConnection(projectName); // octopusSugarLoad(); // loadStandardQueryLibrary(); // } // // private void openDatabaseConnection(String projectName) // { // OctopusProject project = new ProjectManager().getProjectByName(projectName); // database = project.getNewDatabaseInstance(); // this.projectName = projectName; // // graph = database.getGraph(); // g = graph.traversal(); // this.shell.setVariable("graph", graph); // this.shell.setVariable("g", g); // this.shell.setVariable("sessionSteps", new HashMap<String, Closure>()); // } // // private void loadStandardQueryLibrary() // { // try // { // Path languagesDir = OctopusEnvironment.LANGUAGES_DIR; // loadRecursively(languagesDir.toString()); // } catch (IOException e) // { // e.printStackTrace(); // } // } // // private void loadRecursively(String languagesDir) throws IOException // { // SourceFileWalker walker = new OrderedWalker(); // GroovyFileLoader listener = new GroovyFileLoader(); // listener.setGroovyShell(this.getShell()); // // walker.setFilenameFilter("*.groovy"); // walker.addListener(listener); // walker.walk(new String[]{languagesDir}); // } // // public Object execute(String code) // { // // try // { // return shell.evaluate(code); // } catch (Exception ex) // { // return String.format("[%s] %s\n", ex.getClass().getSimpleName(), ex.getMessage()); // } // } // // public int getPort() // { // return port; // } // // public void setPort(int port) // { // this.port = port; // } // // public GroovyShell getShell() // { // return shell; // } // // public void setName(String name) // { // this.name = name; // } // // public String getName() // { // return this.name; // } // // public void markAsOccupied() // { // occupied = true; // } // // public void markAsFree() // { // occupied = false; // } // // public boolean isOccupied() // { // return occupied; // } // // public void shutdownDBInstance() // { // database.closeInstance(); // } // // public String getProjectName() // { // return projectName; // } // // public Graph getGraph() // { // return graph; // } // // } // // Path: src/main/java/octopus/server/restServer/OctopusRestHandler.java // public interface OctopusRestHandler { // // public Object handle(Request req, Response resp); // // }
import octopus.api.shell.ShellManager; import octopus.server.gremlinShell.OctopusGremlinShell; import octopus.server.restServer.OctopusRestHandler; import spark.Request; import spark.Response;
package octopus.server.restServer.handlers; public class ListShellsHandler implements OctopusRestHandler { @Override public Object handle(Request req, Response resp) {
// Path: src/main/java/octopus/api/shell/ShellManager.java // public class ShellManager { // // public List<OctopusGremlinShell> getActiveShells() // { // return OctopusShellManager.getActiveShells(); // } // // public int createNewShellThread(String projectName, String shellName) throws IOException // { // int port = OctopusShellManager.createNewShell(projectName, shellName); // OctopusGremlinShell shell = OctopusShellManager.getShellForPort(port); // startShellThread(shell); // return port; // } // // private void startShellThread(OctopusGremlinShell shell) throws IOException // { // ShellRunnable runnable = new ShellRunnable(shell); // Thread thread = new Thread(runnable); // thread.start(); // } // // } // // Path: src/main/java/octopus/server/gremlinShell/OctopusGremlinShell.java // public class OctopusGremlinShell // { // // private GroovyShell shell; // private int port; // Database database; // private String name; // private boolean occupied = false; // private Graph graph; // private String projectName; // private GraphTraversalSource g; // // static // { // // } // // public OctopusGremlinShell(String projectName) // { // this.projectName = projectName; // } // // private void octopusSugarLoad() // { // String cmd = "GremlinLoader.load();"; // execute(cmd); // // // This is the code responsible for the execution of session steps // cmd = "DefaultGraphTraversal.metaClass.methodMissing = { final String name, final def args -> def closure = getStep(name); if (closure != null) { closure.delegate = delegate; return closure(args); } else { throw new MissingMethodException(name, this.class, args) } }"; // execute(cmd); // } // // public void initShell() // { // this.shell = new GroovyShell(new OctopusCompilerConfiguration()); // openDatabaseConnection(projectName); // octopusSugarLoad(); // loadStandardQueryLibrary(); // } // // private void openDatabaseConnection(String projectName) // { // OctopusProject project = new ProjectManager().getProjectByName(projectName); // database = project.getNewDatabaseInstance(); // this.projectName = projectName; // // graph = database.getGraph(); // g = graph.traversal(); // this.shell.setVariable("graph", graph); // this.shell.setVariable("g", g); // this.shell.setVariable("sessionSteps", new HashMap<String, Closure>()); // } // // private void loadStandardQueryLibrary() // { // try // { // Path languagesDir = OctopusEnvironment.LANGUAGES_DIR; // loadRecursively(languagesDir.toString()); // } catch (IOException e) // { // e.printStackTrace(); // } // } // // private void loadRecursively(String languagesDir) throws IOException // { // SourceFileWalker walker = new OrderedWalker(); // GroovyFileLoader listener = new GroovyFileLoader(); // listener.setGroovyShell(this.getShell()); // // walker.setFilenameFilter("*.groovy"); // walker.addListener(listener); // walker.walk(new String[]{languagesDir}); // } // // public Object execute(String code) // { // // try // { // return shell.evaluate(code); // } catch (Exception ex) // { // return String.format("[%s] %s\n", ex.getClass().getSimpleName(), ex.getMessage()); // } // } // // public int getPort() // { // return port; // } // // public void setPort(int port) // { // this.port = port; // } // // public GroovyShell getShell() // { // return shell; // } // // public void setName(String name) // { // this.name = name; // } // // public String getName() // { // return this.name; // } // // public void markAsOccupied() // { // occupied = true; // } // // public void markAsFree() // { // occupied = false; // } // // public boolean isOccupied() // { // return occupied; // } // // public void shutdownDBInstance() // { // database.closeInstance(); // } // // public String getProjectName() // { // return projectName; // } // // public Graph getGraph() // { // return graph; // } // // } // // Path: src/main/java/octopus/server/restServer/OctopusRestHandler.java // public interface OctopusRestHandler { // // public Object handle(Request req, Response resp); // // } // Path: src/main/java/octopus/server/restServer/handlers/ListShellsHandler.java import octopus.api.shell.ShellManager; import octopus.server.gremlinShell.OctopusGremlinShell; import octopus.server.restServer.OctopusRestHandler; import spark.Request; import spark.Response; package octopus.server.restServer.handlers; public class ListShellsHandler implements OctopusRestHandler { @Override public Object handle(Request req, Response resp) {
ShellManager shellManager = new ShellManager();
octopus-platform/octopus
src/main/java/octopus/server/restServer/handlers/ListShellsHandler.java
// Path: src/main/java/octopus/api/shell/ShellManager.java // public class ShellManager { // // public List<OctopusGremlinShell> getActiveShells() // { // return OctopusShellManager.getActiveShells(); // } // // public int createNewShellThread(String projectName, String shellName) throws IOException // { // int port = OctopusShellManager.createNewShell(projectName, shellName); // OctopusGremlinShell shell = OctopusShellManager.getShellForPort(port); // startShellThread(shell); // return port; // } // // private void startShellThread(OctopusGremlinShell shell) throws IOException // { // ShellRunnable runnable = new ShellRunnable(shell); // Thread thread = new Thread(runnable); // thread.start(); // } // // } // // Path: src/main/java/octopus/server/gremlinShell/OctopusGremlinShell.java // public class OctopusGremlinShell // { // // private GroovyShell shell; // private int port; // Database database; // private String name; // private boolean occupied = false; // private Graph graph; // private String projectName; // private GraphTraversalSource g; // // static // { // // } // // public OctopusGremlinShell(String projectName) // { // this.projectName = projectName; // } // // private void octopusSugarLoad() // { // String cmd = "GremlinLoader.load();"; // execute(cmd); // // // This is the code responsible for the execution of session steps // cmd = "DefaultGraphTraversal.metaClass.methodMissing = { final String name, final def args -> def closure = getStep(name); if (closure != null) { closure.delegate = delegate; return closure(args); } else { throw new MissingMethodException(name, this.class, args) } }"; // execute(cmd); // } // // public void initShell() // { // this.shell = new GroovyShell(new OctopusCompilerConfiguration()); // openDatabaseConnection(projectName); // octopusSugarLoad(); // loadStandardQueryLibrary(); // } // // private void openDatabaseConnection(String projectName) // { // OctopusProject project = new ProjectManager().getProjectByName(projectName); // database = project.getNewDatabaseInstance(); // this.projectName = projectName; // // graph = database.getGraph(); // g = graph.traversal(); // this.shell.setVariable("graph", graph); // this.shell.setVariable("g", g); // this.shell.setVariable("sessionSteps", new HashMap<String, Closure>()); // } // // private void loadStandardQueryLibrary() // { // try // { // Path languagesDir = OctopusEnvironment.LANGUAGES_DIR; // loadRecursively(languagesDir.toString()); // } catch (IOException e) // { // e.printStackTrace(); // } // } // // private void loadRecursively(String languagesDir) throws IOException // { // SourceFileWalker walker = new OrderedWalker(); // GroovyFileLoader listener = new GroovyFileLoader(); // listener.setGroovyShell(this.getShell()); // // walker.setFilenameFilter("*.groovy"); // walker.addListener(listener); // walker.walk(new String[]{languagesDir}); // } // // public Object execute(String code) // { // // try // { // return shell.evaluate(code); // } catch (Exception ex) // { // return String.format("[%s] %s\n", ex.getClass().getSimpleName(), ex.getMessage()); // } // } // // public int getPort() // { // return port; // } // // public void setPort(int port) // { // this.port = port; // } // // public GroovyShell getShell() // { // return shell; // } // // public void setName(String name) // { // this.name = name; // } // // public String getName() // { // return this.name; // } // // public void markAsOccupied() // { // occupied = true; // } // // public void markAsFree() // { // occupied = false; // } // // public boolean isOccupied() // { // return occupied; // } // // public void shutdownDBInstance() // { // database.closeInstance(); // } // // public String getProjectName() // { // return projectName; // } // // public Graph getGraph() // { // return graph; // } // // } // // Path: src/main/java/octopus/server/restServer/OctopusRestHandler.java // public interface OctopusRestHandler { // // public Object handle(Request req, Response resp); // // }
import octopus.api.shell.ShellManager; import octopus.server.gremlinShell.OctopusGremlinShell; import octopus.server.restServer.OctopusRestHandler; import spark.Request; import spark.Response;
package octopus.server.restServer.handlers; public class ListShellsHandler implements OctopusRestHandler { @Override public Object handle(Request req, Response resp) { ShellManager shellManager = new ShellManager(); StringBuilder sb = new StringBuilder();
// Path: src/main/java/octopus/api/shell/ShellManager.java // public class ShellManager { // // public List<OctopusGremlinShell> getActiveShells() // { // return OctopusShellManager.getActiveShells(); // } // // public int createNewShellThread(String projectName, String shellName) throws IOException // { // int port = OctopusShellManager.createNewShell(projectName, shellName); // OctopusGremlinShell shell = OctopusShellManager.getShellForPort(port); // startShellThread(shell); // return port; // } // // private void startShellThread(OctopusGremlinShell shell) throws IOException // { // ShellRunnable runnable = new ShellRunnable(shell); // Thread thread = new Thread(runnable); // thread.start(); // } // // } // // Path: src/main/java/octopus/server/gremlinShell/OctopusGremlinShell.java // public class OctopusGremlinShell // { // // private GroovyShell shell; // private int port; // Database database; // private String name; // private boolean occupied = false; // private Graph graph; // private String projectName; // private GraphTraversalSource g; // // static // { // // } // // public OctopusGremlinShell(String projectName) // { // this.projectName = projectName; // } // // private void octopusSugarLoad() // { // String cmd = "GremlinLoader.load();"; // execute(cmd); // // // This is the code responsible for the execution of session steps // cmd = "DefaultGraphTraversal.metaClass.methodMissing = { final String name, final def args -> def closure = getStep(name); if (closure != null) { closure.delegate = delegate; return closure(args); } else { throw new MissingMethodException(name, this.class, args) } }"; // execute(cmd); // } // // public void initShell() // { // this.shell = new GroovyShell(new OctopusCompilerConfiguration()); // openDatabaseConnection(projectName); // octopusSugarLoad(); // loadStandardQueryLibrary(); // } // // private void openDatabaseConnection(String projectName) // { // OctopusProject project = new ProjectManager().getProjectByName(projectName); // database = project.getNewDatabaseInstance(); // this.projectName = projectName; // // graph = database.getGraph(); // g = graph.traversal(); // this.shell.setVariable("graph", graph); // this.shell.setVariable("g", g); // this.shell.setVariable("sessionSteps", new HashMap<String, Closure>()); // } // // private void loadStandardQueryLibrary() // { // try // { // Path languagesDir = OctopusEnvironment.LANGUAGES_DIR; // loadRecursively(languagesDir.toString()); // } catch (IOException e) // { // e.printStackTrace(); // } // } // // private void loadRecursively(String languagesDir) throws IOException // { // SourceFileWalker walker = new OrderedWalker(); // GroovyFileLoader listener = new GroovyFileLoader(); // listener.setGroovyShell(this.getShell()); // // walker.setFilenameFilter("*.groovy"); // walker.addListener(listener); // walker.walk(new String[]{languagesDir}); // } // // public Object execute(String code) // { // // try // { // return shell.evaluate(code); // } catch (Exception ex) // { // return String.format("[%s] %s\n", ex.getClass().getSimpleName(), ex.getMessage()); // } // } // // public int getPort() // { // return port; // } // // public void setPort(int port) // { // this.port = port; // } // // public GroovyShell getShell() // { // return shell; // } // // public void setName(String name) // { // this.name = name; // } // // public String getName() // { // return this.name; // } // // public void markAsOccupied() // { // occupied = true; // } // // public void markAsFree() // { // occupied = false; // } // // public boolean isOccupied() // { // return occupied; // } // // public void shutdownDBInstance() // { // database.closeInstance(); // } // // public String getProjectName() // { // return projectName; // } // // public Graph getGraph() // { // return graph; // } // // } // // Path: src/main/java/octopus/server/restServer/OctopusRestHandler.java // public interface OctopusRestHandler { // // public Object handle(Request req, Response resp); // // } // Path: src/main/java/octopus/server/restServer/handlers/ListShellsHandler.java import octopus.api.shell.ShellManager; import octopus.server.gremlinShell.OctopusGremlinShell; import octopus.server.restServer.OctopusRestHandler; import spark.Request; import spark.Response; package octopus.server.restServer.handlers; public class ListShellsHandler implements OctopusRestHandler { @Override public Object handle(Request req, Response resp) { ShellManager shellManager = new ShellManager(); StringBuilder sb = new StringBuilder();
for (OctopusGremlinShell shell : shellManager.getActiveShells())
octopus-platform/octopus
src/main/java/octopus/api/plugin/types/OctopusProjectPlugin.java
// Path: src/main/java/octopus/api/plugin/Plugin.java // public interface Plugin // { // void configure(JSONObject settings); // // void execute() throws Exception; // // default void beforeExecution() throws Exception {} // // default void afterExecution() throws Exception {} // // default Object result() // { // return null; // } // } // // Path: src/main/java/octopus/api/plugin/connectors/OctopusProjectConnector.java // public class OctopusProjectConnector { // // OctopusProjectWrapper wrapper; // // public void connect(String projectName) // { // wrapper = openProject(projectName); // } // // protected OctopusProjectWrapper openProject(String projectName) // { // OctopusProject oProject = OctopusProjectManager.getProjectByName(projectName); // if(oProject == null) // throw new RuntimeException("Error: project does not exist"); // // return wrapNewProject(oProject); // } // // protected OctopusProjectWrapper wrapNewProject(OctopusProject oProject) // { // OctopusPlainProject project = new OctopusPlainProject(); // project.setWrappedProject(oProject); // return project; // // } // // public void disconnect() // { // // TODO Auto-generated method stub // } // // public OctopusProjectWrapper getWrapper() // { // return wrapper; // } // // // }
import org.json.JSONObject; import octopus.api.plugin.Plugin; import octopus.api.plugin.connectors.OctopusProjectConnector;
package octopus.api.plugin.types; /** * A plugin that is associated with an Octopus Project. * **/ public abstract class OctopusProjectPlugin implements Plugin {
// Path: src/main/java/octopus/api/plugin/Plugin.java // public interface Plugin // { // void configure(JSONObject settings); // // void execute() throws Exception; // // default void beforeExecution() throws Exception {} // // default void afterExecution() throws Exception {} // // default Object result() // { // return null; // } // } // // Path: src/main/java/octopus/api/plugin/connectors/OctopusProjectConnector.java // public class OctopusProjectConnector { // // OctopusProjectWrapper wrapper; // // public void connect(String projectName) // { // wrapper = openProject(projectName); // } // // protected OctopusProjectWrapper openProject(String projectName) // { // OctopusProject oProject = OctopusProjectManager.getProjectByName(projectName); // if(oProject == null) // throw new RuntimeException("Error: project does not exist"); // // return wrapNewProject(oProject); // } // // protected OctopusProjectWrapper wrapNewProject(OctopusProject oProject) // { // OctopusPlainProject project = new OctopusPlainProject(); // project.setWrappedProject(oProject); // return project; // // } // // public void disconnect() // { // // TODO Auto-generated method stub // } // // public OctopusProjectWrapper getWrapper() // { // return wrapper; // } // // // } // Path: src/main/java/octopus/api/plugin/types/OctopusProjectPlugin.java import org.json.JSONObject; import octopus.api.plugin.Plugin; import octopus.api.plugin.connectors.OctopusProjectConnector; package octopus.api.plugin.types; /** * A plugin that is associated with an Octopus Project. * **/ public abstract class OctopusProjectPlugin implements Plugin {
private OctopusProjectConnector projectConnector;
octopus-platform/octopus
src/main/java/octopus/api/projects/OctopusProject.java
// Path: src/main/java/octopus/api/database/Database.java // public interface Database { // // // /** // * Return a tinkerpop3 graph instance // * */ // // public Graph getGraph(); // // public void closeInstance(); // // } // // Path: src/main/java/octopus/server/database/titan/TitanLocalDatabaseManager.java // public class TitanLocalDatabaseManager implements DatabaseManager { // // @Override // public void initializeDatabaseForProject(OctopusProject project) throws IOException // { // String pathToProject = project.getPathToProjectDir(); // String configFilename = createConfigurationFile(pathToProject); // initializeDatabaseSchema(configFilename); // } // // private String createConfigurationFile(String pathToProject) throws IOException // { // String dbPath = Paths.get(pathToProject, "database").toAbsolutePath().toString(); // String indexPath = Paths.get(pathToProject, "index").toAbsolutePath().toString(); // String dbConfigFile = Paths.get(pathToProject, "db").toAbsolutePath().toString(); // // PrintWriter writer; // writer = new PrintWriter(dbConfigFile, "UTF-8"); // writer.println("storage.backend=berkeleyje"); // writer.println("index.search.backend=lucene"); // writer.println(String.format("storage.directory=%s", dbPath)); // writer.println(String.format("index.search.directory=%s", indexPath)); // writer.close(); // return dbConfigFile; // } // // private void initializeDatabaseSchema(String configFilename) // { // TitanGraph graph = TitanFactory.open(configFilename); // TitanManagement schema = graph.openManagement(); // // PropertyKey extIdKey = schema.makePropertyKey("_key").dataType(String.class).make(); // PropertyKey typeKey = schema.makePropertyKey("type").dataType(String.class).make(); // // // At import, we only create separate composite indices for key and type. // // Additional indices should be built by plugins. // // schema.buildIndex("byKey", Vertex.class).addKey(extIdKey).unique().buildCompositeIndex(); // schema.buildIndex("byType", Vertex.class).addKey(typeKey).buildCompositeIndex(); // // // Lucene indices can be built as follows: // // This would be how to build a STRING index // PropertyKey codeKey = schema.makePropertyKey("code").dataType(String.class).make(); // schema.buildIndex("byValue", Vertex.class) // .addKey(codeKey, Mapping.STRING.asParameter()).buildMixedIndex("search"); // // // And this is how to build a TEXT index // // schema.buildIndex("byTypeAndValue", Vertex.class).addKey(typeKey). // // addKey(valueKey).buildMixedIndex("search"); // // schema.commit(); // graph.close(); // } // // @Override // public Database getDatabaseInstanceForProject(OctopusProject project) // { // TitanLocalDatabase database = new TitanLocalDatabase(); // String dbConfigFile = project.getDBConfigFile(); // TitanGraph graph = TitanFactory.open(dbConfigFile); // database.setGraph(graph); // return database; // } // // @Override // public void deleteDatabaseForProject(OctopusProject project) // { // Database database = getDatabaseInstanceForProject(project); // TitanLocalDatabase titanDatabase = (TitanLocalDatabase) database; // String dbPathName = titanDatabase.getPathToDatabase(); // String indexPathName = titanDatabase.getPathToIndex(); // // try { // FileUtils.deleteDirectory(new File(dbPathName)); // FileUtils.deleteDirectory(new File(indexPathName)); // } catch (IOException e) { // e.printStackTrace(); // }finally{ // database.closeInstance(); // } // // } // // @Override // public void resetDatabase(OctopusProject project) // { // Database database = getDatabaseInstanceForProject(project); // Graph graph = database.getGraph(); // try { // graph.close(); // TitanCleanup.clear((TitanGraph) graph); // initializeDatabaseForProject(project); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } // // }
import java.io.IOException; import java.nio.file.Paths; import octopus.api.database.Database; import octopus.server.database.titan.TitanLocalDatabaseManager;
package octopus.api.projects; public class OctopusProject { private final String pathToProjectDir; private String name; public OctopusProject(String name, String pathToProjectDir) throws IOException { this.pathToProjectDir = pathToProjectDir; this.name = name; } public String getPathToProjectDir() { return pathToProjectDir; } public String getName() { return name; } public String getDBConfigFile() { return Paths.get(pathToProjectDir, "db").toAbsolutePath().toString(); }
// Path: src/main/java/octopus/api/database/Database.java // public interface Database { // // // /** // * Return a tinkerpop3 graph instance // * */ // // public Graph getGraph(); // // public void closeInstance(); // // } // // Path: src/main/java/octopus/server/database/titan/TitanLocalDatabaseManager.java // public class TitanLocalDatabaseManager implements DatabaseManager { // // @Override // public void initializeDatabaseForProject(OctopusProject project) throws IOException // { // String pathToProject = project.getPathToProjectDir(); // String configFilename = createConfigurationFile(pathToProject); // initializeDatabaseSchema(configFilename); // } // // private String createConfigurationFile(String pathToProject) throws IOException // { // String dbPath = Paths.get(pathToProject, "database").toAbsolutePath().toString(); // String indexPath = Paths.get(pathToProject, "index").toAbsolutePath().toString(); // String dbConfigFile = Paths.get(pathToProject, "db").toAbsolutePath().toString(); // // PrintWriter writer; // writer = new PrintWriter(dbConfigFile, "UTF-8"); // writer.println("storage.backend=berkeleyje"); // writer.println("index.search.backend=lucene"); // writer.println(String.format("storage.directory=%s", dbPath)); // writer.println(String.format("index.search.directory=%s", indexPath)); // writer.close(); // return dbConfigFile; // } // // private void initializeDatabaseSchema(String configFilename) // { // TitanGraph graph = TitanFactory.open(configFilename); // TitanManagement schema = graph.openManagement(); // // PropertyKey extIdKey = schema.makePropertyKey("_key").dataType(String.class).make(); // PropertyKey typeKey = schema.makePropertyKey("type").dataType(String.class).make(); // // // At import, we only create separate composite indices for key and type. // // Additional indices should be built by plugins. // // schema.buildIndex("byKey", Vertex.class).addKey(extIdKey).unique().buildCompositeIndex(); // schema.buildIndex("byType", Vertex.class).addKey(typeKey).buildCompositeIndex(); // // // Lucene indices can be built as follows: // // This would be how to build a STRING index // PropertyKey codeKey = schema.makePropertyKey("code").dataType(String.class).make(); // schema.buildIndex("byValue", Vertex.class) // .addKey(codeKey, Mapping.STRING.asParameter()).buildMixedIndex("search"); // // // And this is how to build a TEXT index // // schema.buildIndex("byTypeAndValue", Vertex.class).addKey(typeKey). // // addKey(valueKey).buildMixedIndex("search"); // // schema.commit(); // graph.close(); // } // // @Override // public Database getDatabaseInstanceForProject(OctopusProject project) // { // TitanLocalDatabase database = new TitanLocalDatabase(); // String dbConfigFile = project.getDBConfigFile(); // TitanGraph graph = TitanFactory.open(dbConfigFile); // database.setGraph(graph); // return database; // } // // @Override // public void deleteDatabaseForProject(OctopusProject project) // { // Database database = getDatabaseInstanceForProject(project); // TitanLocalDatabase titanDatabase = (TitanLocalDatabase) database; // String dbPathName = titanDatabase.getPathToDatabase(); // String indexPathName = titanDatabase.getPathToIndex(); // // try { // FileUtils.deleteDirectory(new File(dbPathName)); // FileUtils.deleteDirectory(new File(indexPathName)); // } catch (IOException e) { // e.printStackTrace(); // }finally{ // database.closeInstance(); // } // // } // // @Override // public void resetDatabase(OctopusProject project) // { // Database database = getDatabaseInstanceForProject(project); // Graph graph = database.getGraph(); // try { // graph.close(); // TitanCleanup.clear((TitanGraph) graph); // initializeDatabaseForProject(project); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } // // } // Path: src/main/java/octopus/api/projects/OctopusProject.java import java.io.IOException; import java.nio.file.Paths; import octopus.api.database.Database; import octopus.server.database.titan.TitanLocalDatabaseManager; package octopus.api.projects; public class OctopusProject { private final String pathToProjectDir; private String name; public OctopusProject(String name, String pathToProjectDir) throws IOException { this.pathToProjectDir = pathToProjectDir; this.name = name; } public String getPathToProjectDir() { return pathToProjectDir; } public String getName() { return name; } public String getDBConfigFile() { return Paths.get(pathToProjectDir, "db").toAbsolutePath().toString(); }
public Database getNewDatabaseInstance()
octopus-platform/octopus
src/main/java/octopus/api/projects/OctopusProject.java
// Path: src/main/java/octopus/api/database/Database.java // public interface Database { // // // /** // * Return a tinkerpop3 graph instance // * */ // // public Graph getGraph(); // // public void closeInstance(); // // } // // Path: src/main/java/octopus/server/database/titan/TitanLocalDatabaseManager.java // public class TitanLocalDatabaseManager implements DatabaseManager { // // @Override // public void initializeDatabaseForProject(OctopusProject project) throws IOException // { // String pathToProject = project.getPathToProjectDir(); // String configFilename = createConfigurationFile(pathToProject); // initializeDatabaseSchema(configFilename); // } // // private String createConfigurationFile(String pathToProject) throws IOException // { // String dbPath = Paths.get(pathToProject, "database").toAbsolutePath().toString(); // String indexPath = Paths.get(pathToProject, "index").toAbsolutePath().toString(); // String dbConfigFile = Paths.get(pathToProject, "db").toAbsolutePath().toString(); // // PrintWriter writer; // writer = new PrintWriter(dbConfigFile, "UTF-8"); // writer.println("storage.backend=berkeleyje"); // writer.println("index.search.backend=lucene"); // writer.println(String.format("storage.directory=%s", dbPath)); // writer.println(String.format("index.search.directory=%s", indexPath)); // writer.close(); // return dbConfigFile; // } // // private void initializeDatabaseSchema(String configFilename) // { // TitanGraph graph = TitanFactory.open(configFilename); // TitanManagement schema = graph.openManagement(); // // PropertyKey extIdKey = schema.makePropertyKey("_key").dataType(String.class).make(); // PropertyKey typeKey = schema.makePropertyKey("type").dataType(String.class).make(); // // // At import, we only create separate composite indices for key and type. // // Additional indices should be built by plugins. // // schema.buildIndex("byKey", Vertex.class).addKey(extIdKey).unique().buildCompositeIndex(); // schema.buildIndex("byType", Vertex.class).addKey(typeKey).buildCompositeIndex(); // // // Lucene indices can be built as follows: // // This would be how to build a STRING index // PropertyKey codeKey = schema.makePropertyKey("code").dataType(String.class).make(); // schema.buildIndex("byValue", Vertex.class) // .addKey(codeKey, Mapping.STRING.asParameter()).buildMixedIndex("search"); // // // And this is how to build a TEXT index // // schema.buildIndex("byTypeAndValue", Vertex.class).addKey(typeKey). // // addKey(valueKey).buildMixedIndex("search"); // // schema.commit(); // graph.close(); // } // // @Override // public Database getDatabaseInstanceForProject(OctopusProject project) // { // TitanLocalDatabase database = new TitanLocalDatabase(); // String dbConfigFile = project.getDBConfigFile(); // TitanGraph graph = TitanFactory.open(dbConfigFile); // database.setGraph(graph); // return database; // } // // @Override // public void deleteDatabaseForProject(OctopusProject project) // { // Database database = getDatabaseInstanceForProject(project); // TitanLocalDatabase titanDatabase = (TitanLocalDatabase) database; // String dbPathName = titanDatabase.getPathToDatabase(); // String indexPathName = titanDatabase.getPathToIndex(); // // try { // FileUtils.deleteDirectory(new File(dbPathName)); // FileUtils.deleteDirectory(new File(indexPathName)); // } catch (IOException e) { // e.printStackTrace(); // }finally{ // database.closeInstance(); // } // // } // // @Override // public void resetDatabase(OctopusProject project) // { // Database database = getDatabaseInstanceForProject(project); // Graph graph = database.getGraph(); // try { // graph.close(); // TitanCleanup.clear((TitanGraph) graph); // initializeDatabaseForProject(project); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } // // }
import java.io.IOException; import java.nio.file.Paths; import octopus.api.database.Database; import octopus.server.database.titan.TitanLocalDatabaseManager;
package octopus.api.projects; public class OctopusProject { private final String pathToProjectDir; private String name; public OctopusProject(String name, String pathToProjectDir) throws IOException { this.pathToProjectDir = pathToProjectDir; this.name = name; } public String getPathToProjectDir() { return pathToProjectDir; } public String getName() { return name; } public String getDBConfigFile() { return Paths.get(pathToProjectDir, "db").toAbsolutePath().toString(); } public Database getNewDatabaseInstance() {
// Path: src/main/java/octopus/api/database/Database.java // public interface Database { // // // /** // * Return a tinkerpop3 graph instance // * */ // // public Graph getGraph(); // // public void closeInstance(); // // } // // Path: src/main/java/octopus/server/database/titan/TitanLocalDatabaseManager.java // public class TitanLocalDatabaseManager implements DatabaseManager { // // @Override // public void initializeDatabaseForProject(OctopusProject project) throws IOException // { // String pathToProject = project.getPathToProjectDir(); // String configFilename = createConfigurationFile(pathToProject); // initializeDatabaseSchema(configFilename); // } // // private String createConfigurationFile(String pathToProject) throws IOException // { // String dbPath = Paths.get(pathToProject, "database").toAbsolutePath().toString(); // String indexPath = Paths.get(pathToProject, "index").toAbsolutePath().toString(); // String dbConfigFile = Paths.get(pathToProject, "db").toAbsolutePath().toString(); // // PrintWriter writer; // writer = new PrintWriter(dbConfigFile, "UTF-8"); // writer.println("storage.backend=berkeleyje"); // writer.println("index.search.backend=lucene"); // writer.println(String.format("storage.directory=%s", dbPath)); // writer.println(String.format("index.search.directory=%s", indexPath)); // writer.close(); // return dbConfigFile; // } // // private void initializeDatabaseSchema(String configFilename) // { // TitanGraph graph = TitanFactory.open(configFilename); // TitanManagement schema = graph.openManagement(); // // PropertyKey extIdKey = schema.makePropertyKey("_key").dataType(String.class).make(); // PropertyKey typeKey = schema.makePropertyKey("type").dataType(String.class).make(); // // // At import, we only create separate composite indices for key and type. // // Additional indices should be built by plugins. // // schema.buildIndex("byKey", Vertex.class).addKey(extIdKey).unique().buildCompositeIndex(); // schema.buildIndex("byType", Vertex.class).addKey(typeKey).buildCompositeIndex(); // // // Lucene indices can be built as follows: // // This would be how to build a STRING index // PropertyKey codeKey = schema.makePropertyKey("code").dataType(String.class).make(); // schema.buildIndex("byValue", Vertex.class) // .addKey(codeKey, Mapping.STRING.asParameter()).buildMixedIndex("search"); // // // And this is how to build a TEXT index // // schema.buildIndex("byTypeAndValue", Vertex.class).addKey(typeKey). // // addKey(valueKey).buildMixedIndex("search"); // // schema.commit(); // graph.close(); // } // // @Override // public Database getDatabaseInstanceForProject(OctopusProject project) // { // TitanLocalDatabase database = new TitanLocalDatabase(); // String dbConfigFile = project.getDBConfigFile(); // TitanGraph graph = TitanFactory.open(dbConfigFile); // database.setGraph(graph); // return database; // } // // @Override // public void deleteDatabaseForProject(OctopusProject project) // { // Database database = getDatabaseInstanceForProject(project); // TitanLocalDatabase titanDatabase = (TitanLocalDatabase) database; // String dbPathName = titanDatabase.getPathToDatabase(); // String indexPathName = titanDatabase.getPathToIndex(); // // try { // FileUtils.deleteDirectory(new File(dbPathName)); // FileUtils.deleteDirectory(new File(indexPathName)); // } catch (IOException e) { // e.printStackTrace(); // }finally{ // database.closeInstance(); // } // // } // // @Override // public void resetDatabase(OctopusProject project) // { // Database database = getDatabaseInstanceForProject(project); // Graph graph = database.getGraph(); // try { // graph.close(); // TitanCleanup.clear((TitanGraph) graph); // initializeDatabaseForProject(project); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } // // } // Path: src/main/java/octopus/api/projects/OctopusProject.java import java.io.IOException; import java.nio.file.Paths; import octopus.api.database.Database; import octopus.server.database.titan.TitanLocalDatabaseManager; package octopus.api.projects; public class OctopusProject { private final String pathToProjectDir; private String name; public OctopusProject(String name, String pathToProjectDir) throws IOException { this.pathToProjectDir = pathToProjectDir; this.name = name; } public String getPathToProjectDir() { return pathToProjectDir; } public String getName() { return name; } public String getDBConfigFile() { return Paths.get(pathToProjectDir, "db").toAbsolutePath().toString(); } public Database getNewDatabaseInstance() {
return new TitanLocalDatabaseManager().getDatabaseInstanceForProject(this);
octopus-platform/octopus
src/main/java/octopus/server/restServer/handlers/ExecutePluginHandler.java
// Path: src/main/java/octopus/api/plugin/PluginExecutor.java // public class PluginExecutor { // // public Object executePlugin(String pluginName, String pluginClass) // { // return executePlugin(pluginName, pluginClass, null); // } // // public Object executePlugin(String pluginName, String pluginClass, JSONObject settings) // { // Plugin plugin; // // if(!pluginName.equals("")){ // String pluginDir = OctopusEnvironment.PLUGINS_DIR.toString(); // Path pathToJar = Paths.get(pluginDir, pluginName).toAbsolutePath(); // plugin = PluginLoader.load(pathToJar, pluginClass); // }else{ // plugin = PluginLoader.load(pluginClass); // } // // if (plugin == null) // throw new RuntimeException( // "Error while loading plugin " + pluginName); // // try // { // if(settings != null) // plugin.configure(settings); // plugin.beforeExecution(); // plugin.execute(); // plugin.afterExecution(); // return plugin.result(); // } catch (Exception e) // { // System.out.println(e.getMessage()); // throw new RuntimeException(e.getMessage()); // } // } // // } // // Path: src/main/java/octopus/server/restServer/OctopusRestHandler.java // public interface OctopusRestHandler { // // public Object handle(Request req, Response resp); // // }
import org.json.JSONObject; import octopus.api.plugin.PluginExecutor; import octopus.server.restServer.OctopusRestHandler; import spark.Request; import spark.Response;
package octopus.server.restServer.handlers; public class ExecutePluginHandler implements OctopusRestHandler { private String pluginName; private String pluginClass; private JSONObject settings; @Override public Object handle(Request req, Response resp) { parseBody(req.body()); return executePluginAndRespond(); } private void parseBody(String content) { JSONObject data = new JSONObject(content); pluginName = data.getString("plugin"); pluginClass = data.getString("class"); settings = data.getJSONObject("settings"); if(pluginName == null || pluginClass == null) throw new RuntimeException("Invalid request: pluginName or pluginClass not given"); } private Object executePluginAndRespond() {
// Path: src/main/java/octopus/api/plugin/PluginExecutor.java // public class PluginExecutor { // // public Object executePlugin(String pluginName, String pluginClass) // { // return executePlugin(pluginName, pluginClass, null); // } // // public Object executePlugin(String pluginName, String pluginClass, JSONObject settings) // { // Plugin plugin; // // if(!pluginName.equals("")){ // String pluginDir = OctopusEnvironment.PLUGINS_DIR.toString(); // Path pathToJar = Paths.get(pluginDir, pluginName).toAbsolutePath(); // plugin = PluginLoader.load(pathToJar, pluginClass); // }else{ // plugin = PluginLoader.load(pluginClass); // } // // if (plugin == null) // throw new RuntimeException( // "Error while loading plugin " + pluginName); // // try // { // if(settings != null) // plugin.configure(settings); // plugin.beforeExecution(); // plugin.execute(); // plugin.afterExecution(); // return plugin.result(); // } catch (Exception e) // { // System.out.println(e.getMessage()); // throw new RuntimeException(e.getMessage()); // } // } // // } // // Path: src/main/java/octopus/server/restServer/OctopusRestHandler.java // public interface OctopusRestHandler { // // public Object handle(Request req, Response resp); // // } // Path: src/main/java/octopus/server/restServer/handlers/ExecutePluginHandler.java import org.json.JSONObject; import octopus.api.plugin.PluginExecutor; import octopus.server.restServer.OctopusRestHandler; import spark.Request; import spark.Response; package octopus.server.restServer.handlers; public class ExecutePluginHandler implements OctopusRestHandler { private String pluginName; private String pluginClass; private JSONObject settings; @Override public Object handle(Request req, Response resp) { parseBody(req.body()); return executePluginAndRespond(); } private void parseBody(String content) { JSONObject data = new JSONObject(content); pluginName = data.getString("plugin"); pluginClass = data.getString("class"); settings = data.getJSONObject("settings"); if(pluginName == null || pluginClass == null) throw new RuntimeException("Invalid request: pluginName or pluginClass not given"); } private Object executePluginAndRespond() {
Object result = new PluginExecutor().executePlugin(pluginName, pluginClass, settings);
octopus-platform/octopus
src/main/java/octopus/server/restServer/handlers/ImportCSVHandler.java
// Path: src/main/java/octopus/api/csvImporter/CSVImporter.java // public class CSVImporter { // // public void importCSV(ImportJob job) // { // (new ImportCSVRunnable(job)).run(); // } // // } // // Path: src/main/java/octopus/server/importer/csv/ImportJob.java // public class ImportJob // { // private final String nodeFilename; // private final String edgeFilename; // private final String projectName; // // public ImportJob(String nodeFilename, String edgeFilename, String projectName) // { // this.nodeFilename = nodeFilename; // this.edgeFilename = edgeFilename; // this.projectName = projectName; // } // // public String getNodeFilename() // { // return nodeFilename; // } // // public String getEdgeFilename() // { // return edgeFilename; // } // // public String getProjectName() // { // return projectName; // } // // } // // Path: src/main/java/octopus/server/restServer/OctopusRestHandler.java // public interface OctopusRestHandler { // // public Object handle(Request req, Response resp); // // }
import octopus.api.csvImporter.CSVImporter; import octopus.server.importer.csv.ImportJob; import octopus.server.restServer.OctopusRestHandler; import spark.Request; import spark.Response;
package octopus.server.restServer.handlers; public class ImportCSVHandler implements OctopusRestHandler { @Override public Object handle(Request req, Response resp) {
// Path: src/main/java/octopus/api/csvImporter/CSVImporter.java // public class CSVImporter { // // public void importCSV(ImportJob job) // { // (new ImportCSVRunnable(job)).run(); // } // // } // // Path: src/main/java/octopus/server/importer/csv/ImportJob.java // public class ImportJob // { // private final String nodeFilename; // private final String edgeFilename; // private final String projectName; // // public ImportJob(String nodeFilename, String edgeFilename, String projectName) // { // this.nodeFilename = nodeFilename; // this.edgeFilename = edgeFilename; // this.projectName = projectName; // } // // public String getNodeFilename() // { // return nodeFilename; // } // // public String getEdgeFilename() // { // return edgeFilename; // } // // public String getProjectName() // { // return projectName; // } // // } // // Path: src/main/java/octopus/server/restServer/OctopusRestHandler.java // public interface OctopusRestHandler { // // public Object handle(Request req, Response resp); // // } // Path: src/main/java/octopus/server/restServer/handlers/ImportCSVHandler.java import octopus.api.csvImporter.CSVImporter; import octopus.server.importer.csv.ImportJob; import octopus.server.restServer.OctopusRestHandler; import spark.Request; import spark.Response; package octopus.server.restServer.handlers; public class ImportCSVHandler implements OctopusRestHandler { @Override public Object handle(Request req, Response resp) {
ImportJob job = getImportJobFromRequest(req);
octopus-platform/octopus
src/main/java/octopus/server/restServer/handlers/ImportCSVHandler.java
// Path: src/main/java/octopus/api/csvImporter/CSVImporter.java // public class CSVImporter { // // public void importCSV(ImportJob job) // { // (new ImportCSVRunnable(job)).run(); // } // // } // // Path: src/main/java/octopus/server/importer/csv/ImportJob.java // public class ImportJob // { // private final String nodeFilename; // private final String edgeFilename; // private final String projectName; // // public ImportJob(String nodeFilename, String edgeFilename, String projectName) // { // this.nodeFilename = nodeFilename; // this.edgeFilename = edgeFilename; // this.projectName = projectName; // } // // public String getNodeFilename() // { // return nodeFilename; // } // // public String getEdgeFilename() // { // return edgeFilename; // } // // public String getProjectName() // { // return projectName; // } // // } // // Path: src/main/java/octopus/server/restServer/OctopusRestHandler.java // public interface OctopusRestHandler { // // public Object handle(Request req, Response resp); // // }
import octopus.api.csvImporter.CSVImporter; import octopus.server.importer.csv.ImportJob; import octopus.server.restServer.OctopusRestHandler; import spark.Request; import spark.Response;
package octopus.server.restServer.handlers; public class ImportCSVHandler implements OctopusRestHandler { @Override public Object handle(Request req, Response resp) { ImportJob job = getImportJobFromRequest(req);
// Path: src/main/java/octopus/api/csvImporter/CSVImporter.java // public class CSVImporter { // // public void importCSV(ImportJob job) // { // (new ImportCSVRunnable(job)).run(); // } // // } // // Path: src/main/java/octopus/server/importer/csv/ImportJob.java // public class ImportJob // { // private final String nodeFilename; // private final String edgeFilename; // private final String projectName; // // public ImportJob(String nodeFilename, String edgeFilename, String projectName) // { // this.nodeFilename = nodeFilename; // this.edgeFilename = edgeFilename; // this.projectName = projectName; // } // // public String getNodeFilename() // { // return nodeFilename; // } // // public String getEdgeFilename() // { // return edgeFilename; // } // // public String getProjectName() // { // return projectName; // } // // } // // Path: src/main/java/octopus/server/restServer/OctopusRestHandler.java // public interface OctopusRestHandler { // // public Object handle(Request req, Response resp); // // } // Path: src/main/java/octopus/server/restServer/handlers/ImportCSVHandler.java import octopus.api.csvImporter.CSVImporter; import octopus.server.importer.csv.ImportJob; import octopus.server.restServer.OctopusRestHandler; import spark.Request; import spark.Response; package octopus.server.restServer.handlers; public class ImportCSVHandler implements OctopusRestHandler { @Override public Object handle(Request req, Response resp) { ImportJob job = getImportJobFromRequest(req);
new CSVImporter().importCSV(job);
octopus-platform/octopus
src/main/java/octopus/server/database/titan/TitanLocalDatabaseManager.java
// Path: src/main/java/octopus/api/database/Database.java // public interface Database { // // // /** // * Return a tinkerpop3 graph instance // * */ // // public Graph getGraph(); // // public void closeInstance(); // // } // // Path: src/main/java/octopus/api/database/DatabaseManager.java // public interface DatabaseManager { // // public void initializeDatabaseForProject(OctopusProject project) throws IOException; // public Database getDatabaseInstanceForProject(OctopusProject project); // public void deleteDatabaseForProject(OctopusProject project); // public void resetDatabase(OctopusProject project); // // } // // Path: src/main/java/octopus/api/projects/OctopusProject.java // public class OctopusProject // { // // private final String pathToProjectDir; // private String name; // // public OctopusProject(String name, String pathToProjectDir) throws IOException // { // this.pathToProjectDir = pathToProjectDir; // this.name = name; // } // // public String getPathToProjectDir() // { // return pathToProjectDir; // } // // public String getName() // { // return name; // } // // public String getDBConfigFile() // { // return Paths.get(pathToProjectDir, "db").toAbsolutePath().toString(); // } // // public Database getNewDatabaseInstance() // { // return new TitanLocalDatabaseManager().getDatabaseInstanceForProject(this); // } // // }
import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.nio.file.Paths; import com.thinkaurelius.titan.core.schema.Mapping; import org.apache.commons.io.FileUtils; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; import com.thinkaurelius.titan.core.PropertyKey; import com.thinkaurelius.titan.core.TitanFactory; import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.schema.TitanManagement; import com.thinkaurelius.titan.core.util.TitanCleanup; import octopus.api.database.Database; import octopus.api.database.DatabaseManager; import octopus.api.projects.OctopusProject;
package octopus.server.database.titan; public class TitanLocalDatabaseManager implements DatabaseManager { @Override
// Path: src/main/java/octopus/api/database/Database.java // public interface Database { // // // /** // * Return a tinkerpop3 graph instance // * */ // // public Graph getGraph(); // // public void closeInstance(); // // } // // Path: src/main/java/octopus/api/database/DatabaseManager.java // public interface DatabaseManager { // // public void initializeDatabaseForProject(OctopusProject project) throws IOException; // public Database getDatabaseInstanceForProject(OctopusProject project); // public void deleteDatabaseForProject(OctopusProject project); // public void resetDatabase(OctopusProject project); // // } // // Path: src/main/java/octopus/api/projects/OctopusProject.java // public class OctopusProject // { // // private final String pathToProjectDir; // private String name; // // public OctopusProject(String name, String pathToProjectDir) throws IOException // { // this.pathToProjectDir = pathToProjectDir; // this.name = name; // } // // public String getPathToProjectDir() // { // return pathToProjectDir; // } // // public String getName() // { // return name; // } // // public String getDBConfigFile() // { // return Paths.get(pathToProjectDir, "db").toAbsolutePath().toString(); // } // // public Database getNewDatabaseInstance() // { // return new TitanLocalDatabaseManager().getDatabaseInstanceForProject(this); // } // // } // Path: src/main/java/octopus/server/database/titan/TitanLocalDatabaseManager.java import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.nio.file.Paths; import com.thinkaurelius.titan.core.schema.Mapping; import org.apache.commons.io.FileUtils; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; import com.thinkaurelius.titan.core.PropertyKey; import com.thinkaurelius.titan.core.TitanFactory; import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.schema.TitanManagement; import com.thinkaurelius.titan.core.util.TitanCleanup; import octopus.api.database.Database; import octopus.api.database.DatabaseManager; import octopus.api.projects.OctopusProject; package octopus.server.database.titan; public class TitanLocalDatabaseManager implements DatabaseManager { @Override
public void initializeDatabaseForProject(OctopusProject project) throws IOException
octopus-platform/octopus
src/main/java/octopus/server/database/titan/TitanLocalDatabaseManager.java
// Path: src/main/java/octopus/api/database/Database.java // public interface Database { // // // /** // * Return a tinkerpop3 graph instance // * */ // // public Graph getGraph(); // // public void closeInstance(); // // } // // Path: src/main/java/octopus/api/database/DatabaseManager.java // public interface DatabaseManager { // // public void initializeDatabaseForProject(OctopusProject project) throws IOException; // public Database getDatabaseInstanceForProject(OctopusProject project); // public void deleteDatabaseForProject(OctopusProject project); // public void resetDatabase(OctopusProject project); // // } // // Path: src/main/java/octopus/api/projects/OctopusProject.java // public class OctopusProject // { // // private final String pathToProjectDir; // private String name; // // public OctopusProject(String name, String pathToProjectDir) throws IOException // { // this.pathToProjectDir = pathToProjectDir; // this.name = name; // } // // public String getPathToProjectDir() // { // return pathToProjectDir; // } // // public String getName() // { // return name; // } // // public String getDBConfigFile() // { // return Paths.get(pathToProjectDir, "db").toAbsolutePath().toString(); // } // // public Database getNewDatabaseInstance() // { // return new TitanLocalDatabaseManager().getDatabaseInstanceForProject(this); // } // // }
import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.nio.file.Paths; import com.thinkaurelius.titan.core.schema.Mapping; import org.apache.commons.io.FileUtils; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; import com.thinkaurelius.titan.core.PropertyKey; import com.thinkaurelius.titan.core.TitanFactory; import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.schema.TitanManagement; import com.thinkaurelius.titan.core.util.TitanCleanup; import octopus.api.database.Database; import octopus.api.database.DatabaseManager; import octopus.api.projects.OctopusProject;
private void initializeDatabaseSchema(String configFilename) { TitanGraph graph = TitanFactory.open(configFilename); TitanManagement schema = graph.openManagement(); PropertyKey extIdKey = schema.makePropertyKey("_key").dataType(String.class).make(); PropertyKey typeKey = schema.makePropertyKey("type").dataType(String.class).make(); // At import, we only create separate composite indices for key and type. // Additional indices should be built by plugins. schema.buildIndex("byKey", Vertex.class).addKey(extIdKey).unique().buildCompositeIndex(); schema.buildIndex("byType", Vertex.class).addKey(typeKey).buildCompositeIndex(); // Lucene indices can be built as follows: // This would be how to build a STRING index PropertyKey codeKey = schema.makePropertyKey("code").dataType(String.class).make(); schema.buildIndex("byValue", Vertex.class) .addKey(codeKey, Mapping.STRING.asParameter()).buildMixedIndex("search"); // And this is how to build a TEXT index // schema.buildIndex("byTypeAndValue", Vertex.class).addKey(typeKey). // addKey(valueKey).buildMixedIndex("search"); schema.commit(); graph.close(); } @Override
// Path: src/main/java/octopus/api/database/Database.java // public interface Database { // // // /** // * Return a tinkerpop3 graph instance // * */ // // public Graph getGraph(); // // public void closeInstance(); // // } // // Path: src/main/java/octopus/api/database/DatabaseManager.java // public interface DatabaseManager { // // public void initializeDatabaseForProject(OctopusProject project) throws IOException; // public Database getDatabaseInstanceForProject(OctopusProject project); // public void deleteDatabaseForProject(OctopusProject project); // public void resetDatabase(OctopusProject project); // // } // // Path: src/main/java/octopus/api/projects/OctopusProject.java // public class OctopusProject // { // // private final String pathToProjectDir; // private String name; // // public OctopusProject(String name, String pathToProjectDir) throws IOException // { // this.pathToProjectDir = pathToProjectDir; // this.name = name; // } // // public String getPathToProjectDir() // { // return pathToProjectDir; // } // // public String getName() // { // return name; // } // // public String getDBConfigFile() // { // return Paths.get(pathToProjectDir, "db").toAbsolutePath().toString(); // } // // public Database getNewDatabaseInstance() // { // return new TitanLocalDatabaseManager().getDatabaseInstanceForProject(this); // } // // } // Path: src/main/java/octopus/server/database/titan/TitanLocalDatabaseManager.java import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.nio.file.Paths; import com.thinkaurelius.titan.core.schema.Mapping; import org.apache.commons.io.FileUtils; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; import com.thinkaurelius.titan.core.PropertyKey; import com.thinkaurelius.titan.core.TitanFactory; import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.schema.TitanManagement; import com.thinkaurelius.titan.core.util.TitanCleanup; import octopus.api.database.Database; import octopus.api.database.DatabaseManager; import octopus.api.projects.OctopusProject; private void initializeDatabaseSchema(String configFilename) { TitanGraph graph = TitanFactory.open(configFilename); TitanManagement schema = graph.openManagement(); PropertyKey extIdKey = schema.makePropertyKey("_key").dataType(String.class).make(); PropertyKey typeKey = schema.makePropertyKey("type").dataType(String.class).make(); // At import, we only create separate composite indices for key and type. // Additional indices should be built by plugins. schema.buildIndex("byKey", Vertex.class).addKey(extIdKey).unique().buildCompositeIndex(); schema.buildIndex("byType", Vertex.class).addKey(typeKey).buildCompositeIndex(); // Lucene indices can be built as follows: // This would be how to build a STRING index PropertyKey codeKey = schema.makePropertyKey("code").dataType(String.class).make(); schema.buildIndex("byValue", Vertex.class) .addKey(codeKey, Mapping.STRING.asParameter()).buildMixedIndex("search"); // And this is how to build a TEXT index // schema.buildIndex("byTypeAndValue", Vertex.class).addKey(typeKey). // addKey(valueKey).buildMixedIndex("search"); schema.commit(); graph.close(); } @Override
public Database getDatabaseInstanceForProject(OctopusProject project)
Kixeye/chassis
chassis-support/src/main/java/com/kixeye/chassis/support/metrics/aws/MetricsCloudWatchConfiguration.java
// Path: chassis-support/src/main/java/com/kixeye/chassis/support/util/PropertyUtils.java // public class PropertyUtils { // public static String getPropertyName(String placeHolder){ // return placeHolder.replace("${","").replace("}",""); // } // // }
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import com.kixeye.chassis.support.util.PropertyUtils; import com.netflix.config.ConfigurationManager; import javax.annotation.PostConstruct; import org.apache.commons.configuration.AbstractConfiguration; import org.apache.commons.configuration.event.ConfigurationEvent; import org.apache.commons.configuration.event.ConfigurationListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext;
package com.kixeye.chassis.support.metrics.aws; /* * #%L * Chassis Support * %% * Copyright (C) 2014 KIXEYE, Inc * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ /** * Spring configuration for publishing Metrics to AWS CloudWatch. * * @author dturner@kixeye.com */ @Configuration @ComponentScan(basePackageClasses = MetricsCloudWatchConfiguration.class) public class MetricsCloudWatchConfiguration { private static final Logger logger = LoggerFactory.getLogger(MetricsCloudWatchConfiguration.class); public static final String METRICS_AWS_ENABLED_PROPERTY_NAME = "${metrics.aws.enabled}"; public static String METRICS_AWS_ENABLED; public static String METRICS_AWS_FILTER; public static String METRICS_AWS_PUBLISH_INTERVAL; public static String METRICS_AWS_PUBLISH_INTERVAL_UNIT; static {
// Path: chassis-support/src/main/java/com/kixeye/chassis/support/util/PropertyUtils.java // public class PropertyUtils { // public static String getPropertyName(String placeHolder){ // return placeHolder.replace("${","").replace("}",""); // } // // } // Path: chassis-support/src/main/java/com/kixeye/chassis/support/metrics/aws/MetricsCloudWatchConfiguration.java import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import com.kixeye.chassis.support.util.PropertyUtils; import com.netflix.config.ConfigurationManager; import javax.annotation.PostConstruct; import org.apache.commons.configuration.AbstractConfiguration; import org.apache.commons.configuration.event.ConfigurationEvent; import org.apache.commons.configuration.event.ConfigurationListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; package com.kixeye.chassis.support.metrics.aws; /* * #%L * Chassis Support * %% * Copyright (C) 2014 KIXEYE, Inc * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ /** * Spring configuration for publishing Metrics to AWS CloudWatch. * * @author dturner@kixeye.com */ @Configuration @ComponentScan(basePackageClasses = MetricsCloudWatchConfiguration.class) public class MetricsCloudWatchConfiguration { private static final Logger logger = LoggerFactory.getLogger(MetricsCloudWatchConfiguration.class); public static final String METRICS_AWS_ENABLED_PROPERTY_NAME = "${metrics.aws.enabled}"; public static String METRICS_AWS_ENABLED; public static String METRICS_AWS_FILTER; public static String METRICS_AWS_PUBLISH_INTERVAL; public static String METRICS_AWS_PUBLISH_INTERVAL_UNIT; static {
METRICS_AWS_ENABLED = PropertyUtils.getPropertyName(METRICS_AWS_ENABLED_PROPERTY_NAME);
Kixeye/chassis
chassis-support/src/main/java/com/kixeye/chassis/support/metrics/codahale/MetricsGraphiteConfiguration.java
// Path: chassis-support/src/main/java/com/kixeye/chassis/support/util/PropertyUtils.java // public class PropertyUtils { // public static String getPropertyName(String placeHolder){ // return placeHolder.replace("${","").replace("}",""); // } // // }
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import com.kixeye.chassis.support.util.PropertyUtils; import com.netflix.config.ConfigurationManager; import java.net.UnknownHostException; import javax.annotation.PostConstruct; import org.apache.commons.configuration.AbstractConfiguration; import org.apache.commons.configuration.event.ConfigurationEvent; import org.apache.commons.configuration.event.ConfigurationListener; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext;
package com.kixeye.chassis.support.metrics.codahale; /* * #%L * Chassis Support * %% * Copyright (C) 2014 KIXEYE, Inc * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ @Configuration @ComponentScan(basePackageClasses = MetricsGraphiteConfiguration.class) public class MetricsGraphiteConfiguration { public static final String METRICS_GRAPHITE_ENABLED_PROPERTY_NAME = "${metrics.graphite.enabled}"; private static String METRICS_GRAPHITE_ENABLED; private static String METRICS_GRAPHITE_SERVER; private static String METRICS_GRAPHITE_PORT; private static String METRICS_GRAPHITE_FILTER; private static String METRICS_GRAPHITE_PUBLISH_INTERVAL; private static String METRICS_GRAPHITE_PUBLISH_INTERVAL_UNIT; @Value(METRICS_GRAPHITE_ENABLED_PROPERTY_NAME) private boolean enabled; @Autowired private ApplicationContext applicationContext; private MetricsGraphiteReporterLoader reporterLoader; static {
// Path: chassis-support/src/main/java/com/kixeye/chassis/support/util/PropertyUtils.java // public class PropertyUtils { // public static String getPropertyName(String placeHolder){ // return placeHolder.replace("${","").replace("}",""); // } // // } // Path: chassis-support/src/main/java/com/kixeye/chassis/support/metrics/codahale/MetricsGraphiteConfiguration.java import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import com.kixeye.chassis.support.util.PropertyUtils; import com.netflix.config.ConfigurationManager; import java.net.UnknownHostException; import javax.annotation.PostConstruct; import org.apache.commons.configuration.AbstractConfiguration; import org.apache.commons.configuration.event.ConfigurationEvent; import org.apache.commons.configuration.event.ConfigurationListener; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; package com.kixeye.chassis.support.metrics.codahale; /* * #%L * Chassis Support * %% * Copyright (C) 2014 KIXEYE, Inc * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ @Configuration @ComponentScan(basePackageClasses = MetricsGraphiteConfiguration.class) public class MetricsGraphiteConfiguration { public static final String METRICS_GRAPHITE_ENABLED_PROPERTY_NAME = "${metrics.graphite.enabled}"; private static String METRICS_GRAPHITE_ENABLED; private static String METRICS_GRAPHITE_SERVER; private static String METRICS_GRAPHITE_PORT; private static String METRICS_GRAPHITE_FILTER; private static String METRICS_GRAPHITE_PUBLISH_INTERVAL; private static String METRICS_GRAPHITE_PUBLISH_INTERVAL_UNIT; @Value(METRICS_GRAPHITE_ENABLED_PROPERTY_NAME) private boolean enabled; @Autowired private ApplicationContext applicationContext; private MetricsGraphiteReporterLoader reporterLoader; static {
METRICS_GRAPHITE_ENABLED = PropertyUtils.getPropertyName(METRICS_GRAPHITE_ENABLED_PROPERTY_NAME);
Kixeye/chassis
chassis-bootstrap/src/main/java/com/kixeye/chassis/bootstrap/configuration/ConfigurationProvider.java
// Path: chassis-bootstrap/src/main/java/com/kixeye/chassis/bootstrap/BootstrapException.java // public static class ApplicationConfigurationNotFoundException extends BootstrapException { // public ApplicationConfigurationNotFoundException(String message, Exception e) { // super(message, e); // } // }
import org.apache.commons.configuration.AbstractConfiguration; import java.io.Closeable; import com.kixeye.chassis.bootstrap.BootstrapException.ApplicationConfigurationNotFoundException; import com.kixeye.chassis.bootstrap.aws.ServerInstanceContext;
package com.kixeye.chassis.bootstrap.configuration; /* * #%L * Chassis Bootstrap * %% * Copyright (C) 2014 KIXEYE, Inc * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ /** * Provides a strategy for resolving and/or creating an application's configuration * * @author dturner@kixeye.com */ public interface ConfigurationProvider extends Closeable { /** * Returns the configuration used by the application. * @param environment the environment the application is running in * @param applicationName the name of the application * @param applicationVersion the version of the application * @param serverInstanceContext information about the server that the application is running on. This is useful for providing configurations that are specific to the given server instance only. * @return the configuration * @throws ApplicationConfigurationNotFoundException */ AbstractConfiguration getApplicationConfiguration( String environment, String applicationName, String applicationVersion,
// Path: chassis-bootstrap/src/main/java/com/kixeye/chassis/bootstrap/BootstrapException.java // public static class ApplicationConfigurationNotFoundException extends BootstrapException { // public ApplicationConfigurationNotFoundException(String message, Exception e) { // super(message, e); // } // } // Path: chassis-bootstrap/src/main/java/com/kixeye/chassis/bootstrap/configuration/ConfigurationProvider.java import org.apache.commons.configuration.AbstractConfiguration; import java.io.Closeable; import com.kixeye.chassis.bootstrap.BootstrapException.ApplicationConfigurationNotFoundException; import com.kixeye.chassis.bootstrap.aws.ServerInstanceContext; package com.kixeye.chassis.bootstrap.configuration; /* * #%L * Chassis Bootstrap * %% * Copyright (C) 2014 KIXEYE, Inc * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ /** * Provides a strategy for resolving and/or creating an application's configuration * * @author dturner@kixeye.com */ public interface ConfigurationProvider extends Closeable { /** * Returns the configuration used by the application. * @param environment the environment the application is running in * @param applicationName the name of the application * @param applicationVersion the version of the application * @param serverInstanceContext information about the server that the application is running on. This is useful for providing configurations that are specific to the given server instance only. * @return the configuration * @throws ApplicationConfigurationNotFoundException */ AbstractConfiguration getApplicationConfiguration( String environment, String applicationName, String applicationVersion,
ServerInstanceContext serverInstanceContext) throws ApplicationConfigurationNotFoundException;
Kixeye/chassis
chassis-bootstrap/src/main/java/com/kixeye/chassis/bootstrap/configuration/zookeeper/ZookeeperConfigurationWriter.java
// Path: chassis-bootstrap/src/main/java/com/kixeye/chassis/bootstrap/BootstrapException.java // @SuppressWarnings("serial") // public class BootstrapException extends RuntimeException { // public BootstrapException(String message) { // super(message); // } // // public BootstrapException(String message, Exception e) { // super(message, e); // } // // public static void resourceLoadingFailed(String path, String originalPath, Exception e) { // throw new ResourceLoadingException(path, originalPath, e); // } // // public static void resourceLoadingFailed(String path, Exception e) { // throw new ResourceLoadingException(path, e); // } // // public static void missingApplicationVersion() { // throw new MissingApplicationVersionException(); // } // // public static void zookeeperInitializationFailed(String zookeeperHost, String configPath, Exception e) { // throw new ZookeeperInitializationException(zookeeperHost, configPath, e); // } // // public static void zookeeperInitializationFailed(String zookeeperHost, Exhibitors exhibitors, Exception e) { // throw new ZookeeperInitializationException(zookeeperHost, exhibitors, e); // } // // public static void configurationNotFound(String message, Exception e) { // throw new ApplicationConfigurationNotFoundException(message, e); // } // // public static void moduleKeysConflictFound(String propertyFile, String[] propertyFiles) { // throw new ConflictingModuleConfigurationKeysException(propertyFile, propertyFiles); // } // // public static void zookeeperExhibitorConflict() { // throw new ZookeeperExhibitorUsageException(); // } // // public static void applicationRestartAttempted(){ // throw new ApplicationRestartException(); // } // // public static class MissingApplicationVersionException extends BootstrapException { // // public MissingApplicationVersionException() { // super("application version not found. Version should be defined in application jar's MANIFEST.MF (Implementation-Version), as system property (app.version) or application's configuration (app.version)."); // } // } // // public static class ZookeeperExhibitorUsageException extends BootstrapException{ // // public ZookeeperExhibitorUsageException() { // super("Exhibitor and Zookeeper cannot be configured together. One or the other must be used."); // } // } // // public static class ResourceLoadingException extends BootstrapException { // // public ResourceLoadingException(String path, String originalPath, Exception e) { // super("Unable to load application configuration resource " + path + ". Original path: " + originalPath, e); // } // // public ResourceLoadingException(String path, Exception e) { // super("Unable to load application configuration resource " + path + ".", e); // } // } // // public static class ZookeeperInitializationException extends BootstrapException { // public ZookeeperInitializationException(String zookeeperHost, String configPath, Exception e) { // super("Unable to initialize zookeeper configuration for zookeeper " + zookeeperHost + " at path " + configPath + ".", e); // } // // public ZookeeperInitializationException(String zookeeperHost, Exhibitors exhibitors, Exception e) { // super("Unable to initialize zookeeper configuration for zookeeper " + zookeeperHost + ". Exhibitors:" + ReflectionToStringBuilder.reflectionToString(exhibitors), e); // } // } // // public static class ApplicationConfigurationNotFoundException extends BootstrapException { // public ApplicationConfigurationNotFoundException(String message, Exception e) { // super(message, e); // } // } // // public static class ConflictingModuleConfigurationKeysException extends BootstrapException { // public ConflictingModuleConfigurationKeysException(String propertyFile, String[] propertyFiles) { // super("Duplicate key found in default property file " // + propertyFile // + ". Check that all default property files contains unique keys. Files: " // + Arrays.toString(propertyFiles)); // } // } // // public static class ApplicationRestartException extends BootstrapException{ // public ApplicationRestartException(){ // super("Application cannot be restarted."); // } // } // // }
import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeSet; import com.google.common.base.Preconditions; import com.kixeye.chassis.bootstrap.BootstrapException; import com.kixeye.chassis.bootstrap.configuration.ConfigurationWriter; import com.kixeye.chassis.bootstrap.configuration.Configurations; import org.apache.commons.configuration.Configuration; import org.apache.commons.lang.StringUtils; import org.apache.curator.framework.CuratorFramework; import org.apache.zookeeper.KeeperException.NodeExistsException; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
Preconditions.checkArgument(StringUtils.isNotBlank(version), "version is required"); this.configPath = String.format("/%s/%s/%s/config", environment, applicationName, version); this.curatorFramework = curatorFramework; this.allowOverwrite = allowOverwrite; } @Override public void write(Configuration configuration, Filter propertyFilter) { Map<String, ?> config = Configurations.asMap(configuration); boolean exists = validateConfigPathAbsent(); if (!exists) { writeConfigPath(configPath); } ArrayList<Set<String>> deltas = findDeltas(config); for (String key : deltas.get(0)) { String value = config.get(key) + ""; String path = configPath + "/" + key; writeKey(path, value, propertyFilter); } for (String key : deltas.get(1)) { deleteKey(configPath + "/" + key); } } private void deleteKey(String key) { try { LOGGER.info("deleting key {}...", key); curatorFramework.delete().forPath(key); } catch (Exception e) {
// Path: chassis-bootstrap/src/main/java/com/kixeye/chassis/bootstrap/BootstrapException.java // @SuppressWarnings("serial") // public class BootstrapException extends RuntimeException { // public BootstrapException(String message) { // super(message); // } // // public BootstrapException(String message, Exception e) { // super(message, e); // } // // public static void resourceLoadingFailed(String path, String originalPath, Exception e) { // throw new ResourceLoadingException(path, originalPath, e); // } // // public static void resourceLoadingFailed(String path, Exception e) { // throw new ResourceLoadingException(path, e); // } // // public static void missingApplicationVersion() { // throw new MissingApplicationVersionException(); // } // // public static void zookeeperInitializationFailed(String zookeeperHost, String configPath, Exception e) { // throw new ZookeeperInitializationException(zookeeperHost, configPath, e); // } // // public static void zookeeperInitializationFailed(String zookeeperHost, Exhibitors exhibitors, Exception e) { // throw new ZookeeperInitializationException(zookeeperHost, exhibitors, e); // } // // public static void configurationNotFound(String message, Exception e) { // throw new ApplicationConfigurationNotFoundException(message, e); // } // // public static void moduleKeysConflictFound(String propertyFile, String[] propertyFiles) { // throw new ConflictingModuleConfigurationKeysException(propertyFile, propertyFiles); // } // // public static void zookeeperExhibitorConflict() { // throw new ZookeeperExhibitorUsageException(); // } // // public static void applicationRestartAttempted(){ // throw new ApplicationRestartException(); // } // // public static class MissingApplicationVersionException extends BootstrapException { // // public MissingApplicationVersionException() { // super("application version not found. Version should be defined in application jar's MANIFEST.MF (Implementation-Version), as system property (app.version) or application's configuration (app.version)."); // } // } // // public static class ZookeeperExhibitorUsageException extends BootstrapException{ // // public ZookeeperExhibitorUsageException() { // super("Exhibitor and Zookeeper cannot be configured together. One or the other must be used."); // } // } // // public static class ResourceLoadingException extends BootstrapException { // // public ResourceLoadingException(String path, String originalPath, Exception e) { // super("Unable to load application configuration resource " + path + ". Original path: " + originalPath, e); // } // // public ResourceLoadingException(String path, Exception e) { // super("Unable to load application configuration resource " + path + ".", e); // } // } // // public static class ZookeeperInitializationException extends BootstrapException { // public ZookeeperInitializationException(String zookeeperHost, String configPath, Exception e) { // super("Unable to initialize zookeeper configuration for zookeeper " + zookeeperHost + " at path " + configPath + ".", e); // } // // public ZookeeperInitializationException(String zookeeperHost, Exhibitors exhibitors, Exception e) { // super("Unable to initialize zookeeper configuration for zookeeper " + zookeeperHost + ". Exhibitors:" + ReflectionToStringBuilder.reflectionToString(exhibitors), e); // } // } // // public static class ApplicationConfigurationNotFoundException extends BootstrapException { // public ApplicationConfigurationNotFoundException(String message, Exception e) { // super(message, e); // } // } // // public static class ConflictingModuleConfigurationKeysException extends BootstrapException { // public ConflictingModuleConfigurationKeysException(String propertyFile, String[] propertyFiles) { // super("Duplicate key found in default property file " // + propertyFile // + ". Check that all default property files contains unique keys. Files: " // + Arrays.toString(propertyFiles)); // } // } // // public static class ApplicationRestartException extends BootstrapException{ // public ApplicationRestartException(){ // super("Application cannot be restarted."); // } // } // // } // Path: chassis-bootstrap/src/main/java/com/kixeye/chassis/bootstrap/configuration/zookeeper/ZookeeperConfigurationWriter.java import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeSet; import com.google.common.base.Preconditions; import com.kixeye.chassis.bootstrap.BootstrapException; import com.kixeye.chassis.bootstrap.configuration.ConfigurationWriter; import com.kixeye.chassis.bootstrap.configuration.Configurations; import org.apache.commons.configuration.Configuration; import org.apache.commons.lang.StringUtils; import org.apache.curator.framework.CuratorFramework; import org.apache.zookeeper.KeeperException.NodeExistsException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; Preconditions.checkArgument(StringUtils.isNotBlank(version), "version is required"); this.configPath = String.format("/%s/%s/%s/config", environment, applicationName, version); this.curatorFramework = curatorFramework; this.allowOverwrite = allowOverwrite; } @Override public void write(Configuration configuration, Filter propertyFilter) { Map<String, ?> config = Configurations.asMap(configuration); boolean exists = validateConfigPathAbsent(); if (!exists) { writeConfigPath(configPath); } ArrayList<Set<String>> deltas = findDeltas(config); for (String key : deltas.get(0)) { String value = config.get(key) + ""; String path = configPath + "/" + key; writeKey(path, value, propertyFilter); } for (String key : deltas.get(1)) { deleteKey(configPath + "/" + key); } } private void deleteKey(String key) { try { LOGGER.info("deleting key {}...", key); curatorFramework.delete().forPath(key); } catch (Exception e) {
throw new BootstrapException("Failed to delete key " + key, e);
fergarrui/custom-bytecode-analyzer
src/main/java/net/nandgr/cba/custom/visitor/RuleVisitorsAnalyzer.java
// Path: src/main/java/net/nandgr/cba/custom/visitor/base/CustomVisitor.java // public interface CustomVisitor { // void setNode(Object node); // void process(); // boolean issueFound(); // void setIssueFound(boolean issueFound); // Collection<ReportItem> itemsFound(); // String getRuleName(); // boolean showInReport(); // void clear(); // } // // Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // }
import net.nandgr.cba.custom.visitor.base.CustomVisitor; import net.nandgr.cba.report.ReportItem; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.objectweb.asm.tree.ClassNode;
/* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.custom.visitor; public class RuleVisitorsAnalyzer { private final List<CustomVisitor> visitorList = new ArrayList<>(); public List<CustomVisitor> getVisitorList() { return visitorList; }
// Path: src/main/java/net/nandgr/cba/custom/visitor/base/CustomVisitor.java // public interface CustomVisitor { // void setNode(Object node); // void process(); // boolean issueFound(); // void setIssueFound(boolean issueFound); // Collection<ReportItem> itemsFound(); // String getRuleName(); // boolean showInReport(); // void clear(); // } // // Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // } // Path: src/main/java/net/nandgr/cba/custom/visitor/RuleVisitorsAnalyzer.java import net.nandgr.cba.custom.visitor.base.CustomVisitor; import net.nandgr.cba.report.ReportItem; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.objectweb.asm.tree.ClassNode; /* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.custom.visitor; public class RuleVisitorsAnalyzer { private final List<CustomVisitor> visitorList = new ArrayList<>(); public List<CustomVisitor> getVisitorList() { return visitorList; }
public List<ReportItem> runRules(ClassNode classNode) throws IOException {
fergarrui/custom-bytecode-analyzer
src/main/java/net/nandgr/cba/custom/visitor/base/CustomVisitor.java
// Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // }
import java.util.Collection; import net.nandgr.cba.report.ReportItem;
/* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.custom.visitor.base; public interface CustomVisitor { void setNode(Object node); void process(); boolean issueFound(); void setIssueFound(boolean issueFound);
// Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // } // Path: src/main/java/net/nandgr/cba/custom/visitor/base/CustomVisitor.java import java.util.Collection; import net.nandgr.cba.report.ReportItem; /* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.custom.visitor.base; public interface CustomVisitor { void setNode(Object node); void process(); boolean issueFound(); void setIssueFound(boolean issueFound);
Collection<ReportItem> itemsFound();
fergarrui/custom-bytecode-analyzer
src/test/java/rules/InvocationsTest.java
// Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // }
import java.util.List; import net.nandgr.cba.report.ReportItem; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue;
package rules; public class InvocationsTest extends AbstractTest { public InvocationsTest() { super("invocations"); } @Test public void test() { runTests();
// Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // } // Path: src/test/java/rules/InvocationsTest.java import java.util.List; import net.nandgr.cba.report.ReportItem; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; package rules; public class InvocationsTest extends AbstractTest { public InvocationsTest() { super("invocations"); } @Test public void test() { runTests();
List<ReportItem> reportItems1 = getReportItems("invocations1");
fergarrui/custom-bytecode-analyzer
src/test/java/rules/InterfacesTest.java
// Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // }
import java.util.List; import net.nandgr.cba.report.ReportItem; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import org.junit.Test;
package rules; public class InterfacesTest extends AbstractTest { public InterfacesTest() { super("interfaces"); } @Test public void test() { runTests();
// Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // } // Path: src/test/java/rules/InterfacesTest.java import java.util.List; import net.nandgr.cba.report.ReportItem; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import org.junit.Test; package rules; public class InterfacesTest extends AbstractTest { public InterfacesTest() { super("interfaces"); } @Test public void test() { runTests();
List<ReportItem> reportItems1 = getReportItems("interfaces1");
fergarrui/custom-bytecode-analyzer
src/main/java/net/nandgr/cba/visitor/checks/CustomDeserializationCheck.java
// Path: src/main/java/net/nandgr/cba/custom/visitor/base/CustomAbstractClassVisitor.java // public abstract class CustomAbstractClassVisitor extends CustomAbstractVisitor { // // private ClassNode classNode; // // public CustomAbstractClassVisitor(String ruleName) { // super(ruleName); // } // // @Override // public void setNode(Object node) { // this.classNode = (ClassNode) node; // } // // public ClassNode getClassNode() { // return classNode; // } // } // // Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // } // // Path: src/main/java/net/nandgr/cba/visitor/checks/util/SerializationHelper.java // public class SerializationHelper { // // private static final String READ_OBJECT_ARGUMENT = "java/io/ObjectInputStream"; // private static final String READ_OBJECT_NAME = "readObject"; // // private SerializationHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // // public static boolean isCustomDeserializationMethod(int access, String name, String desc) { // return access == Opcodes.ACC_PRIVATE && READ_OBJECT_NAME.equals(name) && desc.contains(READ_OBJECT_ARGUMENT); // } // }
import java.util.List; import net.nandgr.cba.custom.visitor.base.CustomAbstractClassVisitor; import net.nandgr.cba.report.ReportItem; import net.nandgr.cba.visitor.checks.util.SerializationHelper; import org.objectweb.asm.tree.MethodNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
/* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.visitor.checks; public class CustomDeserializationCheck extends CustomAbstractClassVisitor { private static final Logger logger = LoggerFactory.getLogger(CustomDeserializationCheck.class); public CustomDeserializationCheck() { super("CustomDeserializationCheck"); } @Override public void process() { for (MethodNode methodNode : getClassNode().methods) { int access = methodNode.access; String name = methodNode.name; String desc = methodNode.name; String signature = methodNode.signature; List<String> exceptions = methodNode.exceptions; logger.trace("visitMethod: access={} name={} desc={} signature={} exceptions={}", access, name, desc, signature, exceptions);
// Path: src/main/java/net/nandgr/cba/custom/visitor/base/CustomAbstractClassVisitor.java // public abstract class CustomAbstractClassVisitor extends CustomAbstractVisitor { // // private ClassNode classNode; // // public CustomAbstractClassVisitor(String ruleName) { // super(ruleName); // } // // @Override // public void setNode(Object node) { // this.classNode = (ClassNode) node; // } // // public ClassNode getClassNode() { // return classNode; // } // } // // Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // } // // Path: src/main/java/net/nandgr/cba/visitor/checks/util/SerializationHelper.java // public class SerializationHelper { // // private static final String READ_OBJECT_ARGUMENT = "java/io/ObjectInputStream"; // private static final String READ_OBJECT_NAME = "readObject"; // // private SerializationHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // // public static boolean isCustomDeserializationMethod(int access, String name, String desc) { // return access == Opcodes.ACC_PRIVATE && READ_OBJECT_NAME.equals(name) && desc.contains(READ_OBJECT_ARGUMENT); // } // } // Path: src/main/java/net/nandgr/cba/visitor/checks/CustomDeserializationCheck.java import java.util.List; import net.nandgr.cba.custom.visitor.base.CustomAbstractClassVisitor; import net.nandgr.cba.report.ReportItem; import net.nandgr.cba.visitor.checks.util.SerializationHelper; import org.objectweb.asm.tree.MethodNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.visitor.checks; public class CustomDeserializationCheck extends CustomAbstractClassVisitor { private static final Logger logger = LoggerFactory.getLogger(CustomDeserializationCheck.class); public CustomDeserializationCheck() { super("CustomDeserializationCheck"); } @Override public void process() { for (MethodNode methodNode : getClassNode().methods) { int access = methodNode.access; String name = methodNode.name; String desc = methodNode.name; String signature = methodNode.signature; List<String> exceptions = methodNode.exceptions; logger.trace("visitMethod: access={} name={} desc={} signature={} exceptions={}", access, name, desc, signature, exceptions);
if (SerializationHelper.isCustomDeserializationMethod(access, name, desc)) {
fergarrui/custom-bytecode-analyzer
src/main/java/net/nandgr/cba/visitor/checks/CustomDeserializationCheck.java
// Path: src/main/java/net/nandgr/cba/custom/visitor/base/CustomAbstractClassVisitor.java // public abstract class CustomAbstractClassVisitor extends CustomAbstractVisitor { // // private ClassNode classNode; // // public CustomAbstractClassVisitor(String ruleName) { // super(ruleName); // } // // @Override // public void setNode(Object node) { // this.classNode = (ClassNode) node; // } // // public ClassNode getClassNode() { // return classNode; // } // } // // Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // } // // Path: src/main/java/net/nandgr/cba/visitor/checks/util/SerializationHelper.java // public class SerializationHelper { // // private static final String READ_OBJECT_ARGUMENT = "java/io/ObjectInputStream"; // private static final String READ_OBJECT_NAME = "readObject"; // // private SerializationHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // // public static boolean isCustomDeserializationMethod(int access, String name, String desc) { // return access == Opcodes.ACC_PRIVATE && READ_OBJECT_NAME.equals(name) && desc.contains(READ_OBJECT_ARGUMENT); // } // }
import java.util.List; import net.nandgr.cba.custom.visitor.base.CustomAbstractClassVisitor; import net.nandgr.cba.report.ReportItem; import net.nandgr.cba.visitor.checks.util.SerializationHelper; import org.objectweb.asm.tree.MethodNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
/* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.visitor.checks; public class CustomDeserializationCheck extends CustomAbstractClassVisitor { private static final Logger logger = LoggerFactory.getLogger(CustomDeserializationCheck.class); public CustomDeserializationCheck() { super("CustomDeserializationCheck"); } @Override public void process() { for (MethodNode methodNode : getClassNode().methods) { int access = methodNode.access; String name = methodNode.name; String desc = methodNode.name; String signature = methodNode.signature; List<String> exceptions = methodNode.exceptions; logger.trace("visitMethod: access={} name={} desc={} signature={} exceptions={}", access, name, desc, signature, exceptions); if (SerializationHelper.isCustomDeserializationMethod(access, name, desc)) {
// Path: src/main/java/net/nandgr/cba/custom/visitor/base/CustomAbstractClassVisitor.java // public abstract class CustomAbstractClassVisitor extends CustomAbstractVisitor { // // private ClassNode classNode; // // public CustomAbstractClassVisitor(String ruleName) { // super(ruleName); // } // // @Override // public void setNode(Object node) { // this.classNode = (ClassNode) node; // } // // public ClassNode getClassNode() { // return classNode; // } // } // // Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // } // // Path: src/main/java/net/nandgr/cba/visitor/checks/util/SerializationHelper.java // public class SerializationHelper { // // private static final String READ_OBJECT_ARGUMENT = "java/io/ObjectInputStream"; // private static final String READ_OBJECT_NAME = "readObject"; // // private SerializationHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // // public static boolean isCustomDeserializationMethod(int access, String name, String desc) { // return access == Opcodes.ACC_PRIVATE && READ_OBJECT_NAME.equals(name) && desc.contains(READ_OBJECT_ARGUMENT); // } // } // Path: src/main/java/net/nandgr/cba/visitor/checks/CustomDeserializationCheck.java import java.util.List; import net.nandgr.cba.custom.visitor.base.CustomAbstractClassVisitor; import net.nandgr.cba.report.ReportItem; import net.nandgr.cba.visitor.checks.util.SerializationHelper; import org.objectweb.asm.tree.MethodNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.visitor.checks; public class CustomDeserializationCheck extends CustomAbstractClassVisitor { private static final Logger logger = LoggerFactory.getLogger(CustomDeserializationCheck.class); public CustomDeserializationCheck() { super("CustomDeserializationCheck"); } @Override public void process() { for (MethodNode methodNode : getClassNode().methods) { int access = methodNode.access; String name = methodNode.name; String desc = methodNode.name; String signature = methodNode.signature; List<String> exceptions = methodNode.exceptions; logger.trace("visitMethod: access={} name={} desc={} signature={} exceptions={}", access, name, desc, signature, exceptions); if (SerializationHelper.isCustomDeserializationMethod(access, name, desc)) {
ReportItem reportItem = new ReportItem(getRuleName(), foundIssue).addProperty("Method name", name);
fergarrui/custom-bytecode-analyzer
src/test/java/rules/SuperClassTest.java
// Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // }
import net.nandgr.cba.report.ReportItem; import org.junit.Test; import static org.junit.Assert.assertEquals;
package rules; public class SuperClassTest extends AbstractTest { public SuperClassTest() { super("superclass"); } @Test public void test() { runTests();
// Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // } // Path: src/test/java/rules/SuperClassTest.java import net.nandgr.cba.report.ReportItem; import org.junit.Test; import static org.junit.Assert.assertEquals; package rules; public class SuperClassTest extends AbstractTest { public SuperClassTest() { super("superclass"); } @Test public void test() { runTests();
ReportItem reportItem0 = getReportItems().get(0);
fergarrui/custom-bytecode-analyzer
src/test/java/rules/MethodsTest.java
// Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // }
import java.util.List; import net.nandgr.cba.report.ReportItem; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue;
package rules; public class MethodsTest extends AbstractTest { public MethodsTest() { super("methods"); } @Test public void test(){ runTests();
// Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // } // Path: src/test/java/rules/MethodsTest.java import java.util.List; import net.nandgr.cba.report.ReportItem; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; package rules; public class MethodsTest extends AbstractTest { public MethodsTest() { super("methods"); } @Test public void test(){ runTests();
List<ReportItem> reportItems1 = getReportItems("methods1");
fergarrui/custom-bytecode-analyzer
src/main/java/net/nandgr/cba/callgraph/graph/InvocationGraph.java
// Path: src/main/java/net/nandgr/cba/callgraph/model/MethodGraph.java // public class MethodGraph { // // private final String owner; // private final String name; // // public MethodGraph(String owner, String name) { // this.owner = owner; // this.name = name; // } // // public String getOwner() { // return owner; // } // // public String getName() { // return name; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof MethodGraph)) return false; // // MethodGraph that = (MethodGraph) o; // // if (!getOwner().equals(that.getOwner())) return false; // return getName().equals(that.getName()); // } // // @Override // public int hashCode() { // int result = getOwner().hashCode(); // result = 31 * result + getName().hashCode(); // return result; // } // // @Override // public String toString() { // return "MethodGraph{" + // "owner='" + owner + '\'' + // ", name='" + name + '\'' + // '}'; // } // }
import java.util.Collection; import net.nandgr.cba.callgraph.model.MethodGraph;
/* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.callgraph.graph; /** * This interface contains and manages all relations between the method invocations. * @param <T> Is the type of vertex (method) * @param <C> Is the relation between two vertex. Should represent a method invocation. */ public interface InvocationGraph<T, C> { /** * Standard contains method. * @param element element to find * @return a T element when found. Null of not found */ boolean contains(T element); /** * Adds an element to a parent. * @param element */ void add(T element, T parent); /** * @param element * @return A collection of C (invocations) from element to the beginning of the graph. */ Collection<C> pathsToParents(T element);
// Path: src/main/java/net/nandgr/cba/callgraph/model/MethodGraph.java // public class MethodGraph { // // private final String owner; // private final String name; // // public MethodGraph(String owner, String name) { // this.owner = owner; // this.name = name; // } // // public String getOwner() { // return owner; // } // // public String getName() { // return name; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof MethodGraph)) return false; // // MethodGraph that = (MethodGraph) o; // // if (!getOwner().equals(that.getOwner())) return false; // return getName().equals(that.getName()); // } // // @Override // public int hashCode() { // int result = getOwner().hashCode(); // result = 31 * result + getName().hashCode(); // return result; // } // // @Override // public String toString() { // return "MethodGraph{" + // "owner='" + owner + '\'' + // ", name='" + name + '\'' + // '}'; // } // } // Path: src/main/java/net/nandgr/cba/callgraph/graph/InvocationGraph.java import java.util.Collection; import net.nandgr.cba.callgraph.model.MethodGraph; /* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.callgraph.graph; /** * This interface contains and manages all relations between the method invocations. * @param <T> Is the type of vertex (method) * @param <C> Is the relation between two vertex. Should represent a method invocation. */ public interface InvocationGraph<T, C> { /** * Standard contains method. * @param element element to find * @return a T element when found. Null of not found */ boolean contains(T element); /** * Adds an element to a parent. * @param element */ void add(T element, T parent); /** * @param element * @return A collection of C (invocations) from element to the beginning of the graph. */ Collection<C> pathsToParents(T element);
boolean findCycles(MethodGraph vertex);
fergarrui/custom-bytecode-analyzer
src/test/java/rules/AnnotationsTest.java
// Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // }
import java.util.List; import net.nandgr.cba.report.ReportItem; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue;
package rules; public class AnnotationsTest extends AbstractTest { public AnnotationsTest() { super("annotations"); } @Test public void test(){ runTests();
// Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // } // Path: src/test/java/rules/AnnotationsTest.java import java.util.List; import net.nandgr.cba.report.ReportItem; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; package rules; public class AnnotationsTest extends AbstractTest { public AnnotationsTest() { super("annotations"); } @Test public void test(){ runTests();
List<ReportItem> reportItems1 = getReportItems("annotations1");
fergarrui/custom-bytecode-analyzer
src/main/java/net/nandgr/cba/cli/CliHelper.java
// Path: src/main/java/net/nandgr/cba/custom/model/Rules.java // public class Rules { // // private List<Rule> rules; // // public List<Rule> getRules() { // return rules; // } // // public void setRules(List<Rule> rules) { // this.rules = rules; // } // // @Override // public String toString() { // return "Rules{" + // "rules=" + Arrays.toString(rules.toArray()) + // '}'; // } // // public void validateRules() throws BadRulesException { // for (Rule rule : this.getRules()) { // if (StringUtils.isBlank(rule.getName())) { // throw new BadRulesException("Rule name cannot be blank."); // } // validateRule(rule); // } // } // // private static void validateRule(Rule rule) throws BadRulesException { // if (rule.getInvocations() != null) { // for (Invocation invocation : rule.getInvocations()) { // // Method notFrom = invocation.getNotFrom(); // checkEmpty(notFrom, "\"invocation.notFrom\" property cannot have all the fields blank."); // // Method from = invocation.getFrom(); // checkEmpty(from, "\"invocation.from\" property cannot have all the fields blank."); // // Method method = invocation.getMethod(); // checkEmpty(method, "\"invocation.method\" property cannot have all the fields blank."); // // if (notFrom != null && from != null) { // throw new BadRulesException("\"invocation.notFrom\" and \"invocation.from\" cannot be defined at the same time in the same rule."); // } // } // } // } // // private static void checkEmpty(Method method, String message) throws BadRulesException { // if (allEmpty(method)) { // throw new BadRulesException(message); // } // } // }
import net.nandgr.cba.custom.model.Rules; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.ParseException;
/* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.cli; public class CliHelper { private static CommandLineParser commandLineParser = new DefaultParser(); private static CommandLine commandLine;
// Path: src/main/java/net/nandgr/cba/custom/model/Rules.java // public class Rules { // // private List<Rule> rules; // // public List<Rule> getRules() { // return rules; // } // // public void setRules(List<Rule> rules) { // this.rules = rules; // } // // @Override // public String toString() { // return "Rules{" + // "rules=" + Arrays.toString(rules.toArray()) + // '}'; // } // // public void validateRules() throws BadRulesException { // for (Rule rule : this.getRules()) { // if (StringUtils.isBlank(rule.getName())) { // throw new BadRulesException("Rule name cannot be blank."); // } // validateRule(rule); // } // } // // private static void validateRule(Rule rule) throws BadRulesException { // if (rule.getInvocations() != null) { // for (Invocation invocation : rule.getInvocations()) { // // Method notFrom = invocation.getNotFrom(); // checkEmpty(notFrom, "\"invocation.notFrom\" property cannot have all the fields blank."); // // Method from = invocation.getFrom(); // checkEmpty(from, "\"invocation.from\" property cannot have all the fields blank."); // // Method method = invocation.getMethod(); // checkEmpty(method, "\"invocation.method\" property cannot have all the fields blank."); // // if (notFrom != null && from != null) { // throw new BadRulesException("\"invocation.notFrom\" and \"invocation.from\" cannot be defined at the same time in the same rule."); // } // } // } // } // // private static void checkEmpty(Method method, String message) throws BadRulesException { // if (allEmpty(method)) { // throw new BadRulesException(message); // } // } // } // Path: src/main/java/net/nandgr/cba/cli/CliHelper.java import net.nandgr.cba.custom.model.Rules; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.ParseException; /* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.cli; public class CliHelper { private static CommandLineParser commandLineParser = new DefaultParser(); private static CommandLine commandLine;
private static Rules rules;
fergarrui/custom-bytecode-analyzer
src/main/java/net/nandgr/cba/custom/model/Rules.java
// Path: src/main/java/net/nandgr/cba/exception/BadRulesException.java // public class BadRulesException extends Exception { // // public BadRulesException(String message) { // super(message); // } // } // // Path: src/main/java/net/nandgr/cba/custom/visitor/helper/RuleHelper.java // public static boolean allEmpty(Method method) { // if (method == null) { // return false; // } // return StringUtils.isBlank(method.getName()) && method.getParameters() == null && StringUtils.isBlank(method.getVisibility()); // }
import java.util.Arrays; import java.util.List; import net.nandgr.cba.exception.BadRulesException; import org.apache.commons.lang.StringUtils; import static net.nandgr.cba.custom.visitor.helper.RuleHelper.allEmpty;
/* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.custom.model; public class Rules { private List<Rule> rules; public List<Rule> getRules() { return rules; } public void setRules(List<Rule> rules) { this.rules = rules; } @Override public String toString() { return "Rules{" + "rules=" + Arrays.toString(rules.toArray()) + '}'; }
// Path: src/main/java/net/nandgr/cba/exception/BadRulesException.java // public class BadRulesException extends Exception { // // public BadRulesException(String message) { // super(message); // } // } // // Path: src/main/java/net/nandgr/cba/custom/visitor/helper/RuleHelper.java // public static boolean allEmpty(Method method) { // if (method == null) { // return false; // } // return StringUtils.isBlank(method.getName()) && method.getParameters() == null && StringUtils.isBlank(method.getVisibility()); // } // Path: src/main/java/net/nandgr/cba/custom/model/Rules.java import java.util.Arrays; import java.util.List; import net.nandgr.cba.exception.BadRulesException; import org.apache.commons.lang.StringUtils; import static net.nandgr.cba.custom.visitor.helper.RuleHelper.allEmpty; /* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.custom.model; public class Rules { private List<Rule> rules; public List<Rule> getRules() { return rules; } public void setRules(List<Rule> rules) { this.rules = rules; } @Override public String toString() { return "Rules{" + "rules=" + Arrays.toString(rules.toArray()) + '}'; }
public void validateRules() throws BadRulesException {
fergarrui/custom-bytecode-analyzer
src/main/java/net/nandgr/cba/custom/model/Rules.java
// Path: src/main/java/net/nandgr/cba/exception/BadRulesException.java // public class BadRulesException extends Exception { // // public BadRulesException(String message) { // super(message); // } // } // // Path: src/main/java/net/nandgr/cba/custom/visitor/helper/RuleHelper.java // public static boolean allEmpty(Method method) { // if (method == null) { // return false; // } // return StringUtils.isBlank(method.getName()) && method.getParameters() == null && StringUtils.isBlank(method.getVisibility()); // }
import java.util.Arrays; import java.util.List; import net.nandgr.cba.exception.BadRulesException; import org.apache.commons.lang.StringUtils; import static net.nandgr.cba.custom.visitor.helper.RuleHelper.allEmpty;
public void validateRules() throws BadRulesException { for (Rule rule : this.getRules()) { if (StringUtils.isBlank(rule.getName())) { throw new BadRulesException("Rule name cannot be blank."); } validateRule(rule); } } private static void validateRule(Rule rule) throws BadRulesException { if (rule.getInvocations() != null) { for (Invocation invocation : rule.getInvocations()) { Method notFrom = invocation.getNotFrom(); checkEmpty(notFrom, "\"invocation.notFrom\" property cannot have all the fields blank."); Method from = invocation.getFrom(); checkEmpty(from, "\"invocation.from\" property cannot have all the fields blank."); Method method = invocation.getMethod(); checkEmpty(method, "\"invocation.method\" property cannot have all the fields blank."); if (notFrom != null && from != null) { throw new BadRulesException("\"invocation.notFrom\" and \"invocation.from\" cannot be defined at the same time in the same rule."); } } } } private static void checkEmpty(Method method, String message) throws BadRulesException {
// Path: src/main/java/net/nandgr/cba/exception/BadRulesException.java // public class BadRulesException extends Exception { // // public BadRulesException(String message) { // super(message); // } // } // // Path: src/main/java/net/nandgr/cba/custom/visitor/helper/RuleHelper.java // public static boolean allEmpty(Method method) { // if (method == null) { // return false; // } // return StringUtils.isBlank(method.getName()) && method.getParameters() == null && StringUtils.isBlank(method.getVisibility()); // } // Path: src/main/java/net/nandgr/cba/custom/model/Rules.java import java.util.Arrays; import java.util.List; import net.nandgr.cba.exception.BadRulesException; import org.apache.commons.lang.StringUtils; import static net.nandgr.cba.custom.visitor.helper.RuleHelper.allEmpty; public void validateRules() throws BadRulesException { for (Rule rule : this.getRules()) { if (StringUtils.isBlank(rule.getName())) { throw new BadRulesException("Rule name cannot be blank."); } validateRule(rule); } } private static void validateRule(Rule rule) throws BadRulesException { if (rule.getInvocations() != null) { for (Invocation invocation : rule.getInvocations()) { Method notFrom = invocation.getNotFrom(); checkEmpty(notFrom, "\"invocation.notFrom\" property cannot have all the fields blank."); Method from = invocation.getFrom(); checkEmpty(from, "\"invocation.from\" property cannot have all the fields blank."); Method method = invocation.getMethod(); checkEmpty(method, "\"invocation.method\" property cannot have all the fields blank."); if (notFrom != null && from != null) { throw new BadRulesException("\"invocation.notFrom\" and \"invocation.from\" cannot be defined at the same time in the same rule."); } } } } private static void checkEmpty(Method method, String message) throws BadRulesException {
if (allEmpty(method)) {
fergarrui/custom-bytecode-analyzer
src/main/java/net/nandgr/cba/report/ReportBuilder.java
// Path: src/main/java/net/nandgr/cba/custom/visitor/helper/StringsHelper.java // public class StringsHelper { // // private static final String CLASS_SUFFIX = ".class"; // // private StringsHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // // public static String dotsToSlashes(String s) { // return s.replaceAll("\\.", "/"); // } // // public static String spacesToDashesLowercase(String s) { // return s.replaceAll(" ", "-").toLowerCase(); // } // // public static String simpleDescriptorToHuman(String s) { // String result = s; // if(result.startsWith("[")) { // result = result.substring(1, result.length()); // } // if (result.startsWith("L")) { // result = result.substring(1, result.length()); // } // if (result.endsWith(";")) { // result = result.substring(0, result.length()-1); // // } // return result; // } // // public static String removeClassSuffix(String s) { // if (s.endsWith(CLASS_SUFFIX)) { // return s.substring(0, s.length()-CLASS_SUFFIX.length()); // } // return s; // } // } // // Path: src/main/java/net/nandgr/cba/cli/CliHelper.java // public class CliHelper { // // private static CommandLineParser commandLineParser = new DefaultParser(); // private static CommandLine commandLine; // private static Rules rules; // // private CliHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // // public static void parseCliArguments(String[] args) throws ParseException { // commandLine = commandLineParser.parse(CliArguments.getOptions(), args); // } // // public static String getPathToAnalyze() { // return commandLine.getOptionValue("a"); // } // // public static int getMaxThreads() { // return Integer.parseInt(commandLine.getOptionValue("t", CliArguments.MAX_THREADS_DEFAULT)); // } // // public static boolean hasOutputDir() { // return commandLine.hasOption("o"); // } // // public static String getOutputDir() { // return commandLine.getOptionValue("o", CliArguments.OUTPUT_DEFAULT); // } // // public static boolean hasMaxItemsInReport() { // return commandLine.hasOption("i"); // } // // public static int getMaxItemsInReport() { // return Integer.parseInt(commandLine.getOptionValue("i", CliArguments.MAX_ITEMS_IN_REPORT_DEFAULT)); // } // // public static boolean hasChecks() { // return commandLine.hasOption("c"); // } // // public static String[] getChecks() { // return commandLine.getOptionValues("c"); // } // // public static boolean hasCustomFile() { // return commandLine.hasOption("f"); // } // // public static String getCustomFile() { // return commandLine.getOptionValue("f"); // } // // public static void printHelp() { // HelpFormatter helpFormatter = new HelpFormatter(); // helpFormatter.printHelp("java -jar cba-cli.jar [OPTIONS] -a DIRECTORY_TO_ANALYZE", CliArguments.getOptions()); // } // // public static boolean hasHelp() { // return commandLine.hasOption("h"); // } // // public static boolean hasVerboseDebug() { // return commandLine.hasOption("v"); // } // // public static boolean hasVerboseTrace() { // return commandLine.hasOption("vv"); // } // // public static Rules getRules() { // return rules; // } // // public static void setRules(Rules rules) { // CliHelper.rules = rules; // } // }
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.collect.Lists; import java.io.StringWriter; import java.util.Properties; import net.nandgr.cba.custom.visitor.helper.StringsHelper; import net.nandgr.cba.cli.CliHelper; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.commons.io.FileUtils; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine;
/* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.report; public class ReportBuilder { private static final Logger logger = LoggerFactory.getLogger(ReportBuilder.class); private ReportBuilder() { throw new IllegalAccessError("Do not instantiate this class."); } public static void saveAsHtml(Map<String, List<ReportItem>> reportItems) { for (Map.Entry<String,List<ReportItem>> entry : reportItems.entrySet()) { String ruleName = entry.getKey(); saveAsHtml(ruleName,entry.getValue()); } } public static void saveAsHtml(String ruleName, List<ReportItem> reportItemList) {
// Path: src/main/java/net/nandgr/cba/custom/visitor/helper/StringsHelper.java // public class StringsHelper { // // private static final String CLASS_SUFFIX = ".class"; // // private StringsHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // // public static String dotsToSlashes(String s) { // return s.replaceAll("\\.", "/"); // } // // public static String spacesToDashesLowercase(String s) { // return s.replaceAll(" ", "-").toLowerCase(); // } // // public static String simpleDescriptorToHuman(String s) { // String result = s; // if(result.startsWith("[")) { // result = result.substring(1, result.length()); // } // if (result.startsWith("L")) { // result = result.substring(1, result.length()); // } // if (result.endsWith(";")) { // result = result.substring(0, result.length()-1); // // } // return result; // } // // public static String removeClassSuffix(String s) { // if (s.endsWith(CLASS_SUFFIX)) { // return s.substring(0, s.length()-CLASS_SUFFIX.length()); // } // return s; // } // } // // Path: src/main/java/net/nandgr/cba/cli/CliHelper.java // public class CliHelper { // // private static CommandLineParser commandLineParser = new DefaultParser(); // private static CommandLine commandLine; // private static Rules rules; // // private CliHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // // public static void parseCliArguments(String[] args) throws ParseException { // commandLine = commandLineParser.parse(CliArguments.getOptions(), args); // } // // public static String getPathToAnalyze() { // return commandLine.getOptionValue("a"); // } // // public static int getMaxThreads() { // return Integer.parseInt(commandLine.getOptionValue("t", CliArguments.MAX_THREADS_DEFAULT)); // } // // public static boolean hasOutputDir() { // return commandLine.hasOption("o"); // } // // public static String getOutputDir() { // return commandLine.getOptionValue("o", CliArguments.OUTPUT_DEFAULT); // } // // public static boolean hasMaxItemsInReport() { // return commandLine.hasOption("i"); // } // // public static int getMaxItemsInReport() { // return Integer.parseInt(commandLine.getOptionValue("i", CliArguments.MAX_ITEMS_IN_REPORT_DEFAULT)); // } // // public static boolean hasChecks() { // return commandLine.hasOption("c"); // } // // public static String[] getChecks() { // return commandLine.getOptionValues("c"); // } // // public static boolean hasCustomFile() { // return commandLine.hasOption("f"); // } // // public static String getCustomFile() { // return commandLine.getOptionValue("f"); // } // // public static void printHelp() { // HelpFormatter helpFormatter = new HelpFormatter(); // helpFormatter.printHelp("java -jar cba-cli.jar [OPTIONS] -a DIRECTORY_TO_ANALYZE", CliArguments.getOptions()); // } // // public static boolean hasHelp() { // return commandLine.hasOption("h"); // } // // public static boolean hasVerboseDebug() { // return commandLine.hasOption("v"); // } // // public static boolean hasVerboseTrace() { // return commandLine.hasOption("vv"); // } // // public static Rules getRules() { // return rules; // } // // public static void setRules(Rules rules) { // CliHelper.rules = rules; // } // } // Path: src/main/java/net/nandgr/cba/report/ReportBuilder.java import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.collect.Lists; import java.io.StringWriter; import java.util.Properties; import net.nandgr.cba.custom.visitor.helper.StringsHelper; import net.nandgr.cba.cli.CliHelper; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.commons.io.FileUtils; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; /* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.report; public class ReportBuilder { private static final Logger logger = LoggerFactory.getLogger(ReportBuilder.class); private ReportBuilder() { throw new IllegalAccessError("Do not instantiate this class."); } public static void saveAsHtml(Map<String, List<ReportItem>> reportItems) { for (Map.Entry<String,List<ReportItem>> entry : reportItems.entrySet()) { String ruleName = entry.getKey(); saveAsHtml(ruleName,entry.getValue()); } } public static void saveAsHtml(String ruleName, List<ReportItem> reportItemList) {
File reportsDirectory = new File(CliHelper.getOutputDir());
fergarrui/custom-bytecode-analyzer
src/main/java/net/nandgr/cba/report/ReportBuilder.java
// Path: src/main/java/net/nandgr/cba/custom/visitor/helper/StringsHelper.java // public class StringsHelper { // // private static final String CLASS_SUFFIX = ".class"; // // private StringsHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // // public static String dotsToSlashes(String s) { // return s.replaceAll("\\.", "/"); // } // // public static String spacesToDashesLowercase(String s) { // return s.replaceAll(" ", "-").toLowerCase(); // } // // public static String simpleDescriptorToHuman(String s) { // String result = s; // if(result.startsWith("[")) { // result = result.substring(1, result.length()); // } // if (result.startsWith("L")) { // result = result.substring(1, result.length()); // } // if (result.endsWith(";")) { // result = result.substring(0, result.length()-1); // // } // return result; // } // // public static String removeClassSuffix(String s) { // if (s.endsWith(CLASS_SUFFIX)) { // return s.substring(0, s.length()-CLASS_SUFFIX.length()); // } // return s; // } // } // // Path: src/main/java/net/nandgr/cba/cli/CliHelper.java // public class CliHelper { // // private static CommandLineParser commandLineParser = new DefaultParser(); // private static CommandLine commandLine; // private static Rules rules; // // private CliHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // // public static void parseCliArguments(String[] args) throws ParseException { // commandLine = commandLineParser.parse(CliArguments.getOptions(), args); // } // // public static String getPathToAnalyze() { // return commandLine.getOptionValue("a"); // } // // public static int getMaxThreads() { // return Integer.parseInt(commandLine.getOptionValue("t", CliArguments.MAX_THREADS_DEFAULT)); // } // // public static boolean hasOutputDir() { // return commandLine.hasOption("o"); // } // // public static String getOutputDir() { // return commandLine.getOptionValue("o", CliArguments.OUTPUT_DEFAULT); // } // // public static boolean hasMaxItemsInReport() { // return commandLine.hasOption("i"); // } // // public static int getMaxItemsInReport() { // return Integer.parseInt(commandLine.getOptionValue("i", CliArguments.MAX_ITEMS_IN_REPORT_DEFAULT)); // } // // public static boolean hasChecks() { // return commandLine.hasOption("c"); // } // // public static String[] getChecks() { // return commandLine.getOptionValues("c"); // } // // public static boolean hasCustomFile() { // return commandLine.hasOption("f"); // } // // public static String getCustomFile() { // return commandLine.getOptionValue("f"); // } // // public static void printHelp() { // HelpFormatter helpFormatter = new HelpFormatter(); // helpFormatter.printHelp("java -jar cba-cli.jar [OPTIONS] -a DIRECTORY_TO_ANALYZE", CliArguments.getOptions()); // } // // public static boolean hasHelp() { // return commandLine.hasOption("h"); // } // // public static boolean hasVerboseDebug() { // return commandLine.hasOption("v"); // } // // public static boolean hasVerboseTrace() { // return commandLine.hasOption("vv"); // } // // public static Rules getRules() { // return rules; // } // // public static void setRules(Rules rules) { // CliHelper.rules = rules; // } // }
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.collect.Lists; import java.io.StringWriter; import java.util.Properties; import net.nandgr.cba.custom.visitor.helper.StringsHelper; import net.nandgr.cba.cli.CliHelper; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.commons.io.FileUtils; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine;
/* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.report; public class ReportBuilder { private static final Logger logger = LoggerFactory.getLogger(ReportBuilder.class); private ReportBuilder() { throw new IllegalAccessError("Do not instantiate this class."); } public static void saveAsHtml(Map<String, List<ReportItem>> reportItems) { for (Map.Entry<String,List<ReportItem>> entry : reportItems.entrySet()) { String ruleName = entry.getKey(); saveAsHtml(ruleName,entry.getValue()); } } public static void saveAsHtml(String ruleName, List<ReportItem> reportItemList) { File reportsDirectory = new File(CliHelper.getOutputDir()); if (!reportsDirectory.exists()) { reportsDirectory.mkdir(); } int reportFileIndex = 0; try { List<String> htmlChunks = generateHtmlChunks(reportItemList); for (String htmlChunk : htmlChunks) {
// Path: src/main/java/net/nandgr/cba/custom/visitor/helper/StringsHelper.java // public class StringsHelper { // // private static final String CLASS_SUFFIX = ".class"; // // private StringsHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // // public static String dotsToSlashes(String s) { // return s.replaceAll("\\.", "/"); // } // // public static String spacesToDashesLowercase(String s) { // return s.replaceAll(" ", "-").toLowerCase(); // } // // public static String simpleDescriptorToHuman(String s) { // String result = s; // if(result.startsWith("[")) { // result = result.substring(1, result.length()); // } // if (result.startsWith("L")) { // result = result.substring(1, result.length()); // } // if (result.endsWith(";")) { // result = result.substring(0, result.length()-1); // // } // return result; // } // // public static String removeClassSuffix(String s) { // if (s.endsWith(CLASS_SUFFIX)) { // return s.substring(0, s.length()-CLASS_SUFFIX.length()); // } // return s; // } // } // // Path: src/main/java/net/nandgr/cba/cli/CliHelper.java // public class CliHelper { // // private static CommandLineParser commandLineParser = new DefaultParser(); // private static CommandLine commandLine; // private static Rules rules; // // private CliHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // // public static void parseCliArguments(String[] args) throws ParseException { // commandLine = commandLineParser.parse(CliArguments.getOptions(), args); // } // // public static String getPathToAnalyze() { // return commandLine.getOptionValue("a"); // } // // public static int getMaxThreads() { // return Integer.parseInt(commandLine.getOptionValue("t", CliArguments.MAX_THREADS_DEFAULT)); // } // // public static boolean hasOutputDir() { // return commandLine.hasOption("o"); // } // // public static String getOutputDir() { // return commandLine.getOptionValue("o", CliArguments.OUTPUT_DEFAULT); // } // // public static boolean hasMaxItemsInReport() { // return commandLine.hasOption("i"); // } // // public static int getMaxItemsInReport() { // return Integer.parseInt(commandLine.getOptionValue("i", CliArguments.MAX_ITEMS_IN_REPORT_DEFAULT)); // } // // public static boolean hasChecks() { // return commandLine.hasOption("c"); // } // // public static String[] getChecks() { // return commandLine.getOptionValues("c"); // } // // public static boolean hasCustomFile() { // return commandLine.hasOption("f"); // } // // public static String getCustomFile() { // return commandLine.getOptionValue("f"); // } // // public static void printHelp() { // HelpFormatter helpFormatter = new HelpFormatter(); // helpFormatter.printHelp("java -jar cba-cli.jar [OPTIONS] -a DIRECTORY_TO_ANALYZE", CliArguments.getOptions()); // } // // public static boolean hasHelp() { // return commandLine.hasOption("h"); // } // // public static boolean hasVerboseDebug() { // return commandLine.hasOption("v"); // } // // public static boolean hasVerboseTrace() { // return commandLine.hasOption("vv"); // } // // public static Rules getRules() { // return rules; // } // // public static void setRules(Rules rules) { // CliHelper.rules = rules; // } // } // Path: src/main/java/net/nandgr/cba/report/ReportBuilder.java import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.collect.Lists; import java.io.StringWriter; import java.util.Properties; import net.nandgr.cba.custom.visitor.helper.StringsHelper; import net.nandgr.cba.cli.CliHelper; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.commons.io.FileUtils; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; /* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba.report; public class ReportBuilder { private static final Logger logger = LoggerFactory.getLogger(ReportBuilder.class); private ReportBuilder() { throw new IllegalAccessError("Do not instantiate this class."); } public static void saveAsHtml(Map<String, List<ReportItem>> reportItems) { for (Map.Entry<String,List<ReportItem>> entry : reportItems.entrySet()) { String ruleName = entry.getKey(); saveAsHtml(ruleName,entry.getValue()); } } public static void saveAsHtml(String ruleName, List<ReportItem> reportItemList) { File reportsDirectory = new File(CliHelper.getOutputDir()); if (!reportsDirectory.exists()) { reportsDirectory.mkdir(); } int reportFileIndex = 0; try { List<String> htmlChunks = generateHtmlChunks(reportItemList); for (String htmlChunk : htmlChunks) {
File reportFile = new File(reportsDirectory.getAbsolutePath() + "/" + StringsHelper.spacesToDashesLowercase(ruleName) + "-"+ reportFileIndex +".html");
fergarrui/custom-bytecode-analyzer
src/test/java/rules/FieldsTest.java
// Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // }
import java.util.List; import java.util.stream.Collectors; import net.nandgr.cba.report.ReportItem; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import org.junit.Test;
package rules; public class FieldsTest extends AbstractTest { public FieldsTest() { super("fields"); } @Test public void test() { runTests();
// Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // } // Path: src/test/java/rules/FieldsTest.java import java.util.List; import java.util.stream.Collectors; import net.nandgr.cba.report.ReportItem; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import org.junit.Test; package rules; public class FieldsTest extends AbstractTest { public FieldsTest() { super("fields"); } @Test public void test() { runTests();
List<ReportItem> reportItems1 = getReportItems("fields1");
fergarrui/custom-bytecode-analyzer
src/main/java/net/nandgr/cba/decompile/ZipEntryDecompiler.java
// Path: src/main/java/net/nandgr/cba/cli/CliHelper.java // public class CliHelper { // // private static CommandLineParser commandLineParser = new DefaultParser(); // private static CommandLine commandLine; // private static Rules rules; // // private CliHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // // public static void parseCliArguments(String[] args) throws ParseException { // commandLine = commandLineParser.parse(CliArguments.getOptions(), args); // } // // public static String getPathToAnalyze() { // return commandLine.getOptionValue("a"); // } // // public static int getMaxThreads() { // return Integer.parseInt(commandLine.getOptionValue("t", CliArguments.MAX_THREADS_DEFAULT)); // } // // public static boolean hasOutputDir() { // return commandLine.hasOption("o"); // } // // public static String getOutputDir() { // return commandLine.getOptionValue("o", CliArguments.OUTPUT_DEFAULT); // } // // public static boolean hasMaxItemsInReport() { // return commandLine.hasOption("i"); // } // // public static int getMaxItemsInReport() { // return Integer.parseInt(commandLine.getOptionValue("i", CliArguments.MAX_ITEMS_IN_REPORT_DEFAULT)); // } // // public static boolean hasChecks() { // return commandLine.hasOption("c"); // } // // public static String[] getChecks() { // return commandLine.getOptionValues("c"); // } // // public static boolean hasCustomFile() { // return commandLine.hasOption("f"); // } // // public static String getCustomFile() { // return commandLine.getOptionValue("f"); // } // // public static void printHelp() { // HelpFormatter helpFormatter = new HelpFormatter(); // helpFormatter.printHelp("java -jar cba-cli.jar [OPTIONS] -a DIRECTORY_TO_ANALYZE", CliArguments.getOptions()); // } // // public static boolean hasHelp() { // return commandLine.hasOption("h"); // } // // public static boolean hasVerboseDebug() { // return commandLine.hasOption("v"); // } // // public static boolean hasVerboseTrace() { // return commandLine.hasOption("vv"); // } // // public static Rules getRules() { // return rules; // } // // public static void setRules(Rules rules) { // CliHelper.rules = rules; // } // }
import com.strobel.decompiler.PlainTextOutput; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.StringWriter; import net.nandgr.cba.cli.CliHelper; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
File decompiledFile = new File(decompiledFileName); decompiledFile.getParentFile().mkdirs(); StringWriter pw = new StringWriter(); try { com.strobel.decompiler.Decompiler.decompile(tempFile.getAbsolutePath(), new PlainTextOutput(pw)); } catch (Exception e) { logger.info("Error while decompiling {}. " , entryName); throw e; } pw.flush(); String decompiledFileContent = pw.toString(); FileUtils.writeStringToFile(decompiledFile, decompiledFileContent); return decompiledFileContent; } private static File createTempFile(String entryName, InputStream inputStream) throws IOException { byte[] inputStreamBytes = IOUtils.toByteArray(inputStream); InputStream byteArrayInputStream = new ByteArrayInputStream(inputStreamBytes); String prefix = entryName.replaceAll(File.separator, "."); final File tempFile = File.createTempFile(prefix, ".class"); FileOutputStream outputStream = new FileOutputStream(tempFile); int copiedBytes = IOUtils.copy(byteArrayInputStream, outputStream); logger.debug("Copied {} bytes to a temp file.", copiedBytes); return tempFile; } private static String getDecompiledFileName(String entryName) {
// Path: src/main/java/net/nandgr/cba/cli/CliHelper.java // public class CliHelper { // // private static CommandLineParser commandLineParser = new DefaultParser(); // private static CommandLine commandLine; // private static Rules rules; // // private CliHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // // public static void parseCliArguments(String[] args) throws ParseException { // commandLine = commandLineParser.parse(CliArguments.getOptions(), args); // } // // public static String getPathToAnalyze() { // return commandLine.getOptionValue("a"); // } // // public static int getMaxThreads() { // return Integer.parseInt(commandLine.getOptionValue("t", CliArguments.MAX_THREADS_DEFAULT)); // } // // public static boolean hasOutputDir() { // return commandLine.hasOption("o"); // } // // public static String getOutputDir() { // return commandLine.getOptionValue("o", CliArguments.OUTPUT_DEFAULT); // } // // public static boolean hasMaxItemsInReport() { // return commandLine.hasOption("i"); // } // // public static int getMaxItemsInReport() { // return Integer.parseInt(commandLine.getOptionValue("i", CliArguments.MAX_ITEMS_IN_REPORT_DEFAULT)); // } // // public static boolean hasChecks() { // return commandLine.hasOption("c"); // } // // public static String[] getChecks() { // return commandLine.getOptionValues("c"); // } // // public static boolean hasCustomFile() { // return commandLine.hasOption("f"); // } // // public static String getCustomFile() { // return commandLine.getOptionValue("f"); // } // // public static void printHelp() { // HelpFormatter helpFormatter = new HelpFormatter(); // helpFormatter.printHelp("java -jar cba-cli.jar [OPTIONS] -a DIRECTORY_TO_ANALYZE", CliArguments.getOptions()); // } // // public static boolean hasHelp() { // return commandLine.hasOption("h"); // } // // public static boolean hasVerboseDebug() { // return commandLine.hasOption("v"); // } // // public static boolean hasVerboseTrace() { // return commandLine.hasOption("vv"); // } // // public static Rules getRules() { // return rules; // } // // public static void setRules(Rules rules) { // CliHelper.rules = rules; // } // } // Path: src/main/java/net/nandgr/cba/decompile/ZipEntryDecompiler.java import com.strobel.decompiler.PlainTextOutput; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.StringWriter; import net.nandgr.cba.cli.CliHelper; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; File decompiledFile = new File(decompiledFileName); decompiledFile.getParentFile().mkdirs(); StringWriter pw = new StringWriter(); try { com.strobel.decompiler.Decompiler.decompile(tempFile.getAbsolutePath(), new PlainTextOutput(pw)); } catch (Exception e) { logger.info("Error while decompiling {}. " , entryName); throw e; } pw.flush(); String decompiledFileContent = pw.toString(); FileUtils.writeStringToFile(decompiledFile, decompiledFileContent); return decompiledFileContent; } private static File createTempFile(String entryName, InputStream inputStream) throws IOException { byte[] inputStreamBytes = IOUtils.toByteArray(inputStream); InputStream byteArrayInputStream = new ByteArrayInputStream(inputStreamBytes); String prefix = entryName.replaceAll(File.separator, "."); final File tempFile = File.createTempFile(prefix, ".class"); FileOutputStream outputStream = new FileOutputStream(tempFile); int copiedBytes = IOUtils.copy(byteArrayInputStream, outputStream); logger.debug("Copied {} bytes to a temp file.", copiedBytes); return tempFile; } private static String getDecompiledFileName(String entryName) {
String outputDir = CliHelper.getOutputDir();
fergarrui/custom-bytecode-analyzer
src/main/java/net/nandgr/cba/ByteCodeAnalyzer.java
// Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // }
import net.nandgr.cba.report.ReportItem; import java.util.List; import org.objectweb.asm.tree.ClassNode;
/* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba; @FunctionalInterface public interface ByteCodeAnalyzer {
// Path: src/main/java/net/nandgr/cba/report/ReportItem.java // public class ReportItem { // // private String jarPath = ""; // private String className = ""; // private String decompiledFile; // private final String ruleName; // private final boolean showInReport; // private Map<String,String> properties = new HashMap<>(); // // public ReportItem(String ruleName, boolean showInReport) { // this.ruleName = ruleName; // this.showInReport = showInReport; // } // // public String getJarPath() { // return jarPath; // } // // public String getClassName() { // return className; // } // // public String getRuleName() { // return ruleName; // } // // public void setJarPath(String jarPath) { // this.jarPath = jarPath; // } // // public void setClassName(String className) { // this.className = className; // } // // public boolean isShowInReport() { // return showInReport; // } // // public String getDecompiledFile() { // return decompiledFile; // } // // public String getDecompiledFileHtml() { // return StringEscapeUtils.escapeHtml(decompiledFile); // } // // public Map<String, String> getProperties() { // return properties; // } // // public ReportItem addProperty(String propertyName, String propertyValue) { // properties.put(propertyName, propertyValue); // return this; // } // // public void setDecompiledFile(String decompiledFile) { // this.decompiledFile = decompiledFile; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ReportItem)) return false; // // ReportItem that = (ReportItem) o; // // if (isShowInReport() != that.isShowInReport()) return false; // if (getJarPath() != null ? !getJarPath().equals(that.getJarPath()) : that.getJarPath() != null) return false; // if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) // return false; // if (getDecompiledFile() != null ? !getDecompiledFile().equals(that.getDecompiledFile()) : that.getDecompiledFile() != null) // return false; // if (getRuleName() != null ? !getRuleName().equals(that.getRuleName()) : that.getRuleName() != null) return false; // return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; // } // // @Override // public int hashCode() { // int result = getJarPath() != null ? getJarPath().hashCode() : 0; // result = 31 * result + (getClassName() != null ? getClassName().hashCode() : 0); // result = 31 * result + (getDecompiledFile() != null ? getDecompiledFile().hashCode() : 0); // result = 31 * result + (getRuleName() != null ? getRuleName().hashCode() : 0); // result = 31 * result + (isShowInReport() ? 1 : 0); // result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); // return result; // } // } // Path: src/main/java/net/nandgr/cba/ByteCodeAnalyzer.java import net.nandgr.cba.report.ReportItem; import java.util.List; import org.objectweb.asm.tree.ClassNode; /* * Copyright (c) 2016-2017, Fernando Garcia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.nandgr.cba; @FunctionalInterface public interface ByteCodeAnalyzer {
List<ReportItem> analyze(ClassNode classNode);
fergarrui/custom-bytecode-analyzer
src/main/java/net/nandgr/cba/cli/CliArguments.java
// Path: src/main/java/net/nandgr/cba/custom/model/Rules.java // public class Rules { // // private List<Rule> rules; // // public List<Rule> getRules() { // return rules; // } // // public void setRules(List<Rule> rules) { // this.rules = rules; // } // // @Override // public String toString() { // return "Rules{" + // "rules=" + Arrays.toString(rules.toArray()) + // '}'; // } // // public void validateRules() throws BadRulesException { // for (Rule rule : this.getRules()) { // if (StringUtils.isBlank(rule.getName())) { // throw new BadRulesException("Rule name cannot be blank."); // } // validateRule(rule); // } // } // // private static void validateRule(Rule rule) throws BadRulesException { // if (rule.getInvocations() != null) { // for (Invocation invocation : rule.getInvocations()) { // // Method notFrom = invocation.getNotFrom(); // checkEmpty(notFrom, "\"invocation.notFrom\" property cannot have all the fields blank."); // // Method from = invocation.getFrom(); // checkEmpty(from, "\"invocation.from\" property cannot have all the fields blank."); // // Method method = invocation.getMethod(); // checkEmpty(method, "\"invocation.method\" property cannot have all the fields blank."); // // if (notFrom != null && from != null) { // throw new BadRulesException("\"invocation.notFrom\" and \"invocation.from\" cannot be defined at the same time in the same rule."); // } // } // } // } // // private static void checkEmpty(Method method, String message) throws BadRulesException { // if (allEmpty(method)) { // throw new BadRulesException(message); // } // } // } // // Path: src/main/java/net/nandgr/cba/exception/BadArgumentsException.java // public class BadArgumentsException extends Exception { // // public BadArgumentsException(String message) { // super(message); // } // // public BadArgumentsException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/net/nandgr/cba/exception/BadRulesException.java // public class BadRulesException extends Exception { // // public BadRulesException(String message) { // super(message); // } // } // // Path: src/main/java/net/nandgr/cba/logging/LogHelper.java // public class LogHelper { // // private LogHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // public static void toDebug() { // Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); // root.setLevel(Level.DEBUG); // } // // public static void toTrace() { // Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); // root.setLevel(Level.TRACE); // } // }
import com.google.gson.Gson; import java.io.File; import java.io.IOException; import net.nandgr.cba.custom.model.Rules; import net.nandgr.cba.exception.BadArgumentsException; import net.nandgr.cba.exception.BadRulesException; import net.nandgr.cba.logging.LogHelper; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
Option verboseDebug = Option .builder("v") .longOpt("verbose-debug") .desc("Increase verbosity to debug mode.") .build(); Option verboseTrace = Option .builder("vv") .longOpt("verbose-trace") .desc("Increase verbosity to trace mode - makes it slower, use it only when you need.") .build(); options.addOption(help); options.addOption(path); /* disabled until thread safety is done properly. options.addOption(maxThreads); */ options.addOption(maxReportItems); options.addOption(output); options.addOption(checks); options.addOption(customFile); options.addOption(verboseDebug); options.addOption(verboseTrace); } public static Options getOptions() { return options; }
// Path: src/main/java/net/nandgr/cba/custom/model/Rules.java // public class Rules { // // private List<Rule> rules; // // public List<Rule> getRules() { // return rules; // } // // public void setRules(List<Rule> rules) { // this.rules = rules; // } // // @Override // public String toString() { // return "Rules{" + // "rules=" + Arrays.toString(rules.toArray()) + // '}'; // } // // public void validateRules() throws BadRulesException { // for (Rule rule : this.getRules()) { // if (StringUtils.isBlank(rule.getName())) { // throw new BadRulesException("Rule name cannot be blank."); // } // validateRule(rule); // } // } // // private static void validateRule(Rule rule) throws BadRulesException { // if (rule.getInvocations() != null) { // for (Invocation invocation : rule.getInvocations()) { // // Method notFrom = invocation.getNotFrom(); // checkEmpty(notFrom, "\"invocation.notFrom\" property cannot have all the fields blank."); // // Method from = invocation.getFrom(); // checkEmpty(from, "\"invocation.from\" property cannot have all the fields blank."); // // Method method = invocation.getMethod(); // checkEmpty(method, "\"invocation.method\" property cannot have all the fields blank."); // // if (notFrom != null && from != null) { // throw new BadRulesException("\"invocation.notFrom\" and \"invocation.from\" cannot be defined at the same time in the same rule."); // } // } // } // } // // private static void checkEmpty(Method method, String message) throws BadRulesException { // if (allEmpty(method)) { // throw new BadRulesException(message); // } // } // } // // Path: src/main/java/net/nandgr/cba/exception/BadArgumentsException.java // public class BadArgumentsException extends Exception { // // public BadArgumentsException(String message) { // super(message); // } // // public BadArgumentsException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/net/nandgr/cba/exception/BadRulesException.java // public class BadRulesException extends Exception { // // public BadRulesException(String message) { // super(message); // } // } // // Path: src/main/java/net/nandgr/cba/logging/LogHelper.java // public class LogHelper { // // private LogHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // public static void toDebug() { // Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); // root.setLevel(Level.DEBUG); // } // // public static void toTrace() { // Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); // root.setLevel(Level.TRACE); // } // } // Path: src/main/java/net/nandgr/cba/cli/CliArguments.java import com.google.gson.Gson; import java.io.File; import java.io.IOException; import net.nandgr.cba.custom.model.Rules; import net.nandgr.cba.exception.BadArgumentsException; import net.nandgr.cba.exception.BadRulesException; import net.nandgr.cba.logging.LogHelper; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; Option verboseDebug = Option .builder("v") .longOpt("verbose-debug") .desc("Increase verbosity to debug mode.") .build(); Option verboseTrace = Option .builder("vv") .longOpt("verbose-trace") .desc("Increase verbosity to trace mode - makes it slower, use it only when you need.") .build(); options.addOption(help); options.addOption(path); /* disabled until thread safety is done properly. options.addOption(maxThreads); */ options.addOption(maxReportItems); options.addOption(output); options.addOption(checks); options.addOption(customFile); options.addOption(verboseDebug); options.addOption(verboseTrace); } public static Options getOptions() { return options; }
public static void parseArguments(String[] args) throws BadArgumentsException {
fergarrui/custom-bytecode-analyzer
src/main/java/net/nandgr/cba/cli/CliArguments.java
// Path: src/main/java/net/nandgr/cba/custom/model/Rules.java // public class Rules { // // private List<Rule> rules; // // public List<Rule> getRules() { // return rules; // } // // public void setRules(List<Rule> rules) { // this.rules = rules; // } // // @Override // public String toString() { // return "Rules{" + // "rules=" + Arrays.toString(rules.toArray()) + // '}'; // } // // public void validateRules() throws BadRulesException { // for (Rule rule : this.getRules()) { // if (StringUtils.isBlank(rule.getName())) { // throw new BadRulesException("Rule name cannot be blank."); // } // validateRule(rule); // } // } // // private static void validateRule(Rule rule) throws BadRulesException { // if (rule.getInvocations() != null) { // for (Invocation invocation : rule.getInvocations()) { // // Method notFrom = invocation.getNotFrom(); // checkEmpty(notFrom, "\"invocation.notFrom\" property cannot have all the fields blank."); // // Method from = invocation.getFrom(); // checkEmpty(from, "\"invocation.from\" property cannot have all the fields blank."); // // Method method = invocation.getMethod(); // checkEmpty(method, "\"invocation.method\" property cannot have all the fields blank."); // // if (notFrom != null && from != null) { // throw new BadRulesException("\"invocation.notFrom\" and \"invocation.from\" cannot be defined at the same time in the same rule."); // } // } // } // } // // private static void checkEmpty(Method method, String message) throws BadRulesException { // if (allEmpty(method)) { // throw new BadRulesException(message); // } // } // } // // Path: src/main/java/net/nandgr/cba/exception/BadArgumentsException.java // public class BadArgumentsException extends Exception { // // public BadArgumentsException(String message) { // super(message); // } // // public BadArgumentsException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/net/nandgr/cba/exception/BadRulesException.java // public class BadRulesException extends Exception { // // public BadRulesException(String message) { // super(message); // } // } // // Path: src/main/java/net/nandgr/cba/logging/LogHelper.java // public class LogHelper { // // private LogHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // public static void toDebug() { // Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); // root.setLevel(Level.DEBUG); // } // // public static void toTrace() { // Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); // root.setLevel(Level.TRACE); // } // }
import com.google.gson.Gson; import java.io.File; import java.io.IOException; import net.nandgr.cba.custom.model.Rules; import net.nandgr.cba.exception.BadArgumentsException; import net.nandgr.cba.exception.BadRulesException; import net.nandgr.cba.logging.LogHelper; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
disabled until thread safety is done properly. options.addOption(maxThreads); */ options.addOption(maxReportItems); options.addOption(output); options.addOption(checks); options.addOption(customFile); options.addOption(verboseDebug); options.addOption(verboseTrace); } public static Options getOptions() { return options; } public static void parseArguments(String[] args) throws BadArgumentsException { try { CliHelper.parseCliArguments(args); } catch (ParseException e) { throw new BadArgumentsException("Error while parsing arguments", e); } CliArguments.validateArguments(); if (CliHelper.hasHelp()) { CliHelper.printHelp(); System.exit(1); } if (CliHelper.hasVerboseDebug()) { logger.info("Setting logger to DEBUG mode.");
// Path: src/main/java/net/nandgr/cba/custom/model/Rules.java // public class Rules { // // private List<Rule> rules; // // public List<Rule> getRules() { // return rules; // } // // public void setRules(List<Rule> rules) { // this.rules = rules; // } // // @Override // public String toString() { // return "Rules{" + // "rules=" + Arrays.toString(rules.toArray()) + // '}'; // } // // public void validateRules() throws BadRulesException { // for (Rule rule : this.getRules()) { // if (StringUtils.isBlank(rule.getName())) { // throw new BadRulesException("Rule name cannot be blank."); // } // validateRule(rule); // } // } // // private static void validateRule(Rule rule) throws BadRulesException { // if (rule.getInvocations() != null) { // for (Invocation invocation : rule.getInvocations()) { // // Method notFrom = invocation.getNotFrom(); // checkEmpty(notFrom, "\"invocation.notFrom\" property cannot have all the fields blank."); // // Method from = invocation.getFrom(); // checkEmpty(from, "\"invocation.from\" property cannot have all the fields blank."); // // Method method = invocation.getMethod(); // checkEmpty(method, "\"invocation.method\" property cannot have all the fields blank."); // // if (notFrom != null && from != null) { // throw new BadRulesException("\"invocation.notFrom\" and \"invocation.from\" cannot be defined at the same time in the same rule."); // } // } // } // } // // private static void checkEmpty(Method method, String message) throws BadRulesException { // if (allEmpty(method)) { // throw new BadRulesException(message); // } // } // } // // Path: src/main/java/net/nandgr/cba/exception/BadArgumentsException.java // public class BadArgumentsException extends Exception { // // public BadArgumentsException(String message) { // super(message); // } // // public BadArgumentsException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/net/nandgr/cba/exception/BadRulesException.java // public class BadRulesException extends Exception { // // public BadRulesException(String message) { // super(message); // } // } // // Path: src/main/java/net/nandgr/cba/logging/LogHelper.java // public class LogHelper { // // private LogHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // public static void toDebug() { // Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); // root.setLevel(Level.DEBUG); // } // // public static void toTrace() { // Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); // root.setLevel(Level.TRACE); // } // } // Path: src/main/java/net/nandgr/cba/cli/CliArguments.java import com.google.gson.Gson; import java.io.File; import java.io.IOException; import net.nandgr.cba.custom.model.Rules; import net.nandgr.cba.exception.BadArgumentsException; import net.nandgr.cba.exception.BadRulesException; import net.nandgr.cba.logging.LogHelper; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; disabled until thread safety is done properly. options.addOption(maxThreads); */ options.addOption(maxReportItems); options.addOption(output); options.addOption(checks); options.addOption(customFile); options.addOption(verboseDebug); options.addOption(verboseTrace); } public static Options getOptions() { return options; } public static void parseArguments(String[] args) throws BadArgumentsException { try { CliHelper.parseCliArguments(args); } catch (ParseException e) { throw new BadArgumentsException("Error while parsing arguments", e); } CliArguments.validateArguments(); if (CliHelper.hasHelp()) { CliHelper.printHelp(); System.exit(1); } if (CliHelper.hasVerboseDebug()) { logger.info("Setting logger to DEBUG mode.");
LogHelper.toDebug();
fergarrui/custom-bytecode-analyzer
src/main/java/net/nandgr/cba/cli/CliArguments.java
// Path: src/main/java/net/nandgr/cba/custom/model/Rules.java // public class Rules { // // private List<Rule> rules; // // public List<Rule> getRules() { // return rules; // } // // public void setRules(List<Rule> rules) { // this.rules = rules; // } // // @Override // public String toString() { // return "Rules{" + // "rules=" + Arrays.toString(rules.toArray()) + // '}'; // } // // public void validateRules() throws BadRulesException { // for (Rule rule : this.getRules()) { // if (StringUtils.isBlank(rule.getName())) { // throw new BadRulesException("Rule name cannot be blank."); // } // validateRule(rule); // } // } // // private static void validateRule(Rule rule) throws BadRulesException { // if (rule.getInvocations() != null) { // for (Invocation invocation : rule.getInvocations()) { // // Method notFrom = invocation.getNotFrom(); // checkEmpty(notFrom, "\"invocation.notFrom\" property cannot have all the fields blank."); // // Method from = invocation.getFrom(); // checkEmpty(from, "\"invocation.from\" property cannot have all the fields blank."); // // Method method = invocation.getMethod(); // checkEmpty(method, "\"invocation.method\" property cannot have all the fields blank."); // // if (notFrom != null && from != null) { // throw new BadRulesException("\"invocation.notFrom\" and \"invocation.from\" cannot be defined at the same time in the same rule."); // } // } // } // } // // private static void checkEmpty(Method method, String message) throws BadRulesException { // if (allEmpty(method)) { // throw new BadRulesException(message); // } // } // } // // Path: src/main/java/net/nandgr/cba/exception/BadArgumentsException.java // public class BadArgumentsException extends Exception { // // public BadArgumentsException(String message) { // super(message); // } // // public BadArgumentsException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/net/nandgr/cba/exception/BadRulesException.java // public class BadRulesException extends Exception { // // public BadRulesException(String message) { // super(message); // } // } // // Path: src/main/java/net/nandgr/cba/logging/LogHelper.java // public class LogHelper { // // private LogHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // public static void toDebug() { // Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); // root.setLevel(Level.DEBUG); // } // // public static void toTrace() { // Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); // root.setLevel(Level.TRACE); // } // }
import com.google.gson.Gson; import java.io.File; import java.io.IOException; import net.nandgr.cba.custom.model.Rules; import net.nandgr.cba.exception.BadArgumentsException; import net.nandgr.cba.exception.BadRulesException; import net.nandgr.cba.logging.LogHelper; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
try { CliHelper.parseCliArguments(args); } catch (ParseException e) { throw new BadArgumentsException("Error while parsing arguments", e); } CliArguments.validateArguments(); if (CliHelper.hasHelp()) { CliHelper.printHelp(); System.exit(1); } if (CliHelper.hasVerboseDebug()) { logger.info("Setting logger to DEBUG mode."); LogHelper.toDebug(); } if (CliHelper.hasVerboseTrace()) { logger.info("Setting logger to TRACE mode."); LogHelper.toTrace(); } if (CliHelper.hasCustomFile()) { String customFilePath = CliHelper.getCustomFile(); File customFile = new File(customFilePath); String json = null; try { json = FileUtils.readFileToString(customFile); } catch (IOException e) { throw new BadArgumentsException("Error with provided custom file", e); } Gson gson = new Gson();
// Path: src/main/java/net/nandgr/cba/custom/model/Rules.java // public class Rules { // // private List<Rule> rules; // // public List<Rule> getRules() { // return rules; // } // // public void setRules(List<Rule> rules) { // this.rules = rules; // } // // @Override // public String toString() { // return "Rules{" + // "rules=" + Arrays.toString(rules.toArray()) + // '}'; // } // // public void validateRules() throws BadRulesException { // for (Rule rule : this.getRules()) { // if (StringUtils.isBlank(rule.getName())) { // throw new BadRulesException("Rule name cannot be blank."); // } // validateRule(rule); // } // } // // private static void validateRule(Rule rule) throws BadRulesException { // if (rule.getInvocations() != null) { // for (Invocation invocation : rule.getInvocations()) { // // Method notFrom = invocation.getNotFrom(); // checkEmpty(notFrom, "\"invocation.notFrom\" property cannot have all the fields blank."); // // Method from = invocation.getFrom(); // checkEmpty(from, "\"invocation.from\" property cannot have all the fields blank."); // // Method method = invocation.getMethod(); // checkEmpty(method, "\"invocation.method\" property cannot have all the fields blank."); // // if (notFrom != null && from != null) { // throw new BadRulesException("\"invocation.notFrom\" and \"invocation.from\" cannot be defined at the same time in the same rule."); // } // } // } // } // // private static void checkEmpty(Method method, String message) throws BadRulesException { // if (allEmpty(method)) { // throw new BadRulesException(message); // } // } // } // // Path: src/main/java/net/nandgr/cba/exception/BadArgumentsException.java // public class BadArgumentsException extends Exception { // // public BadArgumentsException(String message) { // super(message); // } // // public BadArgumentsException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/net/nandgr/cba/exception/BadRulesException.java // public class BadRulesException extends Exception { // // public BadRulesException(String message) { // super(message); // } // } // // Path: src/main/java/net/nandgr/cba/logging/LogHelper.java // public class LogHelper { // // private LogHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // public static void toDebug() { // Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); // root.setLevel(Level.DEBUG); // } // // public static void toTrace() { // Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); // root.setLevel(Level.TRACE); // } // } // Path: src/main/java/net/nandgr/cba/cli/CliArguments.java import com.google.gson.Gson; import java.io.File; import java.io.IOException; import net.nandgr.cba.custom.model.Rules; import net.nandgr.cba.exception.BadArgumentsException; import net.nandgr.cba.exception.BadRulesException; import net.nandgr.cba.logging.LogHelper; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; try { CliHelper.parseCliArguments(args); } catch (ParseException e) { throw new BadArgumentsException("Error while parsing arguments", e); } CliArguments.validateArguments(); if (CliHelper.hasHelp()) { CliHelper.printHelp(); System.exit(1); } if (CliHelper.hasVerboseDebug()) { logger.info("Setting logger to DEBUG mode."); LogHelper.toDebug(); } if (CliHelper.hasVerboseTrace()) { logger.info("Setting logger to TRACE mode."); LogHelper.toTrace(); } if (CliHelper.hasCustomFile()) { String customFilePath = CliHelper.getCustomFile(); File customFile = new File(customFilePath); String json = null; try { json = FileUtils.readFileToString(customFile); } catch (IOException e) { throw new BadArgumentsException("Error with provided custom file", e); } Gson gson = new Gson();
Rules rules = gson.fromJson(json, Rules.class);
fergarrui/custom-bytecode-analyzer
src/main/java/net/nandgr/cba/cli/CliArguments.java
// Path: src/main/java/net/nandgr/cba/custom/model/Rules.java // public class Rules { // // private List<Rule> rules; // // public List<Rule> getRules() { // return rules; // } // // public void setRules(List<Rule> rules) { // this.rules = rules; // } // // @Override // public String toString() { // return "Rules{" + // "rules=" + Arrays.toString(rules.toArray()) + // '}'; // } // // public void validateRules() throws BadRulesException { // for (Rule rule : this.getRules()) { // if (StringUtils.isBlank(rule.getName())) { // throw new BadRulesException("Rule name cannot be blank."); // } // validateRule(rule); // } // } // // private static void validateRule(Rule rule) throws BadRulesException { // if (rule.getInvocations() != null) { // for (Invocation invocation : rule.getInvocations()) { // // Method notFrom = invocation.getNotFrom(); // checkEmpty(notFrom, "\"invocation.notFrom\" property cannot have all the fields blank."); // // Method from = invocation.getFrom(); // checkEmpty(from, "\"invocation.from\" property cannot have all the fields blank."); // // Method method = invocation.getMethod(); // checkEmpty(method, "\"invocation.method\" property cannot have all the fields blank."); // // if (notFrom != null && from != null) { // throw new BadRulesException("\"invocation.notFrom\" and \"invocation.from\" cannot be defined at the same time in the same rule."); // } // } // } // } // // private static void checkEmpty(Method method, String message) throws BadRulesException { // if (allEmpty(method)) { // throw new BadRulesException(message); // } // } // } // // Path: src/main/java/net/nandgr/cba/exception/BadArgumentsException.java // public class BadArgumentsException extends Exception { // // public BadArgumentsException(String message) { // super(message); // } // // public BadArgumentsException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/net/nandgr/cba/exception/BadRulesException.java // public class BadRulesException extends Exception { // // public BadRulesException(String message) { // super(message); // } // } // // Path: src/main/java/net/nandgr/cba/logging/LogHelper.java // public class LogHelper { // // private LogHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // public static void toDebug() { // Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); // root.setLevel(Level.DEBUG); // } // // public static void toTrace() { // Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); // root.setLevel(Level.TRACE); // } // }
import com.google.gson.Gson; import java.io.File; import java.io.IOException; import net.nandgr.cba.custom.model.Rules; import net.nandgr.cba.exception.BadArgumentsException; import net.nandgr.cba.exception.BadRulesException; import net.nandgr.cba.logging.LogHelper; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
throw new BadArgumentsException("Error while parsing arguments", e); } CliArguments.validateArguments(); if (CliHelper.hasHelp()) { CliHelper.printHelp(); System.exit(1); } if (CliHelper.hasVerboseDebug()) { logger.info("Setting logger to DEBUG mode."); LogHelper.toDebug(); } if (CliHelper.hasVerboseTrace()) { logger.info("Setting logger to TRACE mode."); LogHelper.toTrace(); } if (CliHelper.hasCustomFile()) { String customFilePath = CliHelper.getCustomFile(); File customFile = new File(customFilePath); String json = null; try { json = FileUtils.readFileToString(customFile); } catch (IOException e) { throw new BadArgumentsException("Error with provided custom file", e); } Gson gson = new Gson(); Rules rules = gson.fromJson(json, Rules.class); try { rules.validateRules();
// Path: src/main/java/net/nandgr/cba/custom/model/Rules.java // public class Rules { // // private List<Rule> rules; // // public List<Rule> getRules() { // return rules; // } // // public void setRules(List<Rule> rules) { // this.rules = rules; // } // // @Override // public String toString() { // return "Rules{" + // "rules=" + Arrays.toString(rules.toArray()) + // '}'; // } // // public void validateRules() throws BadRulesException { // for (Rule rule : this.getRules()) { // if (StringUtils.isBlank(rule.getName())) { // throw new BadRulesException("Rule name cannot be blank."); // } // validateRule(rule); // } // } // // private static void validateRule(Rule rule) throws BadRulesException { // if (rule.getInvocations() != null) { // for (Invocation invocation : rule.getInvocations()) { // // Method notFrom = invocation.getNotFrom(); // checkEmpty(notFrom, "\"invocation.notFrom\" property cannot have all the fields blank."); // // Method from = invocation.getFrom(); // checkEmpty(from, "\"invocation.from\" property cannot have all the fields blank."); // // Method method = invocation.getMethod(); // checkEmpty(method, "\"invocation.method\" property cannot have all the fields blank."); // // if (notFrom != null && from != null) { // throw new BadRulesException("\"invocation.notFrom\" and \"invocation.from\" cannot be defined at the same time in the same rule."); // } // } // } // } // // private static void checkEmpty(Method method, String message) throws BadRulesException { // if (allEmpty(method)) { // throw new BadRulesException(message); // } // } // } // // Path: src/main/java/net/nandgr/cba/exception/BadArgumentsException.java // public class BadArgumentsException extends Exception { // // public BadArgumentsException(String message) { // super(message); // } // // public BadArgumentsException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/net/nandgr/cba/exception/BadRulesException.java // public class BadRulesException extends Exception { // // public BadRulesException(String message) { // super(message); // } // } // // Path: src/main/java/net/nandgr/cba/logging/LogHelper.java // public class LogHelper { // // private LogHelper() { // throw new IllegalAccessError("Cannot instantiate this utility class."); // } // public static void toDebug() { // Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); // root.setLevel(Level.DEBUG); // } // // public static void toTrace() { // Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); // root.setLevel(Level.TRACE); // } // } // Path: src/main/java/net/nandgr/cba/cli/CliArguments.java import com.google.gson.Gson; import java.io.File; import java.io.IOException; import net.nandgr.cba.custom.model.Rules; import net.nandgr.cba.exception.BadArgumentsException; import net.nandgr.cba.exception.BadRulesException; import net.nandgr.cba.logging.LogHelper; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; throw new BadArgumentsException("Error while parsing arguments", e); } CliArguments.validateArguments(); if (CliHelper.hasHelp()) { CliHelper.printHelp(); System.exit(1); } if (CliHelper.hasVerboseDebug()) { logger.info("Setting logger to DEBUG mode."); LogHelper.toDebug(); } if (CliHelper.hasVerboseTrace()) { logger.info("Setting logger to TRACE mode."); LogHelper.toTrace(); } if (CliHelper.hasCustomFile()) { String customFilePath = CliHelper.getCustomFile(); File customFile = new File(customFilePath); String json = null; try { json = FileUtils.readFileToString(customFile); } catch (IOException e) { throw new BadArgumentsException("Error with provided custom file", e); } Gson gson = new Gson(); Rules rules = gson.fromJson(json, Rules.class); try { rules.validateRules();
} catch (BadRulesException e) {
kmizu/yapp
benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappOptimizedXMLRecognizer.java
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // }
import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.OptimizedXMLParser; import com.github.kmizu.yapp.benchmark.parser.XMLParser; import com.github.kmizu.yapp.runtime.Result;
package com.github.kmizu.yapp.benchmark; public class YappOptimizedXMLRecognizer implements GenericParser<Object> { private OptimizedXMLParser recognizer; public void setInput(Reader input) { recognizer = new OptimizedXMLParser(input); } public Object parse() {
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // } // Path: benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappOptimizedXMLRecognizer.java import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.OptimizedXMLParser; import com.github.kmizu.yapp.benchmark.parser.XMLParser; import com.github.kmizu.yapp.runtime.Result; package com.github.kmizu.yapp.benchmark; public class YappOptimizedXMLRecognizer implements GenericParser<Object> { private OptimizedXMLParser recognizer; public void setInput(Reader input) { recognizer = new OptimizedXMLParser(input); } public Object parse() {
Result<?> r = recognizer.parse();
kmizu/yapp
benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappACJSONRecognizer.java
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // }
import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.ACJSONParser; import com.github.kmizu.yapp.benchmark.parser.ACXMLParser; import com.github.kmizu.yapp.benchmark.parser.OptimizedXMLParser; import com.github.kmizu.yapp.benchmark.parser.XMLParser; import com.github.kmizu.yapp.runtime.Result;
package com.github.kmizu.yapp.benchmark; public class YappACJSONRecognizer implements GenericParser<Object> { private ACJSONParser recognizer; public void setInput(Reader input) { recognizer = new ACJSONParser(input); } public Object parse() {
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // } // Path: benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappACJSONRecognizer.java import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.ACJSONParser; import com.github.kmizu.yapp.benchmark.parser.ACXMLParser; import com.github.kmizu.yapp.benchmark.parser.OptimizedXMLParser; import com.github.kmizu.yapp.benchmark.parser.XMLParser; import com.github.kmizu.yapp.runtime.Result; package com.github.kmizu.yapp.benchmark; public class YappACJSONRecognizer implements GenericParser<Object> { private ACJSONParser recognizer; public void setInput(Reader input) { recognizer = new ACJSONParser(input); } public Object parse() {
Result<?> r = recognizer.parse();
kmizu/yapp
benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappJavaRecognizer.java
// Path: src/main/java/com/github/kmizu/yapp/runtime/ParseError.java // public class ParseError { // private final Location location; // private final String message; // // public ParseError(Location location, String message) { // this.location = location; // this.message = message; // } // // public Location getLocation() { // return location; // } // // public int getLine() { // return location.getLine(); // } // // public int getColumn() { // return location.getColumn(); // } // // public String getMessage() { // return message; // } // // public String getErrorMessage() { // StringBuilder builder = new StringBuilder(); // Formatter f = new Formatter(builder); // f.format("%d, %d: %s", location.getLine(), location.getColumn(), message); // f.flush(); // return new String(builder); // } // } // // Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // }
import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.JavaRecognizer; import com.github.kmizu.yapp.runtime.ParseError; import com.github.kmizu.yapp.runtime.Result;
package com.github.kmizu.yapp.benchmark; public class YappJavaRecognizer implements GenericParser<Object> { private JavaRecognizer recognizer; public YappJavaRecognizer(){ } public void setInput(Reader input) { recognizer = new JavaRecognizer(input); } public Object parse() {
// Path: src/main/java/com/github/kmizu/yapp/runtime/ParseError.java // public class ParseError { // private final Location location; // private final String message; // // public ParseError(Location location, String message) { // this.location = location; // this.message = message; // } // // public Location getLocation() { // return location; // } // // public int getLine() { // return location.getLine(); // } // // public int getColumn() { // return location.getColumn(); // } // // public String getMessage() { // return message; // } // // public String getErrorMessage() { // StringBuilder builder = new StringBuilder(); // Formatter f = new Formatter(builder); // f.format("%d, %d: %s", location.getLine(), location.getColumn(), message); // f.flush(); // return new String(builder); // } // } // // Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // } // Path: benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappJavaRecognizer.java import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.JavaRecognizer; import com.github.kmizu.yapp.runtime.ParseError; import com.github.kmizu.yapp.runtime.Result; package com.github.kmizu.yapp.benchmark; public class YappJavaRecognizer implements GenericParser<Object> { private JavaRecognizer recognizer; public YappJavaRecognizer(){ } public void setInput(Reader input) { recognizer = new JavaRecognizer(input); } public Object parse() {
Result<?> r = recognizer.parse();
kmizu/yapp
benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappACXMLRecognizer.java
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // }
import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.ACXMLParser; import com.github.kmizu.yapp.benchmark.parser.OptimizedXMLParser; import com.github.kmizu.yapp.benchmark.parser.XMLParser; import com.github.kmizu.yapp.runtime.Result;
package com.github.kmizu.yapp.benchmark; public class YappACXMLRecognizer implements GenericParser<Object> { private ACXMLParser recognizer; public void setInput(Reader input) { recognizer = new ACXMLParser(input); } public Object parse() {
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // } // Path: benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappACXMLRecognizer.java import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.ACXMLParser; import com.github.kmizu.yapp.benchmark.parser.OptimizedXMLParser; import com.github.kmizu.yapp.benchmark.parser.XMLParser; import com.github.kmizu.yapp.runtime.Result; package com.github.kmizu.yapp.benchmark; public class YappACXMLRecognizer implements GenericParser<Object> { private ACXMLParser recognizer; public void setInput(Reader input) { recognizer = new ACXMLParser(input); } public Object parse() {
Result<?> r = recognizer.parse();
kmizu/yapp
src/main/java/com/github/kmizu/yapp/translator/ExpressionFlattener.java
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class N_Alternation extends VarArgExpression { // public N_Alternation(Position pos, List<Expression> expressions){ // super(pos, expressions); // } // // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("("); // buf.append(body.get(0).toString()); // for(Expression e : body.subList(1, body.size())){ // buf.append(" / "); // buf.append(e.toString()); // } // buf.append(")"); // return new String(buf); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Grammar extends Node implements Iterable<Rule> { // private Symbol name; // private final List<MacroDefinition> macros; // private final List<Rule> rules; // // public Grammar(Position pos, Symbol name, List<MacroDefinition> macros, List<Rule> rules){ // super(pos); // this.name = name; // this.macros = macros; // this.rules = rules; // } // // public Iterator<Rule> iterator() { // return rules.iterator(); // } // // public Symbol name() { // return name; // } // // public void setName(Symbol name) { // this.name = name; // } // // public List<MacroDefinition> macros() { // return macros; // } // // public List<Rule> getRules() { // return rules; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("grammar " + name + ";"); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // for(Rule r : rules) { // buf.append(r); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // } // return new String(buf); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class N_Sequence extends VarArgExpression { // public N_Sequence(Position pos, List<Expression> expressions) { // super(pos, expressions); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("("); // buf.append(body.get(0).toString()); // for(Expression e : body.subList(1, body.size())){ // buf.append(" "); // buf.append(e.toString()); // } // buf.append(")"); // return new String(buf); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/util/CollectionUtil.java // public class CollectionUtil { // public static <T> List<T> list(T... elements) { // return new ArrayList<T>(Arrays.asList(elements)); // } // // public static <A, B> Pair<A, B> t(A fst, B snd) { // return new Pair<A, B>(fst, snd); // } // // public static <K, V> Map<K, V> map(Pair<? extends K, ? extends V>... elements) { // Map<K, V> map = new HashMap<K, V>(); // for(Pair<? extends K, ? extends V> e:elements) { // map.put(e.fst(), e.snd()); // } // return map; // } // // public static <T> Set<T> set(T... elements) { // return new HashSet<T>(Arrays.asList(elements)); // } // // public static <T> Set<T> setFrom(Collection<? extends T> collection) { // return new HashSet<T>(collection); // } // }
import java.util.ArrayList; import java.util.List; import com.github.kmizu.yapp.Ast.N_Alternation; import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.Grammar; import com.github.kmizu.yapp.Ast.N_Sequence; import static com.github.kmizu.yapp.util.CollectionUtil.*;
package com.github.kmizu.yapp.translator; public class ExpressionFlattener implements Translator<Grammar, Grammar> { private Translator<Grammar, Grammar> f1 = new AbstractGrammarExpander<Void>(){ @Override
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class N_Alternation extends VarArgExpression { // public N_Alternation(Position pos, List<Expression> expressions){ // super(pos, expressions); // } // // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("("); // buf.append(body.get(0).toString()); // for(Expression e : body.subList(1, body.size())){ // buf.append(" / "); // buf.append(e.toString()); // } // buf.append(")"); // return new String(buf); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Grammar extends Node implements Iterable<Rule> { // private Symbol name; // private final List<MacroDefinition> macros; // private final List<Rule> rules; // // public Grammar(Position pos, Symbol name, List<MacroDefinition> macros, List<Rule> rules){ // super(pos); // this.name = name; // this.macros = macros; // this.rules = rules; // } // // public Iterator<Rule> iterator() { // return rules.iterator(); // } // // public Symbol name() { // return name; // } // // public void setName(Symbol name) { // this.name = name; // } // // public List<MacroDefinition> macros() { // return macros; // } // // public List<Rule> getRules() { // return rules; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("grammar " + name + ";"); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // for(Rule r : rules) { // buf.append(r); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // } // return new String(buf); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class N_Sequence extends VarArgExpression { // public N_Sequence(Position pos, List<Expression> expressions) { // super(pos, expressions); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("("); // buf.append(body.get(0).toString()); // for(Expression e : body.subList(1, body.size())){ // buf.append(" "); // buf.append(e.toString()); // } // buf.append(")"); // return new String(buf); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/util/CollectionUtil.java // public class CollectionUtil { // public static <T> List<T> list(T... elements) { // return new ArrayList<T>(Arrays.asList(elements)); // } // // public static <A, B> Pair<A, B> t(A fst, B snd) { // return new Pair<A, B>(fst, snd); // } // // public static <K, V> Map<K, V> map(Pair<? extends K, ? extends V>... elements) { // Map<K, V> map = new HashMap<K, V>(); // for(Pair<? extends K, ? extends V> e:elements) { // map.put(e.fst(), e.snd()); // } // return map; // } // // public static <T> Set<T> set(T... elements) { // return new HashSet<T>(Arrays.asList(elements)); // } // // public static <T> Set<T> setFrom(Collection<? extends T> collection) { // return new HashSet<T>(collection); // } // } // Path: src/main/java/com/github/kmizu/yapp/translator/ExpressionFlattener.java import java.util.ArrayList; import java.util.List; import com.github.kmizu.yapp.Ast.N_Alternation; import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.Grammar; import com.github.kmizu.yapp.Ast.N_Sequence; import static com.github.kmizu.yapp.util.CollectionUtil.*; package com.github.kmizu.yapp.translator; public class ExpressionFlattener implements Translator<Grammar, Grammar> { private Translator<Grammar, Grammar> f1 = new AbstractGrammarExpander<Void>(){ @Override
protected Expression visit(N_Sequence node, Void context) {
kmizu/yapp
src/main/java/com/github/kmizu/yapp/translator/ExpressionFlattener.java
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class N_Alternation extends VarArgExpression { // public N_Alternation(Position pos, List<Expression> expressions){ // super(pos, expressions); // } // // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("("); // buf.append(body.get(0).toString()); // for(Expression e : body.subList(1, body.size())){ // buf.append(" / "); // buf.append(e.toString()); // } // buf.append(")"); // return new String(buf); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Grammar extends Node implements Iterable<Rule> { // private Symbol name; // private final List<MacroDefinition> macros; // private final List<Rule> rules; // // public Grammar(Position pos, Symbol name, List<MacroDefinition> macros, List<Rule> rules){ // super(pos); // this.name = name; // this.macros = macros; // this.rules = rules; // } // // public Iterator<Rule> iterator() { // return rules.iterator(); // } // // public Symbol name() { // return name; // } // // public void setName(Symbol name) { // this.name = name; // } // // public List<MacroDefinition> macros() { // return macros; // } // // public List<Rule> getRules() { // return rules; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("grammar " + name + ";"); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // for(Rule r : rules) { // buf.append(r); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // } // return new String(buf); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class N_Sequence extends VarArgExpression { // public N_Sequence(Position pos, List<Expression> expressions) { // super(pos, expressions); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("("); // buf.append(body.get(0).toString()); // for(Expression e : body.subList(1, body.size())){ // buf.append(" "); // buf.append(e.toString()); // } // buf.append(")"); // return new String(buf); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/util/CollectionUtil.java // public class CollectionUtil { // public static <T> List<T> list(T... elements) { // return new ArrayList<T>(Arrays.asList(elements)); // } // // public static <A, B> Pair<A, B> t(A fst, B snd) { // return new Pair<A, B>(fst, snd); // } // // public static <K, V> Map<K, V> map(Pair<? extends K, ? extends V>... elements) { // Map<K, V> map = new HashMap<K, V>(); // for(Pair<? extends K, ? extends V> e:elements) { // map.put(e.fst(), e.snd()); // } // return map; // } // // public static <T> Set<T> set(T... elements) { // return new HashSet<T>(Arrays.asList(elements)); // } // // public static <T> Set<T> setFrom(Collection<? extends T> collection) { // return new HashSet<T>(collection); // } // }
import java.util.ArrayList; import java.util.List; import com.github.kmizu.yapp.Ast.N_Alternation; import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.Grammar; import com.github.kmizu.yapp.Ast.N_Sequence; import static com.github.kmizu.yapp.util.CollectionUtil.*;
package com.github.kmizu.yapp.translator; public class ExpressionFlattener implements Translator<Grammar, Grammar> { private Translator<Grammar, Grammar> f1 = new AbstractGrammarExpander<Void>(){ @Override
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class N_Alternation extends VarArgExpression { // public N_Alternation(Position pos, List<Expression> expressions){ // super(pos, expressions); // } // // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("("); // buf.append(body.get(0).toString()); // for(Expression e : body.subList(1, body.size())){ // buf.append(" / "); // buf.append(e.toString()); // } // buf.append(")"); // return new String(buf); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Grammar extends Node implements Iterable<Rule> { // private Symbol name; // private final List<MacroDefinition> macros; // private final List<Rule> rules; // // public Grammar(Position pos, Symbol name, List<MacroDefinition> macros, List<Rule> rules){ // super(pos); // this.name = name; // this.macros = macros; // this.rules = rules; // } // // public Iterator<Rule> iterator() { // return rules.iterator(); // } // // public Symbol name() { // return name; // } // // public void setName(Symbol name) { // this.name = name; // } // // public List<MacroDefinition> macros() { // return macros; // } // // public List<Rule> getRules() { // return rules; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("grammar " + name + ";"); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // for(Rule r : rules) { // buf.append(r); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // } // return new String(buf); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class N_Sequence extends VarArgExpression { // public N_Sequence(Position pos, List<Expression> expressions) { // super(pos, expressions); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("("); // buf.append(body.get(0).toString()); // for(Expression e : body.subList(1, body.size())){ // buf.append(" "); // buf.append(e.toString()); // } // buf.append(")"); // return new String(buf); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/util/CollectionUtil.java // public class CollectionUtil { // public static <T> List<T> list(T... elements) { // return new ArrayList<T>(Arrays.asList(elements)); // } // // public static <A, B> Pair<A, B> t(A fst, B snd) { // return new Pair<A, B>(fst, snd); // } // // public static <K, V> Map<K, V> map(Pair<? extends K, ? extends V>... elements) { // Map<K, V> map = new HashMap<K, V>(); // for(Pair<? extends K, ? extends V> e:elements) { // map.put(e.fst(), e.snd()); // } // return map; // } // // public static <T> Set<T> set(T... elements) { // return new HashSet<T>(Arrays.asList(elements)); // } // // public static <T> Set<T> setFrom(Collection<? extends T> collection) { // return new HashSet<T>(collection); // } // } // Path: src/main/java/com/github/kmizu/yapp/translator/ExpressionFlattener.java import java.util.ArrayList; import java.util.List; import com.github.kmizu.yapp.Ast.N_Alternation; import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.Grammar; import com.github.kmizu.yapp.Ast.N_Sequence; import static com.github.kmizu.yapp.util.CollectionUtil.*; package com.github.kmizu.yapp.translator; public class ExpressionFlattener implements Translator<Grammar, Grammar> { private Translator<Grammar, Grammar> f1 = new AbstractGrammarExpander<Void>(){ @Override
protected Expression visit(N_Sequence node, Void context) {
kmizu/yapp
src/main/java/com/github/kmizu/yapp/translator/ExpressionFlattener.java
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class N_Alternation extends VarArgExpression { // public N_Alternation(Position pos, List<Expression> expressions){ // super(pos, expressions); // } // // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("("); // buf.append(body.get(0).toString()); // for(Expression e : body.subList(1, body.size())){ // buf.append(" / "); // buf.append(e.toString()); // } // buf.append(")"); // return new String(buf); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Grammar extends Node implements Iterable<Rule> { // private Symbol name; // private final List<MacroDefinition> macros; // private final List<Rule> rules; // // public Grammar(Position pos, Symbol name, List<MacroDefinition> macros, List<Rule> rules){ // super(pos); // this.name = name; // this.macros = macros; // this.rules = rules; // } // // public Iterator<Rule> iterator() { // return rules.iterator(); // } // // public Symbol name() { // return name; // } // // public void setName(Symbol name) { // this.name = name; // } // // public List<MacroDefinition> macros() { // return macros; // } // // public List<Rule> getRules() { // return rules; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("grammar " + name + ";"); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // for(Rule r : rules) { // buf.append(r); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // } // return new String(buf); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class N_Sequence extends VarArgExpression { // public N_Sequence(Position pos, List<Expression> expressions) { // super(pos, expressions); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("("); // buf.append(body.get(0).toString()); // for(Expression e : body.subList(1, body.size())){ // buf.append(" "); // buf.append(e.toString()); // } // buf.append(")"); // return new String(buf); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/util/CollectionUtil.java // public class CollectionUtil { // public static <T> List<T> list(T... elements) { // return new ArrayList<T>(Arrays.asList(elements)); // } // // public static <A, B> Pair<A, B> t(A fst, B snd) { // return new Pair<A, B>(fst, snd); // } // // public static <K, V> Map<K, V> map(Pair<? extends K, ? extends V>... elements) { // Map<K, V> map = new HashMap<K, V>(); // for(Pair<? extends K, ? extends V> e:elements) { // map.put(e.fst(), e.snd()); // } // return map; // } // // public static <T> Set<T> set(T... elements) { // return new HashSet<T>(Arrays.asList(elements)); // } // // public static <T> Set<T> setFrom(Collection<? extends T> collection) { // return new HashSet<T>(collection); // } // }
import java.util.ArrayList; import java.util.List; import com.github.kmizu.yapp.Ast.N_Alternation; import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.Grammar; import com.github.kmizu.yapp.Ast.N_Sequence; import static com.github.kmizu.yapp.util.CollectionUtil.*;
package com.github.kmizu.yapp.translator; public class ExpressionFlattener implements Translator<Grammar, Grammar> { private Translator<Grammar, Grammar> f1 = new AbstractGrammarExpander<Void>(){ @Override protected Expression visit(N_Sequence node, Void context) { List<Expression> es = node.body(); List<Expression> result = new ArrayList<Expression>(); Expression last = es.get(0); for(Expression e : es.subList(1, es.size())){
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class N_Alternation extends VarArgExpression { // public N_Alternation(Position pos, List<Expression> expressions){ // super(pos, expressions); // } // // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("("); // buf.append(body.get(0).toString()); // for(Expression e : body.subList(1, body.size())){ // buf.append(" / "); // buf.append(e.toString()); // } // buf.append(")"); // return new String(buf); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Grammar extends Node implements Iterable<Rule> { // private Symbol name; // private final List<MacroDefinition> macros; // private final List<Rule> rules; // // public Grammar(Position pos, Symbol name, List<MacroDefinition> macros, List<Rule> rules){ // super(pos); // this.name = name; // this.macros = macros; // this.rules = rules; // } // // public Iterator<Rule> iterator() { // return rules.iterator(); // } // // public Symbol name() { // return name; // } // // public void setName(Symbol name) { // this.name = name; // } // // public List<MacroDefinition> macros() { // return macros; // } // // public List<Rule> getRules() { // return rules; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("grammar " + name + ";"); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // for(Rule r : rules) { // buf.append(r); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // } // return new String(buf); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class N_Sequence extends VarArgExpression { // public N_Sequence(Position pos, List<Expression> expressions) { // super(pos, expressions); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("("); // buf.append(body.get(0).toString()); // for(Expression e : body.subList(1, body.size())){ // buf.append(" "); // buf.append(e.toString()); // } // buf.append(")"); // return new String(buf); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/util/CollectionUtil.java // public class CollectionUtil { // public static <T> List<T> list(T... elements) { // return new ArrayList<T>(Arrays.asList(elements)); // } // // public static <A, B> Pair<A, B> t(A fst, B snd) { // return new Pair<A, B>(fst, snd); // } // // public static <K, V> Map<K, V> map(Pair<? extends K, ? extends V>... elements) { // Map<K, V> map = new HashMap<K, V>(); // for(Pair<? extends K, ? extends V> e:elements) { // map.put(e.fst(), e.snd()); // } // return map; // } // // public static <T> Set<T> set(T... elements) { // return new HashSet<T>(Arrays.asList(elements)); // } // // public static <T> Set<T> setFrom(Collection<? extends T> collection) { // return new HashSet<T>(collection); // } // } // Path: src/main/java/com/github/kmizu/yapp/translator/ExpressionFlattener.java import java.util.ArrayList; import java.util.List; import com.github.kmizu.yapp.Ast.N_Alternation; import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.Grammar; import com.github.kmizu.yapp.Ast.N_Sequence; import static com.github.kmizu.yapp.util.CollectionUtil.*; package com.github.kmizu.yapp.translator; public class ExpressionFlattener implements Translator<Grammar, Grammar> { private Translator<Grammar, Grammar> f1 = new AbstractGrammarExpander<Void>(){ @Override protected Expression visit(N_Sequence node, Void context) { List<Expression> es = node.body(); List<Expression> result = new ArrayList<Expression>(); Expression last = es.get(0); for(Expression e : es.subList(1, es.size())){
if(e instanceof N_Alternation){
kmizu/yapp
benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappACJavaRecognizer.java
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // }
import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.ACJavaRecognizer; import com.github.kmizu.yapp.benchmark.parser.OptimizedJavaRecognizer; import com.github.kmizu.yapp.runtime.Result;
package com.github.kmizu.yapp.benchmark; public class YappACJavaRecognizer implements GenericParser { private ACJavaRecognizer recognizer; public void setInput(Reader input) { recognizer = new ACJavaRecognizer(input); } public Object parse() {
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // } // Path: benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappACJavaRecognizer.java import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.ACJavaRecognizer; import com.github.kmizu.yapp.benchmark.parser.OptimizedJavaRecognizer; import com.github.kmizu.yapp.runtime.Result; package com.github.kmizu.yapp.benchmark; public class YappACJavaRecognizer implements GenericParser { private ACJavaRecognizer recognizer; public void setInput(Reader input) { recognizer = new ACJavaRecognizer(input); } public Object parse() {
Result<?> r = recognizer.parse();
kmizu/yapp
benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappXMLRecognizer.java
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // }
import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.XMLParser; import com.github.kmizu.yapp.runtime.Result;
package com.github.kmizu.yapp.benchmark; public class YappXMLRecognizer implements GenericParser<Object> { private XMLParser recognizer; public void setInput(Reader input) { recognizer = new XMLParser(input); } public Object parse() {
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // } // Path: benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappXMLRecognizer.java import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.XMLParser; import com.github.kmizu.yapp.runtime.Result; package com.github.kmizu.yapp.benchmark; public class YappXMLRecognizer implements GenericParser<Object> { private XMLParser recognizer; public void setInput(Reader input) { recognizer = new XMLParser(input); } public Object parse() {
Result<?> r = recognizer.parse();
kmizu/yapp
benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappOptimizedJSONRecognizer.java
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // }
import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.OptimizedJSONParser; import com.github.kmizu.yapp.benchmark.parser.OptimizedJavaRecognizer; import com.github.kmizu.yapp.runtime.Result;
package com.github.kmizu.yapp.benchmark; public class YappOptimizedJSONRecognizer implements GenericParser { private OptimizedJSONParser recognizer; public void setInput(Reader input) { recognizer = new OptimizedJSONParser(input); } public Object parse() {
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // } // Path: benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappOptimizedJSONRecognizer.java import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.OptimizedJSONParser; import com.github.kmizu.yapp.benchmark.parser.OptimizedJavaRecognizer; import com.github.kmizu.yapp.runtime.Result; package com.github.kmizu.yapp.benchmark; public class YappOptimizedJSONRecognizer implements GenericParser { private OptimizedJSONParser recognizer; public void setInput(Reader input) { recognizer = new OptimizedJSONParser(input); } public Object parse() {
Result<?> r = recognizer.parse();
kmizu/yapp
src/main/java/com/github/kmizu/yapp/Regex.java
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Char extends Element { // public final char value; // public Char(char value) { // this.value = value; // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public abstract static class Element {} // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Range extends Element { // public final char start; // public final char end; // public Range(char start, char end) { // this.start = start; // this.end = end; // } // }
import java.util.Set; import com.github.kmizu.yapp.Ast.CharClass.Char; import com.github.kmizu.yapp.Ast.CharClass.Element; import com.github.kmizu.yapp.Ast.CharClass.Range;
} @Override public String toString() { return "."; } } /** * An empty expression of a RE. * @author Kota Mizushima * */ public static class Empty extends Expression { @Override public <R, C> R accept(Visitor<C, R> visitor, C context) { return visitor.visit(this, context); } @Override public String toString() { return ""; } } /** * A character expression of a RE. * @author Kota Mizushima * */
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Char extends Element { // public final char value; // public Char(char value) { // this.value = value; // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public abstract static class Element {} // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Range extends Element { // public final char start; // public final char end; // public Range(char start, char end) { // this.start = start; // this.end = end; // } // } // Path: src/main/java/com/github/kmizu/yapp/Regex.java import java.util.Set; import com.github.kmizu.yapp.Ast.CharClass.Char; import com.github.kmizu.yapp.Ast.CharClass.Element; import com.github.kmizu.yapp.Ast.CharClass.Range; } @Override public String toString() { return "."; } } /** * An empty expression of a RE. * @author Kota Mizushima * */ public static class Empty extends Expression { @Override public <R, C> R accept(Visitor<C, R> visitor, C context) { return visitor.visit(this, context); } @Override public String toString() { return ""; } } /** * A character expression of a RE. * @author Kota Mizushima * */
public static class Char extends Expression {
kmizu/yapp
src/main/java/com/github/kmizu/yapp/Ist.java
// Path: src/main/java/com/github/kmizu/yapp/util/SystemProperties.java // public static final String LINE_SEPARATOR = System.getProperty("line.separator");
import static com.github.kmizu.yapp.util.SystemProperties.LINE_SEPARATOR; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set;
public Symbol getName() { return name; } public Map<Symbol, Set<Character>> getNameToCharSet() { return nameToCharSet; } public Symbol getStartName() { return startName; } public Symbol getStartType() { return startType; } public List<Function> getRules() { return rules; } public Iterator<Function> iterator() { return rules.iterator(); } @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("parser "); builder.append(name);
// Path: src/main/java/com/github/kmizu/yapp/util/SystemProperties.java // public static final String LINE_SEPARATOR = System.getProperty("line.separator"); // Path: src/main/java/com/github/kmizu/yapp/Ist.java import static com.github.kmizu.yapp.util.SystemProperties.LINE_SEPARATOR; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; public Symbol getName() { return name; } public Map<Symbol, Set<Character>> getNameToCharSet() { return nameToCharSet; } public Symbol getStartName() { return startName; } public Symbol getStartType() { return startType; } public List<Function> getRules() { return rules; } public Iterator<Function> iterator() { return rules.iterator(); } @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("parser "); builder.append(name);
builder.append(LINE_SEPARATOR);
kmizu/yapp
src/main/java/com/github/kmizu/yapp/translator/MacroExpanderEx.java
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class BoundedExpression extends Expression { // private Expression body; // public BoundedExpression(Expression body) { // super(body.pos()); // this.body = body; // } // // public Expression body() { // return body; // } // // @Override // public String toString() { // return "bounded{" + body + "}"; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // }
import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.BoundedExpression;
package com.github.kmizu.yapp.translator; /** * A special MacroExpander which doesn't desugar BoundedExpression. */ public class MacroExpanderEx extends MacroExpander { @Override
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class BoundedExpression extends Expression { // private Expression body; // public BoundedExpression(Expression body) { // super(body.pos()); // this.body = body; // } // // public Expression body() { // return body; // } // // @Override // public String toString() { // return "bounded{" + body + "}"; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // Path: src/main/java/com/github/kmizu/yapp/translator/MacroExpanderEx.java import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.BoundedExpression; package com.github.kmizu.yapp.translator; /** * A special MacroExpander which doesn't desugar BoundedExpression. */ public class MacroExpanderEx extends MacroExpander { @Override
protected Expression visit(BoundedExpression node, MacroEnvironment env) {
kmizu/yapp
src/main/java/com/github/kmizu/yapp/translator/MacroExpanderEx.java
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class BoundedExpression extends Expression { // private Expression body; // public BoundedExpression(Expression body) { // super(body.pos()); // this.body = body; // } // // public Expression body() { // return body; // } // // @Override // public String toString() { // return "bounded{" + body + "}"; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // }
import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.BoundedExpression;
package com.github.kmizu.yapp.translator; /** * A special MacroExpander which doesn't desugar BoundedExpression. */ public class MacroExpanderEx extends MacroExpander { @Override
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class BoundedExpression extends Expression { // private Expression body; // public BoundedExpression(Expression body) { // super(body.pos()); // this.body = body; // } // // public Expression body() { // return body; // } // // @Override // public String toString() { // return "bounded{" + body + "}"; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // Path: src/main/java/com/github/kmizu/yapp/translator/MacroExpanderEx.java import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.BoundedExpression; package com.github.kmizu.yapp.translator; /** * A special MacroExpander which doesn't desugar BoundedExpression. */ public class MacroExpanderEx extends MacroExpander { @Override
protected Expression visit(BoundedExpression node, MacroEnvironment env) {
kmizu/yapp
src/main/java/com/github/kmizu/yapp/Ast.java
// Path: src/main/java/com/github/kmizu/yapp/util/SystemProperties.java // public class SystemProperties { // public static final String LINE_SEPARATOR = System.getProperty("line.separator"); // public static final String PATH_SEPARATOR = File.pathSeparator; // public static final String FILE_SEPARATOR = File.separator; // }
import java.util.Collections; import java.util.Iterator; import java.util.List; import com.github.kmizu.yapp.util.SystemProperties;
public Iterator<Rule> iterator() { return rules.iterator(); } public Symbol name() { return name; } public void setName(Symbol name) { this.name = name; } public List<MacroDefinition> macros() { return macros; } public List<Rule> getRules() { return rules; } @Override public <R, C> R accept(Visitor<R, C> visitor, C context) { return visitor.visit(this, context); } @Override public String toString() { StringBuffer buf = new StringBuffer(); buf.append("grammar " + name + ";");
// Path: src/main/java/com/github/kmizu/yapp/util/SystemProperties.java // public class SystemProperties { // public static final String LINE_SEPARATOR = System.getProperty("line.separator"); // public static final String PATH_SEPARATOR = File.pathSeparator; // public static final String FILE_SEPARATOR = File.separator; // } // Path: src/main/java/com/github/kmizu/yapp/Ast.java import java.util.Collections; import java.util.Iterator; import java.util.List; import com.github.kmizu.yapp.util.SystemProperties; public Iterator<Rule> iterator() { return rules.iterator(); } public Symbol name() { return name; } public void setName(Symbol name) { this.name = name; } public List<MacroDefinition> macros() { return macros; } public List<Rule> getRules() { return rules; } @Override public <R, C> R accept(Visitor<R, C> visitor, C context) { return visitor.visit(this, context); } @Override public String toString() { StringBuffer buf = new StringBuffer(); buf.append("grammar " + name + ";");
buf.append(SystemProperties.LINE_SEPARATOR);
kmizu/yapp
benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappOptimizedESLLRecognizer.java
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // }
import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.OptimizedESLLParser; import com.github.kmizu.yapp.benchmark.parser.OptimizedXMLParser; import com.github.kmizu.yapp.benchmark.parser.XMLParser; import com.github.kmizu.yapp.runtime.Result;
package com.github.kmizu.yapp.benchmark; public class YappOptimizedESLLRecognizer implements GenericParser<Object> { private OptimizedESLLParser recognizer; public void setInput(Reader input) { recognizer = new OptimizedESLLParser(input); } public Object parse() {
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // } // Path: benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappOptimizedESLLRecognizer.java import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.OptimizedESLLParser; import com.github.kmizu.yapp.benchmark.parser.OptimizedXMLParser; import com.github.kmizu.yapp.benchmark.parser.XMLParser; import com.github.kmizu.yapp.runtime.Result; package com.github.kmizu.yapp.benchmark; public class YappOptimizedESLLRecognizer implements GenericParser<Object> { private OptimizedESLLParser recognizer; public void setInput(Reader input) { recognizer = new OptimizedESLLParser(input); } public Object parse() {
Result<?> r = recognizer.parse();
kmizu/yapp
src/main/java/com/github/kmizu/yapp/translator/RuleInliner.java
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Grammar extends Node implements Iterable<Rule> { // private Symbol name; // private final List<MacroDefinition> macros; // private final List<Rule> rules; // // public Grammar(Position pos, Symbol name, List<MacroDefinition> macros, List<Rule> rules){ // super(pos); // this.name = name; // this.macros = macros; // this.rules = rules; // } // // public Iterator<Rule> iterator() { // return rules.iterator(); // } // // public Symbol name() { // return name; // } // // public void setName(Symbol name) { // this.name = name; // } // // public List<MacroDefinition> macros() { // return macros; // } // // public List<Rule> getRules() { // return rules; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("grammar " + name + ";"); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // for(Rule r : rules) { // buf.append(r); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // } // return new String(buf); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class NonTerminal extends Expression { // private Symbol name; // private Symbol var; // // public NonTerminal(Position pos, Symbol name, Symbol var) { // super(pos); // this.name = name; // this.var = var; // } // // public NonTerminal(Position pos, Symbol name){ // this(pos, name, null); // } // // public Symbol name() { // return name; // } // // public Symbol var() { // return var; // } // // @Override // public String toString() { // return var != null ? var + ":" + name.toString() : name.toString(); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Rule extends Node { // public static final int BOUNDED = 1; // private int flags; // private Symbol name; // private Symbol type; // private Expression expression; // private String code; // // public Rule(Position pos, int flags, Symbol name, Symbol type, Expression expression, String code){ // super(pos); // this.flags = flags; // this.name = name; // this.type = type; // this.expression = expression; // this.code = code; // } // // public int flags() { // return flags; // } // // public Symbol name() { // return name; // } // // public Symbol type() { // return type; // } // // public Expression body() { // return expression; // } // // public String code() { // return code; // } // // @Override // public String toString() { // return ((flags & BOUNDED) != 0 ? "bounded " : "") + // name + " = " + expression + " ;"; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // }
import java.util.ArrayList; import java.util.LinkedHashMap; import com.github.kmizu.yapp.Symbol; import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.Grammar; import com.github.kmizu.yapp.Ast.NonTerminal; import com.github.kmizu.yapp.Ast.Rule;
package com.github.kmizu.yapp.translator; public class RuleInliner extends AbstractGrammarExpander<RuleInliner.Context> { static class Context {
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Grammar extends Node implements Iterable<Rule> { // private Symbol name; // private final List<MacroDefinition> macros; // private final List<Rule> rules; // // public Grammar(Position pos, Symbol name, List<MacroDefinition> macros, List<Rule> rules){ // super(pos); // this.name = name; // this.macros = macros; // this.rules = rules; // } // // public Iterator<Rule> iterator() { // return rules.iterator(); // } // // public Symbol name() { // return name; // } // // public void setName(Symbol name) { // this.name = name; // } // // public List<MacroDefinition> macros() { // return macros; // } // // public List<Rule> getRules() { // return rules; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("grammar " + name + ";"); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // for(Rule r : rules) { // buf.append(r); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // } // return new String(buf); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class NonTerminal extends Expression { // private Symbol name; // private Symbol var; // // public NonTerminal(Position pos, Symbol name, Symbol var) { // super(pos); // this.name = name; // this.var = var; // } // // public NonTerminal(Position pos, Symbol name){ // this(pos, name, null); // } // // public Symbol name() { // return name; // } // // public Symbol var() { // return var; // } // // @Override // public String toString() { // return var != null ? var + ":" + name.toString() : name.toString(); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Rule extends Node { // public static final int BOUNDED = 1; // private int flags; // private Symbol name; // private Symbol type; // private Expression expression; // private String code; // // public Rule(Position pos, int flags, Symbol name, Symbol type, Expression expression, String code){ // super(pos); // this.flags = flags; // this.name = name; // this.type = type; // this.expression = expression; // this.code = code; // } // // public int flags() { // return flags; // } // // public Symbol name() { // return name; // } // // public Symbol type() { // return type; // } // // public Expression body() { // return expression; // } // // public String code() { // return code; // } // // @Override // public String toString() { // return ((flags & BOUNDED) != 0 ? "bounded " : "") + // name + " = " + expression + " ;"; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // Path: src/main/java/com/github/kmizu/yapp/translator/RuleInliner.java import java.util.ArrayList; import java.util.LinkedHashMap; import com.github.kmizu.yapp.Symbol; import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.Grammar; import com.github.kmizu.yapp.Ast.NonTerminal; import com.github.kmizu.yapp.Ast.Rule; package com.github.kmizu.yapp.translator; public class RuleInliner extends AbstractGrammarExpander<RuleInliner.Context> { static class Context {
LinkedHashMap<Symbol, Rule> env;
kmizu/yapp
src/main/java/com/github/kmizu/yapp/translator/RuleInliner.java
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Grammar extends Node implements Iterable<Rule> { // private Symbol name; // private final List<MacroDefinition> macros; // private final List<Rule> rules; // // public Grammar(Position pos, Symbol name, List<MacroDefinition> macros, List<Rule> rules){ // super(pos); // this.name = name; // this.macros = macros; // this.rules = rules; // } // // public Iterator<Rule> iterator() { // return rules.iterator(); // } // // public Symbol name() { // return name; // } // // public void setName(Symbol name) { // this.name = name; // } // // public List<MacroDefinition> macros() { // return macros; // } // // public List<Rule> getRules() { // return rules; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("grammar " + name + ";"); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // for(Rule r : rules) { // buf.append(r); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // } // return new String(buf); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class NonTerminal extends Expression { // private Symbol name; // private Symbol var; // // public NonTerminal(Position pos, Symbol name, Symbol var) { // super(pos); // this.name = name; // this.var = var; // } // // public NonTerminal(Position pos, Symbol name){ // this(pos, name, null); // } // // public Symbol name() { // return name; // } // // public Symbol var() { // return var; // } // // @Override // public String toString() { // return var != null ? var + ":" + name.toString() : name.toString(); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Rule extends Node { // public static final int BOUNDED = 1; // private int flags; // private Symbol name; // private Symbol type; // private Expression expression; // private String code; // // public Rule(Position pos, int flags, Symbol name, Symbol type, Expression expression, String code){ // super(pos); // this.flags = flags; // this.name = name; // this.type = type; // this.expression = expression; // this.code = code; // } // // public int flags() { // return flags; // } // // public Symbol name() { // return name; // } // // public Symbol type() { // return type; // } // // public Expression body() { // return expression; // } // // public String code() { // return code; // } // // @Override // public String toString() { // return ((flags & BOUNDED) != 0 ? "bounded " : "") + // name + " = " + expression + " ;"; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // }
import java.util.ArrayList; import java.util.LinkedHashMap; import com.github.kmizu.yapp.Symbol; import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.Grammar; import com.github.kmizu.yapp.Ast.NonTerminal; import com.github.kmizu.yapp.Ast.Rule;
package com.github.kmizu.yapp.translator; public class RuleInliner extends AbstractGrammarExpander<RuleInliner.Context> { static class Context { LinkedHashMap<Symbol, Rule> env; int depth; boolean changed; } private final int inlineLimit; public RuleInliner(int inlineLimit) { this.inlineLimit = inlineLimit; } @Override public Context newContext() { return new Context(); } @Override
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Grammar extends Node implements Iterable<Rule> { // private Symbol name; // private final List<MacroDefinition> macros; // private final List<Rule> rules; // // public Grammar(Position pos, Symbol name, List<MacroDefinition> macros, List<Rule> rules){ // super(pos); // this.name = name; // this.macros = macros; // this.rules = rules; // } // // public Iterator<Rule> iterator() { // return rules.iterator(); // } // // public Symbol name() { // return name; // } // // public void setName(Symbol name) { // this.name = name; // } // // public List<MacroDefinition> macros() { // return macros; // } // // public List<Rule> getRules() { // return rules; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("grammar " + name + ";"); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // for(Rule r : rules) { // buf.append(r); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // } // return new String(buf); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class NonTerminal extends Expression { // private Symbol name; // private Symbol var; // // public NonTerminal(Position pos, Symbol name, Symbol var) { // super(pos); // this.name = name; // this.var = var; // } // // public NonTerminal(Position pos, Symbol name){ // this(pos, name, null); // } // // public Symbol name() { // return name; // } // // public Symbol var() { // return var; // } // // @Override // public String toString() { // return var != null ? var + ":" + name.toString() : name.toString(); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Rule extends Node { // public static final int BOUNDED = 1; // private int flags; // private Symbol name; // private Symbol type; // private Expression expression; // private String code; // // public Rule(Position pos, int flags, Symbol name, Symbol type, Expression expression, String code){ // super(pos); // this.flags = flags; // this.name = name; // this.type = type; // this.expression = expression; // this.code = code; // } // // public int flags() { // return flags; // } // // public Symbol name() { // return name; // } // // public Symbol type() { // return type; // } // // public Expression body() { // return expression; // } // // public String code() { // return code; // } // // @Override // public String toString() { // return ((flags & BOUNDED) != 0 ? "bounded " : "") + // name + " = " + expression + " ;"; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // Path: src/main/java/com/github/kmizu/yapp/translator/RuleInliner.java import java.util.ArrayList; import java.util.LinkedHashMap; import com.github.kmizu.yapp.Symbol; import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.Grammar; import com.github.kmizu.yapp.Ast.NonTerminal; import com.github.kmizu.yapp.Ast.Rule; package com.github.kmizu.yapp.translator; public class RuleInliner extends AbstractGrammarExpander<RuleInliner.Context> { static class Context { LinkedHashMap<Symbol, Rule> env; int depth; boolean changed; } private final int inlineLimit; public RuleInliner(int inlineLimit) { this.inlineLimit = inlineLimit; } @Override public Context newContext() { return new Context(); } @Override
public Grammar expand(Grammar node, Context context) {
kmizu/yapp
src/main/java/com/github/kmizu/yapp/translator/RuleInliner.java
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Grammar extends Node implements Iterable<Rule> { // private Symbol name; // private final List<MacroDefinition> macros; // private final List<Rule> rules; // // public Grammar(Position pos, Symbol name, List<MacroDefinition> macros, List<Rule> rules){ // super(pos); // this.name = name; // this.macros = macros; // this.rules = rules; // } // // public Iterator<Rule> iterator() { // return rules.iterator(); // } // // public Symbol name() { // return name; // } // // public void setName(Symbol name) { // this.name = name; // } // // public List<MacroDefinition> macros() { // return macros; // } // // public List<Rule> getRules() { // return rules; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("grammar " + name + ";"); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // for(Rule r : rules) { // buf.append(r); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // } // return new String(buf); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class NonTerminal extends Expression { // private Symbol name; // private Symbol var; // // public NonTerminal(Position pos, Symbol name, Symbol var) { // super(pos); // this.name = name; // this.var = var; // } // // public NonTerminal(Position pos, Symbol name){ // this(pos, name, null); // } // // public Symbol name() { // return name; // } // // public Symbol var() { // return var; // } // // @Override // public String toString() { // return var != null ? var + ":" + name.toString() : name.toString(); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Rule extends Node { // public static final int BOUNDED = 1; // private int flags; // private Symbol name; // private Symbol type; // private Expression expression; // private String code; // // public Rule(Position pos, int flags, Symbol name, Symbol type, Expression expression, String code){ // super(pos); // this.flags = flags; // this.name = name; // this.type = type; // this.expression = expression; // this.code = code; // } // // public int flags() { // return flags; // } // // public Symbol name() { // return name; // } // // public Symbol type() { // return type; // } // // public Expression body() { // return expression; // } // // public String code() { // return code; // } // // @Override // public String toString() { // return ((flags & BOUNDED) != 0 ? "bounded " : "") + // name + " = " + expression + " ;"; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // }
import java.util.ArrayList; import java.util.LinkedHashMap; import com.github.kmizu.yapp.Symbol; import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.Grammar; import com.github.kmizu.yapp.Ast.NonTerminal; import com.github.kmizu.yapp.Ast.Rule;
package com.github.kmizu.yapp.translator; public class RuleInliner extends AbstractGrammarExpander<RuleInliner.Context> { static class Context { LinkedHashMap<Symbol, Rule> env; int depth; boolean changed; } private final int inlineLimit; public RuleInliner(int inlineLimit) { this.inlineLimit = inlineLimit; } @Override public Context newContext() { return new Context(); } @Override public Grammar expand(Grammar node, Context context) { context.env = new LinkedHashMap<Symbol, Rule>(); for(Rule rule : node) { context.env.put(rule.name(), rule); } for(Rule rule : node) { context.env.put(rule.name(), expand(rule, context)); } return new Grammar(node.pos(), node.name(), node.macros(), new ArrayList<Rule>(context.env.values())); } @Override public Rule expand(Rule node, Context context) {
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Grammar extends Node implements Iterable<Rule> { // private Symbol name; // private final List<MacroDefinition> macros; // private final List<Rule> rules; // // public Grammar(Position pos, Symbol name, List<MacroDefinition> macros, List<Rule> rules){ // super(pos); // this.name = name; // this.macros = macros; // this.rules = rules; // } // // public Iterator<Rule> iterator() { // return rules.iterator(); // } // // public Symbol name() { // return name; // } // // public void setName(Symbol name) { // this.name = name; // } // // public List<MacroDefinition> macros() { // return macros; // } // // public List<Rule> getRules() { // return rules; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("grammar " + name + ";"); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // for(Rule r : rules) { // buf.append(r); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // } // return new String(buf); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class NonTerminal extends Expression { // private Symbol name; // private Symbol var; // // public NonTerminal(Position pos, Symbol name, Symbol var) { // super(pos); // this.name = name; // this.var = var; // } // // public NonTerminal(Position pos, Symbol name){ // this(pos, name, null); // } // // public Symbol name() { // return name; // } // // public Symbol var() { // return var; // } // // @Override // public String toString() { // return var != null ? var + ":" + name.toString() : name.toString(); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Rule extends Node { // public static final int BOUNDED = 1; // private int flags; // private Symbol name; // private Symbol type; // private Expression expression; // private String code; // // public Rule(Position pos, int flags, Symbol name, Symbol type, Expression expression, String code){ // super(pos); // this.flags = flags; // this.name = name; // this.type = type; // this.expression = expression; // this.code = code; // } // // public int flags() { // return flags; // } // // public Symbol name() { // return name; // } // // public Symbol type() { // return type; // } // // public Expression body() { // return expression; // } // // public String code() { // return code; // } // // @Override // public String toString() { // return ((flags & BOUNDED) != 0 ? "bounded " : "") + // name + " = " + expression + " ;"; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // Path: src/main/java/com/github/kmizu/yapp/translator/RuleInliner.java import java.util.ArrayList; import java.util.LinkedHashMap; import com.github.kmizu.yapp.Symbol; import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.Grammar; import com.github.kmizu.yapp.Ast.NonTerminal; import com.github.kmizu.yapp.Ast.Rule; package com.github.kmizu.yapp.translator; public class RuleInliner extends AbstractGrammarExpander<RuleInliner.Context> { static class Context { LinkedHashMap<Symbol, Rule> env; int depth; boolean changed; } private final int inlineLimit; public RuleInliner(int inlineLimit) { this.inlineLimit = inlineLimit; } @Override public Context newContext() { return new Context(); } @Override public Grammar expand(Grammar node, Context context) { context.env = new LinkedHashMap<Symbol, Rule>(); for(Rule rule : node) { context.env.put(rule.name(), rule); } for(Rule rule : node) { context.env.put(rule.name(), expand(rule, context)); } return new Grammar(node.pos(), node.name(), node.macros(), new ArrayList<Rule>(context.env.values())); } @Override public Rule expand(Rule node, Context context) {
Expression e = node.body();
kmizu/yapp
src/main/java/com/github/kmizu/yapp/translator/RuleInliner.java
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Grammar extends Node implements Iterable<Rule> { // private Symbol name; // private final List<MacroDefinition> macros; // private final List<Rule> rules; // // public Grammar(Position pos, Symbol name, List<MacroDefinition> macros, List<Rule> rules){ // super(pos); // this.name = name; // this.macros = macros; // this.rules = rules; // } // // public Iterator<Rule> iterator() { // return rules.iterator(); // } // // public Symbol name() { // return name; // } // // public void setName(Symbol name) { // this.name = name; // } // // public List<MacroDefinition> macros() { // return macros; // } // // public List<Rule> getRules() { // return rules; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("grammar " + name + ";"); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // for(Rule r : rules) { // buf.append(r); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // } // return new String(buf); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class NonTerminal extends Expression { // private Symbol name; // private Symbol var; // // public NonTerminal(Position pos, Symbol name, Symbol var) { // super(pos); // this.name = name; // this.var = var; // } // // public NonTerminal(Position pos, Symbol name){ // this(pos, name, null); // } // // public Symbol name() { // return name; // } // // public Symbol var() { // return var; // } // // @Override // public String toString() { // return var != null ? var + ":" + name.toString() : name.toString(); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Rule extends Node { // public static final int BOUNDED = 1; // private int flags; // private Symbol name; // private Symbol type; // private Expression expression; // private String code; // // public Rule(Position pos, int flags, Symbol name, Symbol type, Expression expression, String code){ // super(pos); // this.flags = flags; // this.name = name; // this.type = type; // this.expression = expression; // this.code = code; // } // // public int flags() { // return flags; // } // // public Symbol name() { // return name; // } // // public Symbol type() { // return type; // } // // public Expression body() { // return expression; // } // // public String code() { // return code; // } // // @Override // public String toString() { // return ((flags & BOUNDED) != 0 ? "bounded " : "") + // name + " = " + expression + " ;"; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // }
import java.util.ArrayList; import java.util.LinkedHashMap; import com.github.kmizu.yapp.Symbol; import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.Grammar; import com.github.kmizu.yapp.Ast.NonTerminal; import com.github.kmizu.yapp.Ast.Rule;
@Override public Context newContext() { return new Context(); } @Override public Grammar expand(Grammar node, Context context) { context.env = new LinkedHashMap<Symbol, Rule>(); for(Rule rule : node) { context.env.put(rule.name(), rule); } for(Rule rule : node) { context.env.put(rule.name(), expand(rule, context)); } return new Grammar(node.pos(), node.name(), node.macros(), new ArrayList<Rule>(context.env.values())); } @Override public Rule expand(Rule node, Context context) { Expression e = node.body(); context.depth = 0; context.changed = true; while(context.changed && context.depth < inlineLimit){ context.changed = false; e = e.accept(this, context); } return new Rule(node.pos(), node.flags(), node.name(), node.type(), e, node.code()); } @Override
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Grammar extends Node implements Iterable<Rule> { // private Symbol name; // private final List<MacroDefinition> macros; // private final List<Rule> rules; // // public Grammar(Position pos, Symbol name, List<MacroDefinition> macros, List<Rule> rules){ // super(pos); // this.name = name; // this.macros = macros; // this.rules = rules; // } // // public Iterator<Rule> iterator() { // return rules.iterator(); // } // // public Symbol name() { // return name; // } // // public void setName(Symbol name) { // this.name = name; // } // // public List<MacroDefinition> macros() { // return macros; // } // // public List<Rule> getRules() { // return rules; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // // @Override // public String toString() { // StringBuffer buf = new StringBuffer(); // buf.append("grammar " + name + ";"); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // for(Rule r : rules) { // buf.append(r); // buf.append(SystemProperties.LINE_SEPARATOR); // buf.append(SystemProperties.LINE_SEPARATOR); // } // return new String(buf); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class NonTerminal extends Expression { // private Symbol name; // private Symbol var; // // public NonTerminal(Position pos, Symbol name, Symbol var) { // super(pos); // this.name = name; // this.var = var; // } // // public NonTerminal(Position pos, Symbol name){ // this(pos, name, null); // } // // public Symbol name() { // return name; // } // // public Symbol var() { // return var; // } // // @Override // public String toString() { // return var != null ? var + ":" + name.toString() : name.toString(); // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // // Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static class Rule extends Node { // public static final int BOUNDED = 1; // private int flags; // private Symbol name; // private Symbol type; // private Expression expression; // private String code; // // public Rule(Position pos, int flags, Symbol name, Symbol type, Expression expression, String code){ // super(pos); // this.flags = flags; // this.name = name; // this.type = type; // this.expression = expression; // this.code = code; // } // // public int flags() { // return flags; // } // // public Symbol name() { // return name; // } // // public Symbol type() { // return type; // } // // public Expression body() { // return expression; // } // // public String code() { // return code; // } // // @Override // public String toString() { // return ((flags & BOUNDED) != 0 ? "bounded " : "") + // name + " = " + expression + " ;"; // } // // @Override // public <R, C> R accept(Visitor<R, C> visitor, C context) { // return visitor.visit(this, context); // } // } // Path: src/main/java/com/github/kmizu/yapp/translator/RuleInliner.java import java.util.ArrayList; import java.util.LinkedHashMap; import com.github.kmizu.yapp.Symbol; import com.github.kmizu.yapp.Ast.Expression; import com.github.kmizu.yapp.Ast.Grammar; import com.github.kmizu.yapp.Ast.NonTerminal; import com.github.kmizu.yapp.Ast.Rule; @Override public Context newContext() { return new Context(); } @Override public Grammar expand(Grammar node, Context context) { context.env = new LinkedHashMap<Symbol, Rule>(); for(Rule rule : node) { context.env.put(rule.name(), rule); } for(Rule rule : node) { context.env.put(rule.name(), expand(rule, context)); } return new Grammar(node.pos(), node.name(), node.macros(), new ArrayList<Rule>(context.env.values())); } @Override public Rule expand(Rule node, Context context) { Expression e = node.body(); context.depth = 0; context.changed = true; while(context.changed && context.depth < inlineLimit){ context.changed = false; e = e.accept(this, context); } return new Rule(node.pos(), node.flags(), node.name(), node.type(), e, node.code()); } @Override
protected Expression visit(NonTerminal node, Context context) {
kmizu/yapp
benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappOptimizedJavaRecognizer.java
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // }
import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.OptimizedJavaRecognizer; import com.github.kmizu.yapp.runtime.Result;
package com.github.kmizu.yapp.benchmark; public class YappOptimizedJavaRecognizer implements GenericParser { private OptimizedJavaRecognizer recognizer; public void setInput(Reader input) { recognizer = new OptimizedJavaRecognizer(input); } public Object parse() {
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // } // Path: benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappOptimizedJavaRecognizer.java import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.OptimizedJavaRecognizer; import com.github.kmizu.yapp.runtime.Result; package com.github.kmizu.yapp.benchmark; public class YappOptimizedJavaRecognizer implements GenericParser { private OptimizedJavaRecognizer recognizer; public void setInput(Reader input) { recognizer = new OptimizedJavaRecognizer(input); } public Object parse() {
Result<?> r = recognizer.parse();
kmizu/yapp
benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappJSONRecognizer.java
// Path: src/main/java/com/github/kmizu/yapp/runtime/ParseError.java // public class ParseError { // private final Location location; // private final String message; // // public ParseError(Location location, String message) { // this.location = location; // this.message = message; // } // // public Location getLocation() { // return location; // } // // public int getLine() { // return location.getLine(); // } // // public int getColumn() { // return location.getColumn(); // } // // public String getMessage() { // return message; // } // // public String getErrorMessage() { // StringBuilder builder = new StringBuilder(); // Formatter f = new Formatter(builder); // f.format("%d, %d: %s", location.getLine(), location.getColumn(), message); // f.flush(); // return new String(builder); // } // } // // Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // }
import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.JSONParser; import com.github.kmizu.yapp.benchmark.parser.JavaRecognizer; import com.github.kmizu.yapp.runtime.ParseError; import com.github.kmizu.yapp.runtime.Result;
package com.github.kmizu.yapp.benchmark; public class YappJSONRecognizer implements GenericParser<Object> { private JSONParser recognizer; public YappJSONRecognizer(){ } public void setInput(Reader input) { recognizer = new JSONParser(input); } public Object parse() {
// Path: src/main/java/com/github/kmizu/yapp/runtime/ParseError.java // public class ParseError { // private final Location location; // private final String message; // // public ParseError(Location location, String message) { // this.location = location; // this.message = message; // } // // public Location getLocation() { // return location; // } // // public int getLine() { // return location.getLine(); // } // // public int getColumn() { // return location.getColumn(); // } // // public String getMessage() { // return message; // } // // public String getErrorMessage() { // StringBuilder builder = new StringBuilder(); // Formatter f = new Formatter(builder); // f.format("%d, %d: %s", location.getLine(), location.getColumn(), message); // f.flush(); // return new String(builder); // } // } // // Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // } // Path: benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappJSONRecognizer.java import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.JSONParser; import com.github.kmizu.yapp.benchmark.parser.JavaRecognizer; import com.github.kmizu.yapp.runtime.ParseError; import com.github.kmizu.yapp.runtime.Result; package com.github.kmizu.yapp.benchmark; public class YappJSONRecognizer implements GenericParser<Object> { private JSONParser recognizer; public YappJSONRecognizer(){ } public void setInput(Reader input) { recognizer = new JSONParser(input); } public Object parse() {
Result<?> r = recognizer.parse();
kmizu/yapp
src/main/java/com/github/kmizu/yapp/translator/UnboundedContext.java
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // }
import com.github.kmizu.yapp.Symbol; import com.github.kmizu.yapp.Ast.Expression;
package com.github.kmizu.yapp.translator; public class UnboundedContext { public final Symbol parent;
// Path: src/main/java/com/github/kmizu/yapp/Ast.java // public static abstract class Expression extends Node { // public Expression(Position pos){ // super(pos); // } // } // Path: src/main/java/com/github/kmizu/yapp/translator/UnboundedContext.java import com.github.kmizu.yapp.Symbol; import com.github.kmizu.yapp.Ast.Expression; package com.github.kmizu.yapp.translator; public class UnboundedContext { public final Symbol parent;
public final Expression unboundedExpression;
kmizu/yapp
benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappESLLRecognizer.java
// Path: src/main/java/com/github/kmizu/yapp/runtime/ParseError.java // public class ParseError { // private final Location location; // private final String message; // // public ParseError(Location location, String message) { // this.location = location; // this.message = message; // } // // public Location getLocation() { // return location; // } // // public int getLine() { // return location.getLine(); // } // // public int getColumn() { // return location.getColumn(); // } // // public String getMessage() { // return message; // } // // public String getErrorMessage() { // StringBuilder builder = new StringBuilder(); // Formatter f = new Formatter(builder); // f.format("%d, %d: %s", location.getLine(), location.getColumn(), message); // f.flush(); // return new String(builder); // } // } // // Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // }
import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.ESLLParser; import com.github.kmizu.yapp.benchmark.parser.JSONParser; import com.github.kmizu.yapp.benchmark.parser.JavaRecognizer; import com.github.kmizu.yapp.runtime.ParseError; import com.github.kmizu.yapp.runtime.Result;
package com.github.kmizu.yapp.benchmark; public class YappESLLRecognizer implements GenericParser<Object> { private ESLLParser recognizer; public YappESLLRecognizer(){ } public void setInput(Reader input) { recognizer = new ESLLParser(input); } public Object parse() {
// Path: src/main/java/com/github/kmizu/yapp/runtime/ParseError.java // public class ParseError { // private final Location location; // private final String message; // // public ParseError(Location location, String message) { // this.location = location; // this.message = message; // } // // public Location getLocation() { // return location; // } // // public int getLine() { // return location.getLine(); // } // // public int getColumn() { // return location.getColumn(); // } // // public String getMessage() { // return message; // } // // public String getErrorMessage() { // StringBuilder builder = new StringBuilder(); // Formatter f = new Formatter(builder); // f.format("%d, %d: %s", location.getLine(), location.getColumn(), message); // f.flush(); // return new String(builder); // } // } // // Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // } // Path: benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappESLLRecognizer.java import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.ESLLParser; import com.github.kmizu.yapp.benchmark.parser.JSONParser; import com.github.kmizu.yapp.benchmark.parser.JavaRecognizer; import com.github.kmizu.yapp.runtime.ParseError; import com.github.kmizu.yapp.runtime.Result; package com.github.kmizu.yapp.benchmark; public class YappESLLRecognizer implements GenericParser<Object> { private ESLLParser recognizer; public YappESLLRecognizer(){ } public void setInput(Reader input) { recognizer = new ESLLParser(input); } public Object parse() {
Result<?> r = recognizer.parse();
kmizu/yapp
benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappACESLLRecognizer.java
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // }
import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.ACESLLParser; import com.github.kmizu.yapp.benchmark.parser.ACXMLParser; import com.github.kmizu.yapp.benchmark.parser.OptimizedXMLParser; import com.github.kmizu.yapp.benchmark.parser.XMLParser; import com.github.kmizu.yapp.runtime.Result;
package com.github.kmizu.yapp.benchmark; public class YappACESLLRecognizer implements GenericParser<Object> { private ACESLLParser recognizer; public void setInput(Reader input) { recognizer = new ACESLLParser(input); } public Object parse() {
// Path: src/main/java/com/github/kmizu/yapp/runtime/Result.java // public class Result<T> { // private final int pos; // private final T value; // private final ParseError error; // private final Exception debugInfo; // // @SuppressWarnings(value="unchecked") // public final static Result FAIL = new Result( // -1, null, new ParseError(new Location(0, 0), "default failure object") // ); // // public static Result fail() { // return FAIL; // } // // public Result(int pos, T value){ // this(pos, value, null); // } // // public Result(int pos, T value, ParseError error){ // this(pos, value, error, null); // } // // public Result(int pos, T value, ParseError error, Exception debugInfo){ // this.pos = pos; // this.value = value; // this.error = error; // this.debugInfo = debugInfo; // } // // // public int getPos() { // return pos; // } // // public T getValue() { // return value; // } // // public ParseError getError() { // return error; // } // // public boolean isFailure() { // return error != null; // } // // public boolean isNotFailure() { // return !isFailure(); // } // // public Exception getDebugInfo() { // return debugInfo; // } // } // Path: benchmark/src/main/java/com/github/kmizu/yapp/benchmark/YappACESLLRecognizer.java import java.io.Reader; import com.github.kmizu.yapp.benchmark.parser.ACESLLParser; import com.github.kmizu.yapp.benchmark.parser.ACXMLParser; import com.github.kmizu.yapp.benchmark.parser.OptimizedXMLParser; import com.github.kmizu.yapp.benchmark.parser.XMLParser; import com.github.kmizu.yapp.runtime.Result; package com.github.kmizu.yapp.benchmark; public class YappACESLLRecognizer implements GenericParser<Object> { private ACESLLParser recognizer; public void setInput(Reader input) { recognizer = new ACESLLParser(input); } public Object parse() {
Result<?> r = recognizer.parse();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/SummonerCallback.java
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/Summoner.java // public class Summoner { // public int id; // public String name; // public int profileIconId; // public int summonerLevel; // public long revisionDate; // public String revisionDateStr; // } // // Path: src/yanovski/lol/api/responses/SummonersResponseNotification.java // public class SummonersResponseNotification extends ResponseNotification<List<Summoner>> { // // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import com.google.gson.Gson; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.Summoner; import yanovski.lol.api.responses.SummonersResponseNotification;
package yanovski.lol.api.callbacks; public class SummonerCallback extends GenericCallback<Response> { public SummonerCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/Summoner.java // public class Summoner { // public int id; // public String name; // public int profileIconId; // public int summonerLevel; // public long revisionDate; // public String revisionDateStr; // } // // Path: src/yanovski/lol/api/responses/SummonersResponseNotification.java // public class SummonersResponseNotification extends ResponseNotification<List<Summoner>> { // // } // Path: src/yanovski/lol/api/callbacks/SummonerCallback.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import com.google.gson.Gson; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.Summoner; import yanovski.lol.api.responses.SummonersResponseNotification; package yanovski.lol.api.callbacks; public class SummonerCallback extends GenericCallback<Response> { public SummonerCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
ResponseNotification<List<Summoner>> notification = new SummonersResponseNotification();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/SummonerCallback.java
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/Summoner.java // public class Summoner { // public int id; // public String name; // public int profileIconId; // public int summonerLevel; // public long revisionDate; // public String revisionDateStr; // } // // Path: src/yanovski/lol/api/responses/SummonersResponseNotification.java // public class SummonersResponseNotification extends ResponseNotification<List<Summoner>> { // // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import com.google.gson.Gson; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.Summoner; import yanovski.lol.api.responses.SummonersResponseNotification;
package yanovski.lol.api.callbacks; public class SummonerCallback extends GenericCallback<Response> { public SummonerCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/Summoner.java // public class Summoner { // public int id; // public String name; // public int profileIconId; // public int summonerLevel; // public long revisionDate; // public String revisionDateStr; // } // // Path: src/yanovski/lol/api/responses/SummonersResponseNotification.java // public class SummonersResponseNotification extends ResponseNotification<List<Summoner>> { // // } // Path: src/yanovski/lol/api/callbacks/SummonerCallback.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import com.google.gson.Gson; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.Summoner; import yanovski.lol.api.responses.SummonersResponseNotification; package yanovski.lol.api.callbacks; public class SummonerCallback extends GenericCallback<Response> { public SummonerCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
ResponseNotification<List<Summoner>> notification = new SummonersResponseNotification();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/SummonerCallback.java
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/Summoner.java // public class Summoner { // public int id; // public String name; // public int profileIconId; // public int summonerLevel; // public long revisionDate; // public String revisionDateStr; // } // // Path: src/yanovski/lol/api/responses/SummonersResponseNotification.java // public class SummonersResponseNotification extends ResponseNotification<List<Summoner>> { // // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import com.google.gson.Gson; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.Summoner; import yanovski.lol.api.responses.SummonersResponseNotification;
package yanovski.lol.api.callbacks; public class SummonerCallback extends GenericCallback<Response> { public SummonerCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/Summoner.java // public class Summoner { // public int id; // public String name; // public int profileIconId; // public int summonerLevel; // public long revisionDate; // public String revisionDateStr; // } // // Path: src/yanovski/lol/api/responses/SummonersResponseNotification.java // public class SummonersResponseNotification extends ResponseNotification<List<Summoner>> { // // } // Path: src/yanovski/lol/api/callbacks/SummonerCallback.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import com.google.gson.Gson; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.Summoner; import yanovski.lol.api.responses.SummonersResponseNotification; package yanovski.lol.api.callbacks; public class SummonerCallback extends GenericCallback<Response> { public SummonerCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
ResponseNotification<List<Summoner>> notification = new SummonersResponseNotification();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/SummonerCallback.java
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/Summoner.java // public class Summoner { // public int id; // public String name; // public int profileIconId; // public int summonerLevel; // public long revisionDate; // public String revisionDateStr; // } // // Path: src/yanovski/lol/api/responses/SummonersResponseNotification.java // public class SummonersResponseNotification extends ResponseNotification<List<Summoner>> { // // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import com.google.gson.Gson; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.Summoner; import yanovski.lol.api.responses.SummonersResponseNotification;
BufferedReader br = new BufferedReader(new InputStreamReader(in)); StringBuilder total = new StringBuilder(in.available()); String line; while ((line = br.readLine()) != null) { total.append(line); } JSONObject json = new JSONObject(total.toString()); JSONArray names = json.names(); int length = names.length(); GsonConverter converter = new GsonConverter(new Gson()); List<Summoner> summoners = new ArrayList<Summoner>(); for (int index = 0; index < length; ++index) { String name = names.getString(index); JSONObject current = json.optJSONObject(name); if (null != current) { Summoner s = (Summoner) converter.fromBody(new TypedString(current.toString()), Summoner.class); summoners.add(s); } } notification.data = summoners; } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (ConversionException e) { e.printStackTrace(); }
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/Summoner.java // public class Summoner { // public int id; // public String name; // public int profileIconId; // public int summonerLevel; // public long revisionDate; // public String revisionDateStr; // } // // Path: src/yanovski/lol/api/responses/SummonersResponseNotification.java // public class SummonersResponseNotification extends ResponseNotification<List<Summoner>> { // // } // Path: src/yanovski/lol/api/callbacks/SummonerCallback.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import com.google.gson.Gson; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.Summoner; import yanovski.lol.api.responses.SummonersResponseNotification; BufferedReader br = new BufferedReader(new InputStreamReader(in)); StringBuilder total = new StringBuilder(in.available()); String line; while ((line = br.readLine()) != null) { total.append(line); } JSONObject json = new JSONObject(total.toString()); JSONArray names = json.names(); int length = names.length(); GsonConverter converter = new GsonConverter(new Gson()); List<Summoner> summoners = new ArrayList<Summoner>(); for (int index = 0; index < length; ++index) { String name = names.getString(index); JSONObject current = json.optJSONObject(name); if (null != current) { Summoner s = (Summoner) converter.fromBody(new TypedString(current.toString()), Summoner.class); summoners.add(s); } } notification.data = summoners; } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (ConversionException e) { e.printStackTrace(); }
EventBusManager.post(notification);
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/SimpleLeagueCallback.java
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/League.java // public class League { // public long timestamp; // public String queue; // public String name; // public String tier; // public String participantId; // public List<LeagueItem> entries; // } // // Path: src/yanovski/lol/api/responses/LeagueResponseNotification.java // public class LeagueResponseNotification extends ResponseNotification<League> { // // }
import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.League; import yanovski.lol.api.responses.LeagueResponseNotification;
package yanovski.lol.api.callbacks; public class SimpleLeagueCallback extends GenericCallback<League> { public SimpleLeagueCallback(String requestId) { super(requestId); } @Override
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/League.java // public class League { // public long timestamp; // public String queue; // public String name; // public String tier; // public String participantId; // public List<LeagueItem> entries; // } // // Path: src/yanovski/lol/api/responses/LeagueResponseNotification.java // public class LeagueResponseNotification extends ResponseNotification<League> { // // } // Path: src/yanovski/lol/api/callbacks/SimpleLeagueCallback.java import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.League; import yanovski.lol.api.responses.LeagueResponseNotification; package yanovski.lol.api.callbacks; public class SimpleLeagueCallback extends GenericCallback<League> { public SimpleLeagueCallback(String requestId) { super(requestId); } @Override
protected ResponseNotification<League> createTypedResponse() {
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/SimpleLeagueCallback.java
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/League.java // public class League { // public long timestamp; // public String queue; // public String name; // public String tier; // public String participantId; // public List<LeagueItem> entries; // } // // Path: src/yanovski/lol/api/responses/LeagueResponseNotification.java // public class LeagueResponseNotification extends ResponseNotification<League> { // // }
import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.League; import yanovski.lol.api.responses.LeagueResponseNotification;
package yanovski.lol.api.callbacks; public class SimpleLeagueCallback extends GenericCallback<League> { public SimpleLeagueCallback(String requestId) { super(requestId); } @Override protected ResponseNotification<League> createTypedResponse() {
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/League.java // public class League { // public long timestamp; // public String queue; // public String name; // public String tier; // public String participantId; // public List<LeagueItem> entries; // } // // Path: src/yanovski/lol/api/responses/LeagueResponseNotification.java // public class LeagueResponseNotification extends ResponseNotification<League> { // // } // Path: src/yanovski/lol/api/callbacks/SimpleLeagueCallback.java import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.League; import yanovski.lol.api.responses.LeagueResponseNotification; package yanovski.lol.api.callbacks; public class SimpleLeagueCallback extends GenericCallback<League> { public SimpleLeagueCallback(String requestId) { super(requestId); } @Override protected ResponseNotification<League> createTypedResponse() {
return new LeagueResponseNotification();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/ChampionsCallback.java
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/ChampionList.java // public class ChampionList { // public List<Champion> champions; // } // // Path: src/yanovski/lol/api/responses/ChampionsResponseNotification.java // public class ChampionsResponseNotification extends ResponseNotification<ChampionList> { // // }
import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.ChampionList; import yanovski.lol.api.responses.ChampionsResponseNotification;
package yanovski.lol.api.callbacks; public class ChampionsCallback extends GenericCallback<ChampionList> { public ChampionsCallback(String requestId) { super(requestId); } @Override
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/ChampionList.java // public class ChampionList { // public List<Champion> champions; // } // // Path: src/yanovski/lol/api/responses/ChampionsResponseNotification.java // public class ChampionsResponseNotification extends ResponseNotification<ChampionList> { // // } // Path: src/yanovski/lol/api/callbacks/ChampionsCallback.java import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.ChampionList; import yanovski.lol.api.responses.ChampionsResponseNotification; package yanovski.lol.api.callbacks; public class ChampionsCallback extends GenericCallback<ChampionList> { public ChampionsCallback(String requestId) { super(requestId); } @Override
protected ResponseNotification<ChampionList> createTypedResponse() {
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/ChampionsCallback.java
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/ChampionList.java // public class ChampionList { // public List<Champion> champions; // } // // Path: src/yanovski/lol/api/responses/ChampionsResponseNotification.java // public class ChampionsResponseNotification extends ResponseNotification<ChampionList> { // // }
import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.ChampionList; import yanovski.lol.api.responses.ChampionsResponseNotification;
package yanovski.lol.api.callbacks; public class ChampionsCallback extends GenericCallback<ChampionList> { public ChampionsCallback(String requestId) { super(requestId); } @Override protected ResponseNotification<ChampionList> createTypedResponse() {
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/ChampionList.java // public class ChampionList { // public List<Champion> champions; // } // // Path: src/yanovski/lol/api/responses/ChampionsResponseNotification.java // public class ChampionsResponseNotification extends ResponseNotification<ChampionList> { // // } // Path: src/yanovski/lol/api/callbacks/ChampionsCallback.java import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.ChampionList; import yanovski.lol.api.responses.ChampionsResponseNotification; package yanovski.lol.api.callbacks; public class ChampionsCallback extends GenericCallback<ChampionList> { public ChampionsCallback(String requestId) { super(requestId); } @Override protected ResponseNotification<ChampionList> createTypedResponse() {
return new ChampionsResponseNotification();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/SimpleLeagueEntriesCallback.java
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/LeagueItem.java // public class LeagueItem { // public boolean isFreshBlood; // public boolean isHotStreak; // public boolean isInactive; // public boolean isVeteran; // public long lastPlayed; // public String leagueName; // public int leaguePoints; // public int losses; // public MiniSeries miniSeries; // public String playerOrTeamId; // public String playerOrTeamName; // public String queueType; // public String rank; // public String tier; // public long timeUntilDecay; // public int wins; // } // // Path: src/yanovski/lol/api/responses/LeagueEntriesResponseNotification.java // public class LeagueEntriesResponseNotification extends ResponseNotification<List<LeagueItem>> { // // }
import java.util.List; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.LeagueItem; import yanovski.lol.api.responses.LeagueEntriesResponseNotification;
package yanovski.lol.api.callbacks; public class SimpleLeagueEntriesCallback extends GenericCallback<List<LeagueItem>> { public SimpleLeagueEntriesCallback(String requestId) { super(requestId); } @Override
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/LeagueItem.java // public class LeagueItem { // public boolean isFreshBlood; // public boolean isHotStreak; // public boolean isInactive; // public boolean isVeteran; // public long lastPlayed; // public String leagueName; // public int leaguePoints; // public int losses; // public MiniSeries miniSeries; // public String playerOrTeamId; // public String playerOrTeamName; // public String queueType; // public String rank; // public String tier; // public long timeUntilDecay; // public int wins; // } // // Path: src/yanovski/lol/api/responses/LeagueEntriesResponseNotification.java // public class LeagueEntriesResponseNotification extends ResponseNotification<List<LeagueItem>> { // // } // Path: src/yanovski/lol/api/callbacks/SimpleLeagueEntriesCallback.java import java.util.List; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.LeagueItem; import yanovski.lol.api.responses.LeagueEntriesResponseNotification; package yanovski.lol.api.callbacks; public class SimpleLeagueEntriesCallback extends GenericCallback<List<LeagueItem>> { public SimpleLeagueEntriesCallback(String requestId) { super(requestId); } @Override
protected ResponseNotification<List<LeagueItem>> createTypedResponse() {
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/SimpleLeagueEntriesCallback.java
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/LeagueItem.java // public class LeagueItem { // public boolean isFreshBlood; // public boolean isHotStreak; // public boolean isInactive; // public boolean isVeteran; // public long lastPlayed; // public String leagueName; // public int leaguePoints; // public int losses; // public MiniSeries miniSeries; // public String playerOrTeamId; // public String playerOrTeamName; // public String queueType; // public String rank; // public String tier; // public long timeUntilDecay; // public int wins; // } // // Path: src/yanovski/lol/api/responses/LeagueEntriesResponseNotification.java // public class LeagueEntriesResponseNotification extends ResponseNotification<List<LeagueItem>> { // // }
import java.util.List; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.LeagueItem; import yanovski.lol.api.responses.LeagueEntriesResponseNotification;
package yanovski.lol.api.callbacks; public class SimpleLeagueEntriesCallback extends GenericCallback<List<LeagueItem>> { public SimpleLeagueEntriesCallback(String requestId) { super(requestId); } @Override protected ResponseNotification<List<LeagueItem>> createTypedResponse() {
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/LeagueItem.java // public class LeagueItem { // public boolean isFreshBlood; // public boolean isHotStreak; // public boolean isInactive; // public boolean isVeteran; // public long lastPlayed; // public String leagueName; // public int leaguePoints; // public int losses; // public MiniSeries miniSeries; // public String playerOrTeamId; // public String playerOrTeamName; // public String queueType; // public String rank; // public String tier; // public long timeUntilDecay; // public int wins; // } // // Path: src/yanovski/lol/api/responses/LeagueEntriesResponseNotification.java // public class LeagueEntriesResponseNotification extends ResponseNotification<List<LeagueItem>> { // // } // Path: src/yanovski/lol/api/callbacks/SimpleLeagueEntriesCallback.java import java.util.List; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.LeagueItem; import yanovski.lol.api.responses.LeagueEntriesResponseNotification; package yanovski.lol.api.callbacks; public class SimpleLeagueEntriesCallback extends GenericCallback<List<LeagueItem>> { public SimpleLeagueEntriesCallback(String requestId) { super(requestId); } @Override protected ResponseNotification<List<LeagueItem>> createTypedResponse() {
return new LeagueEntriesResponseNotification();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/GenericCallback.java
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // }
import retrofit.Callback; import retrofit.RetrofitError; import retrofit.client.Response; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification;
package yanovski.lol.api.callbacks; public class GenericCallback<T> implements Callback<T> { private String requestId; public String requestId() { return requestId; } public GenericCallback(String requestId) { this.requestId = requestId; } @Override public void failure(RetrofitError error) {
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // Path: src/yanovski/lol/api/callbacks/GenericCallback.java import retrofit.Callback; import retrofit.RetrofitError; import retrofit.client.Response; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; package yanovski.lol.api.callbacks; public class GenericCallback<T> implements Callback<T> { private String requestId; public String requestId() { return requestId; } public GenericCallback(String requestId) { this.requestId = requestId; } @Override public void failure(RetrofitError error) {
ResponseNotification<T> notification = new ResponseNotification<T>();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/GenericCallback.java
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // }
import retrofit.Callback; import retrofit.RetrofitError; import retrofit.client.Response; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification;
package yanovski.lol.api.callbacks; public class GenericCallback<T> implements Callback<T> { private String requestId; public String requestId() { return requestId; } public GenericCallback(String requestId) { this.requestId = requestId; } @Override public void failure(RetrofitError error) { ResponseNotification<T> notification = new ResponseNotification<T>(); notification.requestId = requestId; notification.error = error;
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // Path: src/yanovski/lol/api/callbacks/GenericCallback.java import retrofit.Callback; import retrofit.RetrofitError; import retrofit.client.Response; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; package yanovski.lol.api.callbacks; public class GenericCallback<T> implements Callback<T> { private String requestId; public String requestId() { return requestId; } public GenericCallback(String requestId) { this.requestId = requestId; } @Override public void failure(RetrofitError error) { ResponseNotification<T> notification = new ResponseNotification<T>(); notification.requestId = requestId; notification.error = error;
EventBusManager.post(notification);
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/TeamsMapCallback.java
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/Team.java // public class Team { // public String createDate; // public String lastGameDate; // public String lastJoinDate; // public String lastJoinedRankedTeamQueueDate; // public List<MatchHistorySummary> matchHistory; // public MessageOfDay messageOfDay; // public String modifyDate; // public String name; // public Roster roster; // public String secondLastJoinDate; // public String status; // public String tag; // public String fullId; // public TeamStatSummary teamStatSummary; // public String thirdLastJoinDate; // public long timestamp; // } // // Path: src/yanovski/lol/api/responses/TeamsResponseNotification.java // public class TeamsResponseNotification extends ResponseNotification<List<Team>> { // // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.Team; import yanovski.lol.api.responses.TeamsResponseNotification; import com.google.gson.Gson;
package yanovski.lol.api.callbacks; public class TeamsMapCallback extends GenericCallback<Response> { public TeamsMapCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/Team.java // public class Team { // public String createDate; // public String lastGameDate; // public String lastJoinDate; // public String lastJoinedRankedTeamQueueDate; // public List<MatchHistorySummary> matchHistory; // public MessageOfDay messageOfDay; // public String modifyDate; // public String name; // public Roster roster; // public String secondLastJoinDate; // public String status; // public String tag; // public String fullId; // public TeamStatSummary teamStatSummary; // public String thirdLastJoinDate; // public long timestamp; // } // // Path: src/yanovski/lol/api/responses/TeamsResponseNotification.java // public class TeamsResponseNotification extends ResponseNotification<List<Team>> { // // } // Path: src/yanovski/lol/api/callbacks/TeamsMapCallback.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.Team; import yanovski.lol.api.responses.TeamsResponseNotification; import com.google.gson.Gson; package yanovski.lol.api.callbacks; public class TeamsMapCallback extends GenericCallback<Response> { public TeamsMapCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
ResponseNotification<List<Team>> notification = new TeamsResponseNotification();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/TeamsMapCallback.java
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/Team.java // public class Team { // public String createDate; // public String lastGameDate; // public String lastJoinDate; // public String lastJoinedRankedTeamQueueDate; // public List<MatchHistorySummary> matchHistory; // public MessageOfDay messageOfDay; // public String modifyDate; // public String name; // public Roster roster; // public String secondLastJoinDate; // public String status; // public String tag; // public String fullId; // public TeamStatSummary teamStatSummary; // public String thirdLastJoinDate; // public long timestamp; // } // // Path: src/yanovski/lol/api/responses/TeamsResponseNotification.java // public class TeamsResponseNotification extends ResponseNotification<List<Team>> { // // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.Team; import yanovski.lol.api.responses.TeamsResponseNotification; import com.google.gson.Gson;
package yanovski.lol.api.callbacks; public class TeamsMapCallback extends GenericCallback<Response> { public TeamsMapCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/Team.java // public class Team { // public String createDate; // public String lastGameDate; // public String lastJoinDate; // public String lastJoinedRankedTeamQueueDate; // public List<MatchHistorySummary> matchHistory; // public MessageOfDay messageOfDay; // public String modifyDate; // public String name; // public Roster roster; // public String secondLastJoinDate; // public String status; // public String tag; // public String fullId; // public TeamStatSummary teamStatSummary; // public String thirdLastJoinDate; // public long timestamp; // } // // Path: src/yanovski/lol/api/responses/TeamsResponseNotification.java // public class TeamsResponseNotification extends ResponseNotification<List<Team>> { // // } // Path: src/yanovski/lol/api/callbacks/TeamsMapCallback.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.Team; import yanovski.lol.api.responses.TeamsResponseNotification; import com.google.gson.Gson; package yanovski.lol.api.callbacks; public class TeamsMapCallback extends GenericCallback<Response> { public TeamsMapCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
ResponseNotification<List<Team>> notification = new TeamsResponseNotification();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/TeamsMapCallback.java
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/Team.java // public class Team { // public String createDate; // public String lastGameDate; // public String lastJoinDate; // public String lastJoinedRankedTeamQueueDate; // public List<MatchHistorySummary> matchHistory; // public MessageOfDay messageOfDay; // public String modifyDate; // public String name; // public Roster roster; // public String secondLastJoinDate; // public String status; // public String tag; // public String fullId; // public TeamStatSummary teamStatSummary; // public String thirdLastJoinDate; // public long timestamp; // } // // Path: src/yanovski/lol/api/responses/TeamsResponseNotification.java // public class TeamsResponseNotification extends ResponseNotification<List<Team>> { // // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.Team; import yanovski.lol.api.responses.TeamsResponseNotification; import com.google.gson.Gson;
package yanovski.lol.api.callbacks; public class TeamsMapCallback extends GenericCallback<Response> { public TeamsMapCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/Team.java // public class Team { // public String createDate; // public String lastGameDate; // public String lastJoinDate; // public String lastJoinedRankedTeamQueueDate; // public List<MatchHistorySummary> matchHistory; // public MessageOfDay messageOfDay; // public String modifyDate; // public String name; // public Roster roster; // public String secondLastJoinDate; // public String status; // public String tag; // public String fullId; // public TeamStatSummary teamStatSummary; // public String thirdLastJoinDate; // public long timestamp; // } // // Path: src/yanovski/lol/api/responses/TeamsResponseNotification.java // public class TeamsResponseNotification extends ResponseNotification<List<Team>> { // // } // Path: src/yanovski/lol/api/callbacks/TeamsMapCallback.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.Team; import yanovski.lol.api.responses.TeamsResponseNotification; import com.google.gson.Gson; package yanovski.lol.api.callbacks; public class TeamsMapCallback extends GenericCallback<Response> { public TeamsMapCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
ResponseNotification<List<Team>> notification = new TeamsResponseNotification();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/TeamsMapCallback.java
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/Team.java // public class Team { // public String createDate; // public String lastGameDate; // public String lastJoinDate; // public String lastJoinedRankedTeamQueueDate; // public List<MatchHistorySummary> matchHistory; // public MessageOfDay messageOfDay; // public String modifyDate; // public String name; // public Roster roster; // public String secondLastJoinDate; // public String status; // public String tag; // public String fullId; // public TeamStatSummary teamStatSummary; // public String thirdLastJoinDate; // public long timestamp; // } // // Path: src/yanovski/lol/api/responses/TeamsResponseNotification.java // public class TeamsResponseNotification extends ResponseNotification<List<Team>> { // // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.Team; import yanovski.lol.api.responses.TeamsResponseNotification; import com.google.gson.Gson;
BufferedReader br = new BufferedReader(new InputStreamReader(in)); StringBuilder total = new StringBuilder(in.available()); String line; while ((line = br.readLine()) != null) { total.append(line); } JSONObject json = new JSONObject(total.toString()); JSONArray names = json.names(); int length = names.length(); GsonConverter converter = new GsonConverter(new Gson()); List<Team> teams = new ArrayList<Team>(); for (int index = 0; index < length; ++index) { String name = names.getString(index); JSONObject current = json.optJSONObject(name); if (null != current) { Team t = (Team) converter.fromBody(new TypedString(current.toString()), Team.class); teams.add(t); } } notification.data = teams; } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (ConversionException e) { e.printStackTrace(); }
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/Team.java // public class Team { // public String createDate; // public String lastGameDate; // public String lastJoinDate; // public String lastJoinedRankedTeamQueueDate; // public List<MatchHistorySummary> matchHistory; // public MessageOfDay messageOfDay; // public String modifyDate; // public String name; // public Roster roster; // public String secondLastJoinDate; // public String status; // public String tag; // public String fullId; // public TeamStatSummary teamStatSummary; // public String thirdLastJoinDate; // public long timestamp; // } // // Path: src/yanovski/lol/api/responses/TeamsResponseNotification.java // public class TeamsResponseNotification extends ResponseNotification<List<Team>> { // // } // Path: src/yanovski/lol/api/callbacks/TeamsMapCallback.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.Team; import yanovski.lol.api.responses.TeamsResponseNotification; import com.google.gson.Gson; BufferedReader br = new BufferedReader(new InputStreamReader(in)); StringBuilder total = new StringBuilder(in.available()); String line; while ((line = br.readLine()) != null) { total.append(line); } JSONObject json = new JSONObject(total.toString()); JSONArray names = json.names(); int length = names.length(); GsonConverter converter = new GsonConverter(new Gson()); List<Team> teams = new ArrayList<Team>(); for (int index = 0; index < length; ++index) { String name = names.getString(index); JSONObject current = json.optJSONObject(name); if (null != current) { Team t = (Team) converter.fromBody(new TypedString(current.toString()), Team.class); teams.add(t); } } notification.data = teams; } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (ConversionException e) { e.printStackTrace(); }
EventBusManager.post(notification);
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/RecentGamesCallback.java
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/RecentGames.java // public class RecentGames { // public long summonerId; // public List<Game> games; // } // // Path: src/yanovski/lol/api/responses/RecentGamesResponseNotification.java // public class RecentGamesResponseNotification extends ResponseNotification<RecentGames> { // // }
import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.RecentGames; import yanovski.lol.api.responses.RecentGamesResponseNotification;
package yanovski.lol.api.callbacks; public class RecentGamesCallback extends GenericCallback<RecentGames> { public RecentGamesCallback(String requestId) { super(requestId); } @Override
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/RecentGames.java // public class RecentGames { // public long summonerId; // public List<Game> games; // } // // Path: src/yanovski/lol/api/responses/RecentGamesResponseNotification.java // public class RecentGamesResponseNotification extends ResponseNotification<RecentGames> { // // } // Path: src/yanovski/lol/api/callbacks/RecentGamesCallback.java import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.RecentGames; import yanovski.lol.api.responses.RecentGamesResponseNotification; package yanovski.lol.api.callbacks; public class RecentGamesCallback extends GenericCallback<RecentGames> { public RecentGamesCallback(String requestId) { super(requestId); } @Override
protected ResponseNotification<RecentGames> createTypedResponse() {
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/RecentGamesCallback.java
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/RecentGames.java // public class RecentGames { // public long summonerId; // public List<Game> games; // } // // Path: src/yanovski/lol/api/responses/RecentGamesResponseNotification.java // public class RecentGamesResponseNotification extends ResponseNotification<RecentGames> { // // }
import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.RecentGames; import yanovski.lol.api.responses.RecentGamesResponseNotification;
package yanovski.lol.api.callbacks; public class RecentGamesCallback extends GenericCallback<RecentGames> { public RecentGamesCallback(String requestId) { super(requestId); } @Override protected ResponseNotification<RecentGames> createTypedResponse() {
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/RecentGames.java // public class RecentGames { // public long summonerId; // public List<Game> games; // } // // Path: src/yanovski/lol/api/responses/RecentGamesResponseNotification.java // public class RecentGamesResponseNotification extends ResponseNotification<RecentGames> { // // } // Path: src/yanovski/lol/api/callbacks/RecentGamesCallback.java import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.RecentGames; import yanovski.lol.api.responses.RecentGamesResponseNotification; package yanovski.lol.api.callbacks; public class RecentGamesCallback extends GenericCallback<RecentGames> { public RecentGamesCallback(String requestId) { super(requestId); } @Override protected ResponseNotification<RecentGames> createTypedResponse() {
return new RecentGamesResponseNotification();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/PlayerStatsSummaryCallback.java
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/PlayerStatsSummaryList.java // public class PlayerStatsSummaryList { // public long summonerId; // public List<PlayerStatsSummary> playerStatSummaries; // } // // Path: src/yanovski/lol/api/responses/PlayerStastsSummaryResponseNotification.java // public class PlayerStastsSummaryResponseNotification extends ResponseNotification<PlayerStatsSummaryList> { // // }
import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.PlayerStatsSummaryList; import yanovski.lol.api.responses.PlayerStastsSummaryResponseNotification;
package yanovski.lol.api.callbacks; public class PlayerStatsSummaryCallback extends GenericCallback<PlayerStatsSummaryList> { public PlayerStatsSummaryCallback(String requestId) { super(requestId); } @Override
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/PlayerStatsSummaryList.java // public class PlayerStatsSummaryList { // public long summonerId; // public List<PlayerStatsSummary> playerStatSummaries; // } // // Path: src/yanovski/lol/api/responses/PlayerStastsSummaryResponseNotification.java // public class PlayerStastsSummaryResponseNotification extends ResponseNotification<PlayerStatsSummaryList> { // // } // Path: src/yanovski/lol/api/callbacks/PlayerStatsSummaryCallback.java import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.PlayerStatsSummaryList; import yanovski.lol.api.responses.PlayerStastsSummaryResponseNotification; package yanovski.lol.api.callbacks; public class PlayerStatsSummaryCallback extends GenericCallback<PlayerStatsSummaryList> { public PlayerStatsSummaryCallback(String requestId) { super(requestId); } @Override
protected ResponseNotification<PlayerStatsSummaryList> createTypedResponse() {
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/PlayerStatsSummaryCallback.java
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/PlayerStatsSummaryList.java // public class PlayerStatsSummaryList { // public long summonerId; // public List<PlayerStatsSummary> playerStatSummaries; // } // // Path: src/yanovski/lol/api/responses/PlayerStastsSummaryResponseNotification.java // public class PlayerStastsSummaryResponseNotification extends ResponseNotification<PlayerStatsSummaryList> { // // }
import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.PlayerStatsSummaryList; import yanovski.lol.api.responses.PlayerStastsSummaryResponseNotification;
package yanovski.lol.api.callbacks; public class PlayerStatsSummaryCallback extends GenericCallback<PlayerStatsSummaryList> { public PlayerStatsSummaryCallback(String requestId) { super(requestId); } @Override protected ResponseNotification<PlayerStatsSummaryList> createTypedResponse() {
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/PlayerStatsSummaryList.java // public class PlayerStatsSummaryList { // public long summonerId; // public List<PlayerStatsSummary> playerStatSummaries; // } // // Path: src/yanovski/lol/api/responses/PlayerStastsSummaryResponseNotification.java // public class PlayerStastsSummaryResponseNotification extends ResponseNotification<PlayerStatsSummaryList> { // // } // Path: src/yanovski/lol/api/callbacks/PlayerStatsSummaryCallback.java import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.PlayerStatsSummaryList; import yanovski.lol.api.responses.PlayerStastsSummaryResponseNotification; package yanovski.lol.api.callbacks; public class PlayerStatsSummaryCallback extends GenericCallback<PlayerStatsSummaryList> { public PlayerStatsSummaryCallback(String requestId) { super(requestId); } @Override protected ResponseNotification<PlayerStatsSummaryList> createTypedResponse() {
return new PlayerStastsSummaryResponseNotification();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/SummonerNamesCallback.java
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/SummonerName.java // public class SummonerName { // public long id; // public String name; // } // // Path: src/yanovski/lol/api/models/SummonerNames.java // public class SummonerNames { // public List<SummonerName> summoners; // } // // Path: src/yanovski/lol/api/responses/SummonerNamesResponseNotification.java // public class SummonerNamesResponseNotification extends ResponseNotification<SummonerNames> { // // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.SummonerName; import yanovski.lol.api.models.SummonerNames; import yanovski.lol.api.responses.SummonerNamesResponseNotification;
package yanovski.lol.api.callbacks; public class SummonerNamesCallback extends GenericCallback<Response> { public SummonerNamesCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/SummonerName.java // public class SummonerName { // public long id; // public String name; // } // // Path: src/yanovski/lol/api/models/SummonerNames.java // public class SummonerNames { // public List<SummonerName> summoners; // } // // Path: src/yanovski/lol/api/responses/SummonerNamesResponseNotification.java // public class SummonerNamesResponseNotification extends ResponseNotification<SummonerNames> { // // } // Path: src/yanovski/lol/api/callbacks/SummonerNamesCallback.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.SummonerName; import yanovski.lol.api.models.SummonerNames; import yanovski.lol.api.responses.SummonerNamesResponseNotification; package yanovski.lol.api.callbacks; public class SummonerNamesCallback extends GenericCallback<Response> { public SummonerNamesCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
ResponseNotification<SummonerNames> notification = new SummonerNamesResponseNotification();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/SummonerNamesCallback.java
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/SummonerName.java // public class SummonerName { // public long id; // public String name; // } // // Path: src/yanovski/lol/api/models/SummonerNames.java // public class SummonerNames { // public List<SummonerName> summoners; // } // // Path: src/yanovski/lol/api/responses/SummonerNamesResponseNotification.java // public class SummonerNamesResponseNotification extends ResponseNotification<SummonerNames> { // // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.SummonerName; import yanovski.lol.api.models.SummonerNames; import yanovski.lol.api.responses.SummonerNamesResponseNotification;
package yanovski.lol.api.callbacks; public class SummonerNamesCallback extends GenericCallback<Response> { public SummonerNamesCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/SummonerName.java // public class SummonerName { // public long id; // public String name; // } // // Path: src/yanovski/lol/api/models/SummonerNames.java // public class SummonerNames { // public List<SummonerName> summoners; // } // // Path: src/yanovski/lol/api/responses/SummonerNamesResponseNotification.java // public class SummonerNamesResponseNotification extends ResponseNotification<SummonerNames> { // // } // Path: src/yanovski/lol/api/callbacks/SummonerNamesCallback.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.SummonerName; import yanovski.lol.api.models.SummonerNames; import yanovski.lol.api.responses.SummonerNamesResponseNotification; package yanovski.lol.api.callbacks; public class SummonerNamesCallback extends GenericCallback<Response> { public SummonerNamesCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
ResponseNotification<SummonerNames> notification = new SummonerNamesResponseNotification();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/SummonerNamesCallback.java
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/SummonerName.java // public class SummonerName { // public long id; // public String name; // } // // Path: src/yanovski/lol/api/models/SummonerNames.java // public class SummonerNames { // public List<SummonerName> summoners; // } // // Path: src/yanovski/lol/api/responses/SummonerNamesResponseNotification.java // public class SummonerNamesResponseNotification extends ResponseNotification<SummonerNames> { // // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.SummonerName; import yanovski.lol.api.models.SummonerNames; import yanovski.lol.api.responses.SummonerNamesResponseNotification;
package yanovski.lol.api.callbacks; public class SummonerNamesCallback extends GenericCallback<Response> { public SummonerNamesCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/SummonerName.java // public class SummonerName { // public long id; // public String name; // } // // Path: src/yanovski/lol/api/models/SummonerNames.java // public class SummonerNames { // public List<SummonerName> summoners; // } // // Path: src/yanovski/lol/api/responses/SummonerNamesResponseNotification.java // public class SummonerNamesResponseNotification extends ResponseNotification<SummonerNames> { // // } // Path: src/yanovski/lol/api/callbacks/SummonerNamesCallback.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.SummonerName; import yanovski.lol.api.models.SummonerNames; import yanovski.lol.api.responses.SummonerNamesResponseNotification; package yanovski.lol.api.callbacks; public class SummonerNamesCallback extends GenericCallback<Response> { public SummonerNamesCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
ResponseNotification<SummonerNames> notification = new SummonerNamesResponseNotification();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/SummonerNamesCallback.java
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/SummonerName.java // public class SummonerName { // public long id; // public String name; // } // // Path: src/yanovski/lol/api/models/SummonerNames.java // public class SummonerNames { // public List<SummonerName> summoners; // } // // Path: src/yanovski/lol/api/responses/SummonerNamesResponseNotification.java // public class SummonerNamesResponseNotification extends ResponseNotification<SummonerNames> { // // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.SummonerName; import yanovski.lol.api.models.SummonerNames; import yanovski.lol.api.responses.SummonerNamesResponseNotification;
package yanovski.lol.api.callbacks; public class SummonerNamesCallback extends GenericCallback<Response> { public SummonerNamesCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) { ResponseNotification<SummonerNames> notification = new SummonerNamesResponseNotification(); notification.requestId = requestId(); notification.origin = r; try { InputStream in = r.getBody().in(); BufferedReader br = new BufferedReader(new InputStreamReader(in)); StringBuilder total = new StringBuilder(in.available()); String line; while ((line = br.readLine()) != null) { total.append(line); } JSONObject json = new JSONObject(total.toString()); JSONArray jsonNames = json.names(); int length = jsonNames.length(); SummonerNames summonerNames = new SummonerNames();
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/SummonerName.java // public class SummonerName { // public long id; // public String name; // } // // Path: src/yanovski/lol/api/models/SummonerNames.java // public class SummonerNames { // public List<SummonerName> summoners; // } // // Path: src/yanovski/lol/api/responses/SummonerNamesResponseNotification.java // public class SummonerNamesResponseNotification extends ResponseNotification<SummonerNames> { // // } // Path: src/yanovski/lol/api/callbacks/SummonerNamesCallback.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.SummonerName; import yanovski.lol.api.models.SummonerNames; import yanovski.lol.api.responses.SummonerNamesResponseNotification; package yanovski.lol.api.callbacks; public class SummonerNamesCallback extends GenericCallback<Response> { public SummonerNamesCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) { ResponseNotification<SummonerNames> notification = new SummonerNamesResponseNotification(); notification.requestId = requestId(); notification.origin = r; try { InputStream in = r.getBody().in(); BufferedReader br = new BufferedReader(new InputStreamReader(in)); StringBuilder total = new StringBuilder(in.available()); String line; while ((line = br.readLine()) != null) { total.append(line); } JSONObject json = new JSONObject(total.toString()); JSONArray jsonNames = json.names(); int length = jsonNames.length(); SummonerNames summonerNames = new SummonerNames();
List<SummonerName> n = new ArrayList<SummonerName>();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/SummonerNamesCallback.java
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/SummonerName.java // public class SummonerName { // public long id; // public String name; // } // // Path: src/yanovski/lol/api/models/SummonerNames.java // public class SummonerNames { // public List<SummonerName> summoners; // } // // Path: src/yanovski/lol/api/responses/SummonerNamesResponseNotification.java // public class SummonerNamesResponseNotification extends ResponseNotification<SummonerNames> { // // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.SummonerName; import yanovski.lol.api.models.SummonerNames; import yanovski.lol.api.responses.SummonerNamesResponseNotification;
StringBuilder total = new StringBuilder(in.available()); String line; while ((line = br.readLine()) != null) { total.append(line); } JSONObject json = new JSONObject(total.toString()); JSONArray jsonNames = json.names(); int length = jsonNames.length(); SummonerNames summonerNames = new SummonerNames(); List<SummonerName> n = new ArrayList<SummonerName>(); for (int index = 0; index < length; ++index) { String id = jsonNames.getString(index); String name = json.getString(id); SummonerName sn = new SummonerName(); sn.id = Long.parseLong(id); sn.name = name; n.add(sn); } summonerNames.summoners = n; notification.data = summonerNames; } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); }
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/SummonerName.java // public class SummonerName { // public long id; // public String name; // } // // Path: src/yanovski/lol/api/models/SummonerNames.java // public class SummonerNames { // public List<SummonerName> summoners; // } // // Path: src/yanovski/lol/api/responses/SummonerNamesResponseNotification.java // public class SummonerNamesResponseNotification extends ResponseNotification<SummonerNames> { // // } // Path: src/yanovski/lol/api/callbacks/SummonerNamesCallback.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.SummonerName; import yanovski.lol.api.models.SummonerNames; import yanovski.lol.api.responses.SummonerNamesResponseNotification; StringBuilder total = new StringBuilder(in.available()); String line; while ((line = br.readLine()) != null) { total.append(line); } JSONObject json = new JSONObject(total.toString()); JSONArray jsonNames = json.names(); int length = jsonNames.length(); SummonerNames summonerNames = new SummonerNames(); List<SummonerName> n = new ArrayList<SummonerName>(); for (int index = 0; index < length; ++index) { String id = jsonNames.getString(index); String name = json.getString(id); SummonerName sn = new SummonerName(); sn.id = Long.parseLong(id); sn.name = name; n.add(sn); } summonerNames.summoners = n; notification.data = summonerNames; } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); }
EventBusManager.post(notification);
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/SimpleLeaguesCallback.java
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/League.java // public class League { // public long timestamp; // public String queue; // public String name; // public String tier; // public String participantId; // public List<LeagueItem> entries; // } // // Path: src/yanovski/lol/api/responses/LeaguesResponseNotification.java // public class LeaguesResponseNotification extends ResponseNotification<List<League>> { // // }
import java.util.List; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.League; import yanovski.lol.api.responses.LeaguesResponseNotification;
package yanovski.lol.api.callbacks; public class SimpleLeaguesCallback extends GenericCallback<List<League>> { public SimpleLeaguesCallback(String requestId) { super(requestId); } @Override
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/League.java // public class League { // public long timestamp; // public String queue; // public String name; // public String tier; // public String participantId; // public List<LeagueItem> entries; // } // // Path: src/yanovski/lol/api/responses/LeaguesResponseNotification.java // public class LeaguesResponseNotification extends ResponseNotification<List<League>> { // // } // Path: src/yanovski/lol/api/callbacks/SimpleLeaguesCallback.java import java.util.List; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.League; import yanovski.lol.api.responses.LeaguesResponseNotification; package yanovski.lol.api.callbacks; public class SimpleLeaguesCallback extends GenericCallback<List<League>> { public SimpleLeaguesCallback(String requestId) { super(requestId); } @Override
protected ResponseNotification<List<League>> createTypedResponse() {
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/SimpleLeaguesCallback.java
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/League.java // public class League { // public long timestamp; // public String queue; // public String name; // public String tier; // public String participantId; // public List<LeagueItem> entries; // } // // Path: src/yanovski/lol/api/responses/LeaguesResponseNotification.java // public class LeaguesResponseNotification extends ResponseNotification<List<League>> { // // }
import java.util.List; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.League; import yanovski.lol.api.responses.LeaguesResponseNotification;
package yanovski.lol.api.callbacks; public class SimpleLeaguesCallback extends GenericCallback<List<League>> { public SimpleLeaguesCallback(String requestId) { super(requestId); } @Override protected ResponseNotification<List<League>> createTypedResponse() {
// Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/League.java // public class League { // public long timestamp; // public String queue; // public String name; // public String tier; // public String participantId; // public List<LeagueItem> entries; // } // // Path: src/yanovski/lol/api/responses/LeaguesResponseNotification.java // public class LeaguesResponseNotification extends ResponseNotification<List<League>> { // // } // Path: src/yanovski/lol/api/callbacks/SimpleLeaguesCallback.java import java.util.List; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.League; import yanovski.lol.api.responses.LeaguesResponseNotification; package yanovski.lol.api.callbacks; public class SimpleLeaguesCallback extends GenericCallback<List<League>> { public SimpleLeaguesCallback(String requestId) { super(requestId); } @Override protected ResponseNotification<List<League>> createTypedResponse() {
return new LeaguesResponseNotification();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/LeaguesCallback.java
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/League.java // public class League { // public long timestamp; // public String queue; // public String name; // public String tier; // public String participantId; // public List<LeagueItem> entries; // } // // Path: src/yanovski/lol/api/responses/LeaguesResponseNotification.java // public class LeaguesResponseNotification extends ResponseNotification<List<League>> { // // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.League; import yanovski.lol.api.responses.LeaguesResponseNotification; import com.google.gson.Gson;
package yanovski.lol.api.callbacks; public class LeaguesCallback extends GenericCallback<Response> { public LeaguesCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/League.java // public class League { // public long timestamp; // public String queue; // public String name; // public String tier; // public String participantId; // public List<LeagueItem> entries; // } // // Path: src/yanovski/lol/api/responses/LeaguesResponseNotification.java // public class LeaguesResponseNotification extends ResponseNotification<List<League>> { // // } // Path: src/yanovski/lol/api/callbacks/LeaguesCallback.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.League; import yanovski.lol.api.responses.LeaguesResponseNotification; import com.google.gson.Gson; package yanovski.lol.api.callbacks; public class LeaguesCallback extends GenericCallback<Response> { public LeaguesCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
ResponseNotification<List<League>> notification = new LeaguesResponseNotification();
samuil-yanovski/lol-api-library
src/yanovski/lol/api/callbacks/LeaguesCallback.java
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/League.java // public class League { // public long timestamp; // public String queue; // public String name; // public String tier; // public String participantId; // public List<LeagueItem> entries; // } // // Path: src/yanovski/lol/api/responses/LeaguesResponseNotification.java // public class LeaguesResponseNotification extends ResponseNotification<List<League>> { // // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.League; import yanovski.lol.api.responses.LeaguesResponseNotification; import com.google.gson.Gson;
package yanovski.lol.api.callbacks; public class LeaguesCallback extends GenericCallback<Response> { public LeaguesCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
// Path: src/yanovski/lol/api/messages/EventBusManager.java // public class EventBusManager { // private static Bus bus; // // public synchronized static Bus getInstance() { // if (null == bus) { // bus = new Bus(); // } // // return bus; // } // // public static void post(Object message) { // Bus instance = getInstance(); // instance.post(message); // } // // public static void register(Object listener) { // Bus instance = getInstance(); // instance.register(listener); // } // // public static void unregister(Object listener) { // Bus instance = getInstance(); // instance.unregister(listener); // } // } // // Path: src/yanovski/lol/api/messages/ResponseNotification.java // public class ResponseNotification<T> { // public String requestId; // public T data; // public Response origin; // public RetrofitError error; // } // // Path: src/yanovski/lol/api/models/League.java // public class League { // public long timestamp; // public String queue; // public String name; // public String tier; // public String participantId; // public List<LeagueItem> entries; // } // // Path: src/yanovski/lol/api/responses/LeaguesResponseNotification.java // public class LeaguesResponseNotification extends ResponseNotification<List<League>> { // // } // Path: src/yanovski/lol/api/callbacks/LeaguesCallback.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit.client.Response; import retrofit.converter.ConversionException; import retrofit.converter.GsonConverter; import retrofit.mime.TypedString; import yanovski.lol.api.messages.EventBusManager; import yanovski.lol.api.messages.ResponseNotification; import yanovski.lol.api.models.League; import yanovski.lol.api.responses.LeaguesResponseNotification; import com.google.gson.Gson; package yanovski.lol.api.callbacks; public class LeaguesCallback extends GenericCallback<Response> { public LeaguesCallback(String requestId) { super(requestId); } @Override public void success(Response r, Response response) {
ResponseNotification<List<League>> notification = new LeaguesResponseNotification();