use of com.github.javaparser.ParserConfiguration in project javaparser by javaparser.
the class CommentParsingSteps method givenTheClassWithEncoding.
@When("read sample \"$sampleName\" using encoding \"$encoding\"")
public void givenTheClassWithEncoding(String sampleName, String encoding) throws IOException {
sourceUnderTest = null;
ParseResult<CompilationUnit> parseResult = new JavaParser(new ParserConfiguration()).parse(COMPILATION_UNIT, provider(getSampleStream(sampleName), Charset.forName(encoding)));
commentsCollection = parseResult.getCommentsCollection().orElse(new CommentsCollection());
}
use of com.github.javaparser.ParserConfiguration in project javaparser by javaparser.
the class JavaParserAPIIntegrationTest method parameterDeclarationResolve.
@Test
public void parameterDeclarationResolve() throws IOException {
File f = adaptPath(new File("src/test/test_sourcecode/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();
}
use of com.github.javaparser.ParserConfiguration in project javaparser by javaparser.
the class JavaParserAPIIntegrationTest method parseWithSymbolResolution.
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();
}
use of com.github.javaparser.ParserConfiguration in project javaparser by javaparser.
the class Issue1364 method setup.
@Before
public void setup() {
ClassOrInterfaceDeclaration fakeObject = new ClassOrInterfaceDeclaration();
fakeObject.setName(new SimpleName("java.lang.Object"));
TypeSolver typeSolver = new TypeSolver() {
@Override
public TypeSolver getParent() {
return null;
}
@Override
public void setParent(TypeSolver parent) {
}
@Override
public SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveType(String name) {
if ("java.lang.Object".equals(name)) {
// custom handling
return SymbolReference.solved(new JavaParserClassDeclaration(fakeObject, this));
}
return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class);
}
};
ParserConfiguration config = new ParserConfiguration();
config.setSymbolResolver(new JavaSymbolSolver(typeSolver));
javaParser = new JavaParser(config);
}
use of com.github.javaparser.ParserConfiguration in project javaparser by javaparser.
the class TypeTest method primitiveTypeArgumentLenientValidator.
@Test
public void primitiveTypeArgumentLenientValidator() {
ParserConfiguration config = new ParserConfiguration().setLanguageLevel(RAW);
config.getPostProcessors().add(new Java5Validator() {
{
remove(noPrimitiveGenericArguments);
}
}.postProcessor());
ParseResult<VariableDeclarationExpr> result = new JavaParser(config).parse(VARIABLE_DECLARATION_EXPR, provider("List<long> x"));
assertTrue(result.isSuccessful());
VariableDeclarationExpr decl = result.getResult().get();
assertEquals("List<long>", decl.getVariable(0).getType().asString());
}
Aggregations