コード例 #1
0
 /**
  * Scans the specified source {@linkplain CompilationUnit} for contributed API javadoc tags. Tags
  * on methods will have unresolved signatures.
  *
  * @param source the source file to scan for tags
  * @param description the API description to annotate with any new tag rules found
  * @param container optional class file container containing the class file for the given source
  *     that can be used to resolve method signatures if required (for tags on methods). If not
  *     provided (<code>null</code>), method signatures will be unresolved.
  * @param options a map of Java compiler options to use when creating the AST to scan or <code>
  *     null</code> if default options should be used
  * @param monitor
  * @throws CoreException
  */
 public void scan(
     CompilationUnit source,
     IApiDescription description,
     IApiTypeContainer container,
     Map options,
     IProgressMonitor monitor)
     throws CoreException {
   SubMonitor localmonitor = SubMonitor.convert(monitor, 2);
   ASTParser parser = ASTParser.newParser(AST.JLS3);
   InputStream inputStream = null;
   try {
     inputStream = source.getInputStream();
     parser.setSource(
         Util.getInputStreamAsCharArray(
             inputStream, -1, System.getProperty("file.encoding"))); // $NON-NLS-1$
   } catch (FileNotFoundException e) {
     throw new CoreException(
         new Status(
             IStatus.ERROR,
             ApiPlugin.PLUGIN_ID,
             MessageFormat.format(
                 "Compilation unit source not found: {0}", new String[] {source.getName()}),
             e)); //$NON-NLS-1$
   } catch (IOException e) {
     if (DEBUG) {
       System.err.println(source.getName());
     }
     throw new CoreException(
         new Status(
             IStatus.ERROR,
             ApiPlugin.PLUGIN_ID,
             MessageFormat.format(
                 "Error reading compilation unit: {0}", new String[] {source.getName()}),
             e)); //$NON-NLS-1$
   } finally {
     if (inputStream != null) {
       try {
         inputStream.close();
       } catch (IOException e) {
         ApiPlugin.log(e);
       }
     }
   }
   Util.updateMonitor(localmonitor);
   Map loptions = options;
   if (loptions == null) {
     loptions = JavaCore.getOptions();
   }
   loptions.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
   parser.setCompilerOptions(loptions);
   org.eclipse.jdt.core.dom.CompilationUnit cunit =
       (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(localmonitor.newChild(1));
   Visitor visitor = new Visitor(description, container);
   cunit.accept(visitor);
   if (visitor.getException() != null) {
     throw visitor.getException();
   }
 }