//step1:擷取ICompilationUnit IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();IProject project = root.getProject("test");try {project.open(null /* IProgressMonitor */);} catch (CoreException e) {// TODO Auto-generated catch blocke.printStackTrace();} IJavaProject javaProject = JavaCore.create(project);IType lwType = null;try {lwType = javaProject.findType("net.chenxs.Test");} catch (JavaModelException e) {e.printStackTrace();}//step2:提取JavaDocICompilationUnit lwCompilationUnit = lwType.getCompilationUnit(); try {SourceType type = (SourceType) lwCompilationUnit.getAllTypes()[0];IBuffer buffer = lwCompilationUnit.getBuffer();IMethod[] methods = type.getMethods();IBuffer buffer1 = lwCompilationUnit.getBuffer();for(int i=0; i<methods.length;i++){IMethod method =methods[i];ISourceRange range = method.getJavadocRange();//擷取JavaDoc的範圍區間if(range != null){System.out.println(range.getOffset() + " " + range.getLength());System.out.println(buffer1.getText(range.getOffset(),range.getLength()));;}}} catch (JavaModelException e) {e.printStackTrace();}註:通過ast也是可以的;ASTParser astParser = ASTParser.newParser(AST.JLS3);astParser.setKind(ASTParser.K_COMPILATION_UNIT);astParser.setSource(lwCompilationUnit);CompilationUnit unit = (CompilationUnit) astParser.createAST(null);TypeDeclaration type = (TypeDeclaration) unit.types().get(0);MethodDeclaration[] methods = type.getMethods();for(int i=0; i<methods.length;i++){ MethodDeclaration method = methods[i]; Javadoc doc = method.getJavadoc(); if(doc != null){System.out.println(doc); }}