public SourceCode sourceCodeFor(Reader reader, String sourceCodeName) { return new SourceCode(new SourceCode.ReaderCodeLoader(reader, sourceCodeName)); }
public SourceCode sourceCodeFor(File file) { return new SourceCode(new SourceCode.FileCodeLoader(file, getSourceEncoding().name())); }
public List<TokensLine> chunk(String fileName, Reader fileReader) { SourceCode sourceCode = new SourceCode(new FileCodeLoaderWithoutCache(fileName, fileReader)); Tokens tokens = new Tokens(); TokenEntry.clearImages(); try { tokenizer.tokenize(sourceCode, tokens); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } TokenEntry.clearImages(); return convert(tokens.getTokens()); }
public SourceCode(URL pageURL) throws IOException { this.source = getSource(pageURL); } public String getSource() { return source; } private String getSource(URL url) throws IOException { URLConnection spoof = url.openConnection(); StringBuffer sb = new StringBuffer(); spoof.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)"); BufferedReader in = new BufferedReader(new InputStreamReader( spoof.getInputStream())); String strLine = ""; while ((strLine = in.readLine()) != null) { sb.append(strLine); } return sb.toString(); } public static void main(String[] args) throws IOException { SourceCode s = new SourceCode(new URL("https://www.google.co.in/")); System.out.println(s.getSource()); }
public static Class<?> compile(ClassLoader parent, String className, String sourceCodeInText) throws Exception { SourceCode sourceCode = new SourceCode(className, sourceCodeInText); CompiledCode compiledCode = new CompiledCode(className); Iterable<? extends JavaFileObject> compilationUnits = Arrays.asList(sourceCode); DynamicClassLoader cl = new DynamicClassLoader(parent); ExtendedStandardJavaFileManager fileManager = new ExtendedStandard( javac.getStandardFileManager(null, null, null), compiledCode, cl); // set the classpath List<String> options = new ArrayList<String>(); options.add("-classpath"); StringBuilder sb = new StringBuilder(); Enumeration<URL> resources = parent.getResources("/"); while (resources.hasMoreElements()) { URL url = resources.nextElement(); sb.append(url.getFile()).append(File.pathSeparator); } options.add(sb.toString()); // execute the compiler Boolean call = javac.getTask(null, fileManager, null, options, null, compilationUnits).call(); if (call) { return cl.loadClass(className); } return null; }
public SourceCode sourceCodeFor(Reader reader, String sourceCodeName) { return new SourceCode(new SourceCode.ReaderCodeLoader(reader, sourceCodeName)); }
public SourceCode sourceCodeFor(File file) { return new SourceCode(new SourceCode.FileCodeLoader(file, getSourceEncoding().name())); }
public List<TokensLine> chunk(File file) { SourceCode sourceCode = new SourceCode(new FileCodeLoaderWithoutCache(file, encoding)); Tokens tokens = new Tokens(); TokenEntry.clearImages(); try { tokenizer.tokenize(sourceCode, tokens); } catch (IOException e) { throw Throwables.propagate(e); } TokenEntry.clearImages(); return convert(tokens.getTokens()); }