You can use JDT to parse and analyze source.
That's scala example. It's easy to do the same with java:
val str = "..." // Checking source code
val parser : ASTParser = ASTParser.newParser(org.eclipse.jdt.core.dom.AST.JLS3)
val options = JavaCore.getOptions.asInstanceOf[java.util.Map[Object, Object]]
options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7)
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7)
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7)
parser.setCompilerOptions(options)
parser.setSource(str.toCharArray)
val cu: CompilationUnit = parser.createAST(null).asInstanceOf[CompilationUnit]
CompilationUnit has method getProblems(). It returns list of detailed problem reports.