本文整理了Java中com.github.javaparser.JavaParser.<init>()
方法的一些代码示例,展示了JavaParser.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JavaParser.<init>()
方法的具体详情如下:
包路径:com.github.javaparser.JavaParser
类名称:JavaParser
方法名:<init>
暂无
代码示例来源:origin: stackoverflow.com
public static void main(String... args) throws NoSuchFieldException, IllegalAccessException, IOException, RecognitionException {
JavaLexer lexer = new JavaLexer(new ANTLRFileStream(args[1], "UTF-8"));
JavaParser parser = new JavaParser(new CommonTokenStream(lexer));
CommonTree tree = (CommonTree)(parser.javaSource().getTree());
int type = ((Integer)(JavaParser.class.getDeclaredField(args[0]).get(null))).intValue();
代码示例来源:origin: stackoverflow.com
if (extension.equals("py")) {
return new PythonParser();
}
else if(extension.equals("java")) {
return new JavaParser();
}
else ...
代码示例来源:origin: com.github.javaparser/javaparser-symbol-solver-core
public JavaParserTypeSolver(Path srcDir, ParserConfiguration parserConfiguration) {
if (!Files.exists(srcDir) || !Files.isDirectory(srcDir)) {
throw new IllegalStateException("SrcDir does not exist or is not a directory: " + srcDir);
}
this.srcDir = srcDir;
javaParser = new JavaParser(parserConfiguration);
}
代码示例来源:origin: stackoverflow.com
public Parser getParser(String filename) {
String extension = filename.substring(filename.lastIndexOf("."));
if( "py".equals(extension) ) { return new PythonParser() }
if( "java".equals(extension)) { return new JavaParser(); }
if( "c".equals(extension) ) { return new CParser(); }
return new TextParser();
}
代码示例来源:origin: stackoverflow.com
final JavaParser parser = new JavaParser(new CommonTokenStream(lexer));
final List<String> variables = new ArrayList<>();
代码示例来源:origin: stackoverflow.com
/**
* Returns the number of variable declarations inside the given method, by parsing the method's AST
* @param method The method text
*/
private int countVariableDeclarations(String method) {
JavaLexer lex = new JavaLexer(new ANTLRInputStream(method));
JavaParser parse = new JavaParser(new CommonTokenStream(lex));
ParseTree tree = parse.methodDeclaration();
ParseTreeWalker walker = new ParseTreeWalker();
final AtomicInteger count = new AtomicInteger();
walker.walk(new JavaBaseListener() {
@Override public void enterLocalVariableDeclaration(JavaParser.LocalVariableDeclarationContext ctx) {
count.incrementAndGet();
}
}, tree);
return count.get();
}
代码示例来源:origin: stackoverflow.com
import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
import org.antlr.stringtemplate.*;
public class Main {
public static void main(String[] args) throws Exception {
JavaLexer lexer = new JavaLexer(new ANTLRFileStream("Test.java"));
JavaParser parser = new JavaParser(new CommonTokenStream(lexer));
CommonTree tree = (CommonTree)parser.javaSource().getTree();
DOTTreeGenerator gen = new DOTTreeGenerator();
StringTemplate st = gen.toDOT(tree);
System.out.println(st);
}
}
代码示例来源:origin: stackoverflow.com
JavaParser parser = new JavaParser(new CommonTokenStream(lexer));
代码示例来源:origin: stackoverflow.com
public static void main(String... args) throws IOException {
JavaLexer lexer = new JavaLexer(new ANTLRFileStream(sourceFile, "UTF-8"));
JavaParser parser = new JavaParser(new CommonTokenStream(lexer));
ParseTree tree = parser.compilationUnit();
ParseTreeWalker walker = new ParseTreeWalker();
MyListener listener = new MyListener();
walker.walk(listener, tree);
}
代码示例来源:origin: io.github.udaychandra.susel/susel-gradle-plugin
public ModuleNameParser(File sourceFolder) {
this.sourceFolder = sourceFolder;
this.javaParser = new JavaParser(new ParserConfiguration()
// Let's use the LTS version of Java that supports "module-info" at the time of this writing.
.setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_11));
}
代码示例来源:origin: stackoverflow.com
enum Type { JAVA, PYTHON, CPP, C, PERL };
Type getType(String filename)
{
// do your if chain here
return JAVA;
}
public Parser getParser(String filename)
{
switch(getType(filename))
{
case PYTHON: return new PythonParser();
case JAVA: return new JavaParser();
case C: return new CParser();
default: return new TextParser();
}
}
代码示例来源:origin: gradle.plugin.rgoldberg/java-modules
private JavaParser newJavaParser(final JavaCompile javaCompile) {
return new JavaParser(new ParserConfiguration().setLanguageLevel(getLanguageLevel(javaCompile)));
}
代码示例来源:origin: javaparser/javasymbolsolver
private CompilationUnit parseWithSymbolResolution(File f) throws IOException {
ParserConfiguration parserConfiguration = new ParserConfiguration();
parserConfiguration.setSymbolResolver(new JavaSymbolSolver(typeSolver));
return new JavaParser(parserConfiguration).parse(ParseStart.COMPILATION_UNIT, new StreamProvider(new FileInputStream(f))).getResult().get();
}
代码示例来源:origin: javaparser/javasymbolsolver
@Test
public void parameterDeclarationResolve() throws IOException {
File f = adaptPath(new File("src/test/resources/javaparser_new_src/javaparser-core/com/github/javaparser/ast/CompilationUnit.java"));
ParserConfiguration parserConfiguration = new ParserConfiguration();
parserConfiguration.setSymbolResolver(new JavaSymbolSolver(typeSolver));
CompilationUnit cu = new JavaParser(parserConfiguration).parse(ParseStart.COMPILATION_UNIT, new StreamProvider(new FileInputStream(f))).getResult().get();
ClassOrInterfaceDeclaration classDeclaration = (ClassOrInterfaceDeclaration) cu.getType(0);
assertEquals("CompilationUnit", classDeclaration.getNameAsString());
MethodDeclaration methodDeclaration = classDeclaration.getMethodsByName("setComments").get(0);
Parameter declaration = methodDeclaration.getParameter(0);
ResolvedParameterDeclaration resolvedDeclaration = declaration.resolve();
}
代码示例来源:origin: javaparser/javasymbolsolver
@Test
public void annotationMemberDeclarationResolve() throws IOException {
File f = adaptPath(new File("src/test/resources/Annotations.java.txt"));
ParserConfiguration parserConfiguration = new ParserConfiguration();
parserConfiguration.setSymbolResolver(new JavaSymbolSolver(typeSolver));
CompilationUnit cu = new JavaParser(parserConfiguration).parse(ParseStart.COMPILATION_UNIT, new StreamProvider(new FileInputStream(f))).getResult().get();
AnnotationDeclaration declaration = (AnnotationDeclaration)cu.getType(2);
assertEquals("MyAnnotationWithFields", declaration.getNameAsString());
AnnotationMemberDeclaration memberDeclaration = (AnnotationMemberDeclaration)declaration.getMember(0);
ResolvedAnnotationMemberDeclaration resolvedDeclaration = memberDeclaration.resolve();
}
代码示例来源:origin: javaparser/javasymbolsolver
private CompilationUnit parseWithTypeSolver(String code) {
TypeSolver typeSolver = new ReflectionTypeSolver();
ParserConfiguration parserConfiguration = new ParserConfiguration();
parserConfiguration.setSymbolResolver(new JavaSymbolSolver(typeSolver));
JavaParser javaParser = new JavaParser(parserConfiguration);
return javaParser.parse(ParseStart.COMPILATION_UNIT, new StringProvider(code)).getResult().get();
}
内容来源于网络,如有侵权,请联系作者删除!