org.eclipse.pde.api.tools_1.0.301.v20111129-2053

     1);
    }
  }
  
  public void doneSaving(ISaveContext context) {}
  
  public void prepareToSave(ISaveContext context)
    throws CoreException
  {}
  
  public void rollback(ISaveContext context) {}
  
  public synchronized void saving(ISaveContext context)
    throws CoreException
  {
    Iterator entries = fDescriptions.entrySet().iterator();
    while (entries.hasNext())
    {
      Map.Entry entry = (Map.Entry)entries.next();
      IJavaProject project = (IJavaProject)entry.getKey();
      ProjectApiDescription desc = (ProjectApiDescription)entry.getValue();
      if (desc.isModified())
      {
        File dir = API_DESCRIPTIONS_CONTAINER_PATH.append(project.getElementName()).toFile();
        dir.mkdirs();
        String xml = desc.getXML();
        try
        {
          Util.saveFile(new File(dir, ".api_description"), xml);
        }
        catch (IOException e)
        {
          abort(MessageFormat.format(ScannerMessages.ApiDescriptionManager_0, new String[] { project.getElementName() }), e);
        }
      }
    }
  }
  
  private boolean restoreDescription(IJavaProject project, ProjectApiDescription description)
    throws CoreException
  {
    File file = API_DESCRIPTIONS_CONTAINER_PATH.append(project.getElementName())
      .append(".api_description").toFile();
    if (file.exists())
    {
      BufferedInputStream stream = null;
      try
      {
        stream = new BufferedInputStream(new FileInputStream(file));
        String xml = new String(Util.getInputStreamAsCharArray(stream, -1, "UTF-8"));
        Element root = Util.parseDocument(xml);
        if (!root.getNodeName().equals("component")) {
          abort(ScannerMessages.ComponentXMLScanner_0, null);
        }
        long timestamp = getLong(root, "modificationStamp");
        String version = root.getAttribute("version");
        description.setEmbeddedVersion(version);
        if ("1.2".equals(version))
        {
          fPackageTimeStamp = timestamp;
          fManifestFile = project.getProject().getFile("META-INF/MANIFEST.MF");
          restoreChildren(description, root, null, fPackageMap);
          return true;
        }
      }
      catch (IOException e)
      {
        abort(MessageFormat.format(ScannerMessages.ApiDescriptionManager_1, 
          new String[] { project.getElementName() }), e);
      }
      finally
      {
        if (stream != null) {
          try
          {
            stream.close();
          }
          catch (IOException localIOException3) {}
        }
      }
      if (stream != null) {
        try
        {
          stream.close();
        }
        catch (IOException localIOException4) {}
      }
    }
    return false;
  }
  
  private void restoreChildren(ProjectApiDescription apiDesc, Element element, ApiDescription.ManifestNode parentNode, Map childrenMap)
    throws CoreException
  {
    NodeList children = element.getChildNodes();
    for (int i = 0; i < children.getLength(); i++)
    {
      Node child = children.item(i);
      if (child.getNodeType() == 1) {
        restoreNode(apiDesc, (Element)child, parentNode, childrenMap);
      }
    }
  }
  
  private void restoreNode(ProjectApiDescription apiDesc, Element element, ApiDescription.ManifestNode parentNode, Map childrenMap)
    throws CoreException
  {
    ApiDescription.ManifestNode node = null;
    IElementDescriptor elementDesc = null;
    if (element.getTagName().equals("package"))
    {
      int vis = getInt(element, "visibility");
      int res = getInt(element, "restrictions");
      
      List fragments = new ArrayList();
      NodeList childNodes = element.getChildNodes();
      String pkgName = null;
      for (int i = 0; i < childNodes.getLength(); i++)
      {
        Node child = childNodes.item(i);
        if ((child.getNodeType() == 1) && 
          (((Element)child).getTagName().equals("fragment")))
        {
          Element fragment = (Element)child;
          String handle = fragment.getAttribute("handle");
          IJavaElement je = JavaCore.create(handle);
          if (je.getElementType() != 4) {
            abort(ScannerMessages.ApiDescriptionManager_2 + handle, null);
          }
          pkgName = je.getElementName();
          fragments.add(je);
        }
      }
      if (!fragments.isEmpty())
      {
        elementDesc = Factory.packageDescriptor(pkgName);
        node = apiDesc.newPackageNode((IPackageFragment[])fragments.toArray(new IPackageFragment[fragments.size()]), parentNode, elementDesc, vis, res);
      }
      else
      {
        abort(ScannerMessages.ApiDescriptionManager_2, null);
      }
    }
    else
    {
      if (element.getTagName().equals("fragment")) {
        return;
      }
      if (element.getTagName().equals("type"))
      {
        String handle = element.getAttribute("handle");
        int vis = getInt(element, "visibility");
        int res = getInt(element, "restrictions");
        IJavaElement je = JavaCore.create(handle);
        if (je.getElementType() != 7) {
          abort(ScannerMessages.ApiDescriptionManager_3 + handle, null);
        }
        IType type = (IType)je;
        elementDesc = Factory.typeDescriptor(type.getFullyQualifiedName('$'));
        ProjectApiDescription.TypeNode tn = apiDesc.newTypeNode(type, parentNode, elementDesc, vis, res);
        node = tn;
        fTimeStamp = getLong(element, "modificationStamp");
      }
      else if (element.getTagName().equals("field"))
      {
        if ((element instanceof IReferenceTypeDescriptor))
        {
          IReferenceTypeDescriptor type = (IReferenceTypeDescriptor)element;
          int vis = getInt(element, "visibility");
          int res = getInt(element, "restrictions");
          String name = element.getAttribute("name");
          elementDesc = type.getField(name);
          node = apiDesc.newNode(parentNode, elementDesc, vis, res);
        }
      }
      else if ((element.getTagName().equals("method")) && 
        ((element instanceof IReferenceTypeDescriptor)))
      {
        IReferenceTypeDescriptor type = (IReferenceTypeDescriptor)element;
        int vis = getInt(element, "visibility");
        int res = getInt(element, "restrictions");
        String name = element.getAttribute("name");
        String sig = element.getAttribute("signature");
        if (sig.indexOf('.') != -1) {
          sig = sig.replace('.', '/');
        }
        elementDesc = type.getMethod(name, sig);
        node = apiDesc.newNode(parentNode, elementDesc, vis, res);
      }
    }
    if (node == null) {
      abort(ScannerMessages.ApiDescriptionManager_4, null);
    }
    childrenMap.put(elementDesc, node);
    restoreChildren(apiDesc, element, node, children);
  }
  
  private int getInt(Element element, String attr)
  {
    String attribute = element.getAttribute(attr);
    try
    {
      return Integer.parseInt(attribute);
    }
    catch (NumberFormatException localNumberFormatException) {}
    return 0;
  }
  
  private long getLong(Element element, String attr)
  {
    String attribute = element.getAttribute(attr);
    if (attribute != null) {
      try
      {
        return Long.parseLong(attribute);
      }
      catch (NumberFormatException localNumberFormatException) {}
    }
    return 0L;
  }
  
  private static void abort(String message, Throwable exception)
    throws CoreException
  {
    IStatus status = new Status(4, "org.eclipse.pde.api.tools", message, exception);
    throw new CoreException(status);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.api.tools.internal.ApiDescriptionManager
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.api.tools.internal;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.BodyDeclaration;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.Javadoc;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.TagElement;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
import org.eclipse.pde.api.tools.internal.provisional.IApiAnnotations;
import org.eclipse.pde.api.tools.internal.provisional.IApiDescription;
import org.eclipse.pde.api.tools.internal.provisional.IApiJavadocTag;
import org.eclipse.pde.api.tools.internal.provisional.RestrictionModifiers;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IFieldDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IMethodDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IReferenceTypeDescriptor;
import org.eclipse.pde.api.tools.internal.util.Signatures;

class ApiDescriptionProcessor$ASTTagVisitor
  extends ASTVisitor
{
  private List apis = null;
  private IApiDescription description = null;
  private ASTRewrite rewrite = null;
  private Stack typeStack;
  
  public ApiDescriptionProcessor$ASTTagVisitor(List apis, IApiDescription description, ASTRewrite rewrite)
  {
    this.apis = apis;
    this.description = description;
    this.rewrite = rewrite;
    typeStack = new Stack();
  }
  
  public boolean visit(TypeDeclaration node)
  {
    int type = 1;
    if (node.isInterface()) {
      type = 2;
    }
    typeStack.push(new Integer(type));
    updateDocNode(findDescriptorByName(node.getName().getFullyQualifiedName(), null), node, getType(), 16);
    return true;
  }
  
  public void endVisit(TypeDeclaration node)
  {
    typeStack.pop();
  }
  
  private int getType()
  {
    return ((Integer)typeStack.peek()).intValue();
  }
  
  public boolean visit(FieldDeclaration node)
  {
    List fields = node.fragments();
    VariableDeclarationFragment fragment = null;
    for (Iterator iter = fields.iterator(); iter.hasNext();)
    {
      fragment = (VariableDeclarationFragment)iter.next();
      updateDocNode(findDescriptorByName(fragment.getName().getFullyQualifiedName(), null), node, getType(), 8);
    }
    return false;
  }
  
  public boolean visit(MethodDeclaration node)
  {
    String signature = Signatures.getMethodSignatureFromNode(node);
    if (signature != null) {
      updateDocNode(findDescriptorByName(node.getName().getFullyQualifiedName(), signature), node, getType(), 4);
    }
    return false;
  }
  
  private void updateDocNode(IElementDescriptor element, BodyDeclaration body, int type, int member)
  {
    if (element != null)
    {
      IApiAnnotations api = description.resolveAnnotations(element);
      if (api != null)
      {
        Javadoc docnode = body.getJavadoc();
        AST ast = body.getAST();
        boolean newnode = docnode == null;
        if (docnode == null) {
          docnode = ast.newJavadoc();
        }
        String[] missingtags = collectMissingTags(api, docnode.tags(), type, member);
        if (missingtags.length == 0) {
          return;
        }
        if (newnode) {
          rewrite.set(body, body.getJavadocProperty(), docnode, null);
        }
        ListRewrite lrewrite = rewrite.getListRewrite(docnode, Javadoc.TAGS_PROPERTY);
        TagElement newtag = null;
        for (int i = 0; i < missingtags.length; i++)
        {
          newtag = createNewTagElement(ast, missingtags[i]);
          lrewrite.insertLast(newtag, null);
        }
      }
    }
  }
  
  private TagElement createNewTagElement(AST ast, String tagname)
  {
    TagElement newtag = ast.newTagElement();
    newtag.setTagName(tagname);
    return newtag;
  }
  
  private String[] collectMissingTags(IApiAnnotations api, List tags, int type, int member)
  {
    int res = api.getRestrictions();
    ArrayList missing = new ArrayList();
    JavadocTagManager jtm = ApiPlugin.getJavadocTagManager();
    switch (member)
    {
    case 8: 
      if ((RestrictionModifiers.isReferenceRestriction(res)) && 
        (!containsRestrictionTag(tags, "@noreference")))
      {
        IApiJavadocTag tag = jtm.getTag("org.eclipse.pde.api.tools.noreference");
        missing.add(tag.getCompleteTag(type, member));
      }
      break;
    case 4: 
      if ((RestrictionModifiers.isReferenceRestriction(res)) && 
        (!containsRestrictionTag(tags, "@noreference")))
      {
        IApiJavadocTag tag = jtm.getTag("org.eclipse.pde.api.tools.noreference");
        missing.add(tag.getCompleteTag(type, member));
      }
      if ((RestrictionModifiers.isOverrideRestriction(res)) && 
        (!containsRestrictionTag(tags, "@nooverride")))
      {
        IApiJavadocTag tag = jtm.getTag("org.eclipse.pde.api.tools.nooverride");
        missing.add(tag.getCompleteTag(type, member));
      }
      break;
    case 16: 
      if ((RestrictionModifiers.isImplementRestriction(res)) && 
        (!containsRestrictionTag(tags, "@noimplement")))
      {
        IApiJavadocTag tag = jtm.getTag("org.eclipse.pde.api.tools.noimplement");
        missing.add(tag.getCompleteTag(type, member));
      }
      if ((RestrictionModifiers.isInstantiateRestriction(res)) && 
        (!containsRestrictionTag(tags, "@noinstantiate")))
      {
        IApiJavadocTag tag = jtm.getTag("org.eclipse.pde.api.tools.noinstantiate");
        missing.add(tag.getCompleteTag(type, member));
      }
      if ((RestrictionModifiers.isExtendRestriction(res)) && 
        (!containsRestrictionTag(tags, "@noextend")))
      {
        IApiJavadocTag tag = jtm.getTag("org.eclipse.pde.api.tools.noextend");
        missing.add(tag.getCompleteTag(type, member));
      }
      break;
    }
    return (String[])missing.toArray(new String[missing.size()]);
  }
  
  private boolean containsRestrictionTag(List tags, String tag)
  {
    TagElement tagelement = null;
    for (int i = 0; i < tags.size(); i++)
    {
      tagelement = (TagElement)tags.get(i);
      if (tag.equals(tagelement.getTagName())) {
        return true;
      }
    }
    return false;
  }
  
  private IElementDescriptor findDescriptorByName(String name, String signature)
  {
    IElementDescriptor desc = null;
    for (int i = 0; i < apis.size(); i++)
    {
      desc = (IElementDescriptor)apis.get(i);
      switch (desc.getElementType())
      {
      case 2: 
        if (((IReferenceTypeDescriptor)desc).getName().equals(name)) {
          return desc;
        }
        break;
      case 6: 
        IMethodDescriptor method = (IMethodDescriptor)desc;
        if ((method.getName().equals(name)) && (method.getSignature().equals(signature))) {
          return desc;
        }
        break;
      case 5: 
        if (((IFieldDescriptor)desc).getName().equals(name)) {
          return desc;
        }
        break;
      }
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.api.tools.internal.ApiDescriptionProcessor.ASTTagVisitor
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.api.tools.internal;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.pde.api.tools.internal.provisional.ApiDescriptionVisitor;
import org.eclipse.pde.api.tools.internal.provisional.IApiAnnotations;
import org.eclipse.pde.api.tools.internal.provisional.IApiDescription;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IReferenceTypeDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.scanner.ScannerMessages;

class ApiDescriptionProcessor$DescriptionVisitor
  extends ApiDescriptionVisitor
{
  private IApiDescription apiDescription = null;
  private IJavaProject project = null;
  private Map fCollector = null;
  private List members = new ArrayList();
  private List exceptions = null;
  
  ApiDescriptionProcessor$DescriptionVisitor(IJavaProject jp, IApiDescription cd, Map collector)
  {
    project = jp;
    apiDescription = cd;
    fCollector = collector;
  }
  
  public boolean visitElement(IElementDescriptor element, IApiAnnotations description)
  {
    switch (element.getElementType())
    {
    case 1: 
      return true;
    case 2: 
      members.clear();
      members.add(element);
      return true;
    }
    members.add(element);
    
    return false;
  }
  
  public void endVisitElement(IElementDescriptor element, IApiAnnotations description)
  {
    if (element.getElementType() == 2)
    {
      IReferenceTypeDescriptor refType = (IReferenceTypeDescriptor)element;
      try
      {
        IReferenceTypeDescriptor topLevelType = refType.getEnclosingType();
        while (topLevelType != null)
        {
          refType = topLevelType;
          topLevelType = refType.getEnclosingType();
        }
        IType type = project.findType(refType.getQualifiedName(), new NullProgressMonitor());
        if (type != null) {
          ApiDescriptionProcessor.processTagUpdates(type, refType, apiDescription, members, fCollector);
        }
      }
      catch (CoreException e)
      {
        addStatus(e.getStatus());
      }
      catch (BadLocationException e)
      {
        addStatus(new Status(4, "org.eclipse.pde.api.tools", 
          ScannerMessages.ComponentXMLScanner_0 + element.toString(), e));
      }
      members.clear();
    }
  }
  
  private void addStatus(IStatus status)
  {
    if (exceptions == null) {
      exceptions = new ArrayList();
    }
    exceptions.add(status);
  }
  
  public IStatus getStatus()
  {
    if (exceptions == null) {
      return Status.OK_STATUS;
    }
    return new MultiStatus("org.eclipse.pde.api.tools", 0, 
      (IStatus[])exceptions.toArray(new IStatus[exceptions.size()]), 
      ScannerMessages.ComponentXMLScanner_1, null);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.api.tools.internal.ApiDescriptionProcessor.DescriptionVisitor
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.api.tools.internal;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.BodyDeclaration;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.Javadoc;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.TagElement;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.pde.api.tools.internal.provisional.ApiDescriptionVisitor;
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
import org.eclipse.pde.api.tools.internal.provisional.Factory;
import org.eclipse.pde.api.tools.internal.provisional.IApiAnnotations;
import org.eclipse.pde.api.tools.internal.provisional.IApiDescription;
import org.eclipse.pde.api.tools.internal.provisional.IApiJavadocTag;
import org.eclipse.pde.api.tools.internal.provisional.RestrictionModifiers;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IFieldDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IMethodDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IPackageDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IReferenceTypeDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.scanner.ScannerMessages;
import org.eclipse.pde.api.tools.internal.util.Signatures;
import org.eclipse.pde.api.tools.internal.util.Util;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class ApiDescriptionProcessor
{
  static class DescriptionVisitor
    extends ApiDescriptionVisitor
  {
    private IApiDescription apiDescription = null;
    private IJavaProject project = null;
    private Map fCollector = null;
    private List members = new ArrayList();
    private List exceptions = null;
    
    DescriptionVisitor(IJavaProject jp, IApiDescription cd, Map collector)
    {
      project = jp;
      apiDescription = cd;
      fCollector = collector;
    }
    
    public boolean visitElement(IElementDescriptor element, IApiAnnotations description)
    {
      switch (element.getElementType())
      {
      case 1: 
        return true;
      case 2: 
        members.clear();
        members.add(element);
        return true;
      }
      members.add(element);
      
      return false;
    }
    
    public void endVisitElement(IElementDescriptor element, IApiAnnotations description)
    {
      if (element.getElementType() == 2)
      {
        IReferenceTypeDescriptor refType = (IReferenceTypeDescriptor)element;
        try
        {
          IReferenceTypeDescriptor topLevelType = refType.getEnclosingType();
          while (topLevelType != null)
          {
            refType = topLevelType;
            topLevelType = refType.getEnclosingType();
          }
          IType type = project.findType(refType.getQualifiedName(), new NullProgressMonitor());
          if (type != null) {
            ApiDescriptionProcessor.processTagUpdates(type, refType, apiDescription, members, fCollector);
          }
        }
        catch (CoreException e)
        {
          addStatus(e.getStatus());
        }
        catch (BadLocationException e)
        {
          addStatus(new Status(4, "org.eclipse.pde.api.tools", 
            ScannerMessages.ComponentXMLScanner_0 + element.toString(), e));
        }
        members.clear();
      }
    }
    
    private void addStatus(IStatus status)
    {
      if (exceptions == null) {
        exceptions = new ArrayList();
      }
      exceptions.add(status);
    }
    
    public IStatus getStatus()
    {
      if (exceptions == null) {
        return Status.OK_STATUS;
      }
      return new MultiStatus("org.eclipse.pde.api.tools", 0, 
        (IStatus[])exceptions.toArray(new IStatus[exceptions.size()]), 
        ScannerMessages.ComponentXMLScanner_1, null);
    }
  }
  
  static class ASTTagVisitor
    extends ASTVisitor
  {
    private List apis = null;
    private IApiDescription description = null;
    private ASTRewrite rewrite = null;
    private Stack typeStack;
    
    public ASTTagVisitor(List apis, IApiDescription description, ASTRewrite rewrite)
    {
      this.apis = apis;
      this.description = description;
      this.rewrite = rewrite;
      typeStack = new Stack();
    }
    
    public boolean visit(TypeDeclaration node)
    {
      int type = 1;
      if (node.isInterface()) {
        type = 2;
      }
      typeStack.push(new Integer(type));
      updateDocNode(findDescriptorByName(node.getName().getFullyQualifiedName(), null), node, getType(), 16);
      return true;
    }
    
    public void endVisit(TypeDeclaration node)
    {
      typeStack.pop();
    }
    
    private int getType()
    {
      return ((Integer)typeStack.peek()).intValue();
    }
    
    public boolean visit(FieldDeclaration node)
    {
      List fields = node.fragments();
      VariableDeclarationFragment fragment = null;
      for (Iterator iter = fields.iterator(); iter.hasNext();)
      {
        fragment = (VariableDeclarationFragment)iter.next();
        updateDocNode(findDescriptorByName(fragment.getName().getFullyQualifiedName(), null), node, getType(), 8);
      }
      return false;
    }
    
    public boolean visit(MethodDeclaration node)
    {
      String signature = Signatures.getMethodSignatureFromNode(node);
      if (signature != null) {
        updateDocNode(findDescriptorByName(node.getName().getFullyQualifiedName(), signature), node, getType(), 4);
      }
      return false;
    }
    
    private void updateDocNode(IElementDescriptor element, BodyDeclaration body, int type, int member)
    {
      if (element != null)
      {
        IApiAnnotations api = description.resolveAnnotations(element);
        if (api != null)
        {
          Javadoc docnode = body.getJavadoc();
          AST ast = body.getAST();
          boolean newnode = docnode == null;
          if (docnode == null) {
            docnode = ast.newJavadoc();
          }
          String[] missingtags = collectMissingTags(api, docnode.tags(), type, member);
          if (missingtags.length == 0) {
            return;
          }
          if (newnode) {
            rewrite.set(body, body.getJavadocProperty(), docnode, null);
          }
          ListRewrite lrewrite = rewrite.getListRewrite(docnode, Javadoc.TAGS_PROPERTY);
          TagElement newtag = null;
          for (int i = 0; i < missingtags.length; i++)
          {
            newtag = createNewTagElement(ast, missingtags[i]);
            lrewrite.insertLast(newtag, null);
          }
        }
      }
    }
    
    private TagElement createNewTagElement(AST ast, String tagname)
    {
      TagElement newtag = ast.newTagElement();
      newtag.setTagName(tagname);
      return newtag;
    }
    
    private String[] collectMissingTags(IApiAnnotations api, List tags, int type, int member)
    {
      int res = api.getRestrictions();
      ArrayList missing = new ArrayList();
      JavadocTagManager jtm = ApiPlugin.getJavadocTagManager();
      switch (member)
      {
      case 8: 
        if ((RestrictionModifiers.isReferenceRestriction(res)) && 
          (!containsRestrictionTag(tags, "@noreference")))
        {
          IApiJavadocTag tag = jtm.getTag("org.eclipse.pde.api.tools.noreference");
          missing.add(tag.getCompleteTag(type, member));
        }
        break;
      case 4: 
        if ((RestrictionModifiers.isReferenceRestriction(res)) && 
          (!containsRestrictionTag(tags, "@noreference")))
        {
          IApiJavadocTag tag = jtm.getTag("org.eclipse.pde.api.tools.noreference");
          missing.add(tag.getCompleteTag(type, member));
        }
        if ((RestrictionModifiers.isOverrideRestriction(res)) && 
          (!containsRestrictionTag(tags, "@nooverride")))
        {
          IApiJavadocTag tag = jtm.getTag("org.eclipse.pde.api.tools.nooverride");
          missing.add(tag.getCompleteTag(type, member));
        }
        break;
      case 16: 
        if ((RestrictionModifiers.isImplementRestriction(res)) && 
          (!containsRestrictionTag(tags, "@noimplement")))
        {
          IApiJavadocTag tag = jtm.getTag("org.eclipse.pde.api.tools.noimplement");
          missing.add(tag.getCompleteTag(type, member));
        }
        if ((RestrictionModifiers.isInstantiateRestriction(res)) && 
          (!containsRestrictionTag(tags, "@noinstantiate")))
        {
          IApiJavadocTag tag = jtm.getTag("org.eclipse.pde.api.tools.noinstantiate");
          missing.add(tag.getCompleteTag(type, member));
        }
        if ((RestrictionModifiers.isExtendRestriction(res)) && 
          (!containsRestrictionTag(tags, "@noextend")))
        {
          IApiJavadocTag tag = jtm.getTag("org.eclipse.pde.api.tools.noextend");
          missing.add(tag.getCompleteTag(type, member));
        }
        break;
      }
      return (String[])missing.toArray(new String[missing.size()]);
    }
    
    private boolean containsRestrictionTag(List tags, String tag)
    {
      TagElement tagelement = null;
      for (int i = 0; i < tags.size(); i++)
      {
        tagelement = (TagElement)tags.get(i);
        if (tag.equals(tagelement.getTagName())) {
          return true;
        }
      }
      return false;
    }
    
    private IElementDescriptor findDescriptorByName(String name, String signature)
    {
      IElementDescriptor desc = null;
      for (int i = 0; i < apis.size(); i++)
      {
        desc = (IElementDescriptor)apis.get(i);
        switch (desc.getElementType())
        {
        case 2: 
          if (((IReferenceTypeDescriptor)desc).getName().equals(name)) {
            return desc;
          }
          break;
        case 6: 
          IMethodDescriptor method = (IMethodDescriptor)desc;
          if ((method.getName().equals(name)) && (method.getSignature().equals(signature))) {
            return desc;
          }
          break;
        case 5: 
          if (((IFieldDescriptor)desc).getName().equals(name)) {
            return desc;
          }
          break;
        }
      }
      return null;
    }
  }
  
  public static String serializeComponentXml(File location)
  {
    if (location.exists())
    {
      ZipFile jarFile = null;
      InputStream stream = null;
      try
      {
        String extension = new Path(location.getName()).getFileExtension();
        if ((extension != null) && (extension.equals("jar")) && (location.isFile()))
        {
          jarFile = new ZipFile(location, 1);
          ZipEntry manifestEntry = jarFile.getEntry("component.xml");
          if (manifestEntry != null) {
            stream = jarFile.getInputStream(manifestEntry);
          }
        }
        else if (location.isDirectory())
        {
          File file = new File(location, "component.xml");
          if (file.exists()) {
            stream = new FileInputStream(file);
          }
        }
        else if ((location.isFile()) && 
          (location.getName().equals("component.xml")))
        {
          stream = new FileInputStream(location);
        }
        if (stream != null) {
          return new String(Util.getInputStreamAsCharArray(stream, -1, "UTF-8"));
        }
      }
      catch (IOException e)
      {
        ApiPlugin.log(e);
      }
      finally
      {
        try
        {
          if (stream != null) {
            stream.close();
          }
        }
        catch (IOException e)
        {
          ApiPlugin.log(e);
        }
        try
        {
          if (jarFile != null) {
            jarFile.close();
          }
        }
        catch (IOException e)
        {
          ApiPlugin.log(e);
        }
      }
      try
      {
        if (stream != null) {
          stream.close();
        }
      }
      catch (IOException e)
      {
        ApiPlugin.log(e);
      }
      try
      {
        if (jarFile != null) {
          jarFile.close();
        }
      }
      catch (IOException e)
      {
        ApiPlugin.log(e);
      }
    }
    return null;
  }
  
  public static void collectTagUpdates(IJavaProject project, File componentxml, Map collector)
    throws CoreException, IOException
  {
    IApiDescription description = new ApiDescription(null);
    annotateApiSettings(project, description, serializeComponentXml(componentxml));
    
    DescriptionVisitor visitor = new DescriptionVisitor(project, description, collector);
    description.accept(visitor, null);
    IStatus status = visitor.getStatus();
    if (!status.isOK()) {
      throw new CoreException(status);
    }
  }
  
  /* Error */
  static void processTagUpdates(IType type, IReferenceTypeDescriptor desc, IApiDescription description, List members, Map collector)
    throws CoreException, BadLocationException
  {
    // Byte code:
    //   0: iconst_4
    //   1: invokestatic 531	org/eclipse/jdt/core/dom/ASTParser:newParser	(I)Lorg/eclipse/jdt/core/dom/ASTParser;
    //   4: astore 5
    //   6: aload_0
    //   7: invokeinterface 575 1 0
    //   12: astore 6
    //   14: aload 6
    //   16: ifnull +270 -> 286
    //   19: aload 5
    //   21: aload 6
    //   23: invokevirtual 530	org/eclipse/jdt/core/dom/ASTParser:setSource	(Lorg/eclipse/jdt/core/ICompilationUnit;)V
    //   26: aload 6
    //   28: invokeinterface 570 1 0
    //   33: iconst_1
    //   34: invokeinterface 572 2 0
    //   39: astore 7
    //   41: aload 7
    //   43: ldc 5
    //   45: ldc 3
    //   47: invokeinterface 563 3 0
    //   52: pop
    //   53: aload 5
    //   55: aload 7
    //   57: invokevirtual 529	org/eclipse/jdt/core/dom/ASTParser:setCompilerOptions	(Ljava/util/Map;)V
    //   60: aload 5
    //   62: new 274	org/eclipse/core/runtime/NullProgressMonitor
    //   65: dup
    //   66: invokespecial 522	org/eclipse/core/runtime/NullProgressMonitor:<init>	()V
    //   69: invokevirtual 532	org/eclipse/jdt/core/dom/ASTParser:createAST	(Lorg/eclipse/core/runtime/IProgressMonitor;)Lorg/eclipse/jdt/core/dom/ASTNode;
    //   72: checkcast 284	org/eclipse/jdt/core/dom/CompilationUnit
    //   75: astore 8
    //   77: aload 8
    //   79: invokevirtual 533	org/eclipse/jdt/core/dom/CompilationUnit:recordModifications	()V
    //   82: aload 8
    //   84: invokevirtual 535	org/eclipse/jdt/core/dom/CompilationUnit:getAST	()Lorg/eclipse/jdt/core/dom/AST;
    //   87: invokestatic 537	org/eclipse/jdt/core/dom/rewrite/ASTRewrite:create	(Lorg/eclipse/jdt/core/dom/AST;)Lorg/eclipse/jdt/core/dom/rewrite/ASTRewrite;
    //   90: astore 9
    //   92: new 289	org/eclipse/pde/api/tools/internal/ApiDescriptionProcessor$ASTTagVisitor
    //   95: dup
    //   96: aload_3
    //   97: aload_2
    //   98: aload 9
    //   100: invokespecial 551	org/eclipse/pde/api/tools/internal/ApiDescriptionProcessor$ASTTagVisitor:<init>	(Ljava/util/List;Lorg/eclipse/pde/api/tools/internal/provisional/IApiDescription;Lorg/eclipse/jdt/core/dom/rewrite/ASTRewrite;)V
    //   103: astore 10
    //   105: aload 8
    //   107: aload 10
    //   109: invokevirtual 536	org/eclipse/jdt/core/dom/CompilationUnit:accept	(Lorg/eclipse/jdt/core/dom/ASTVisitor;)V
    //   112: invokestatic 520	org/eclipse/core/filebuffers/FileBuffers:getTextFileBufferManager	()Lorg/eclipse/core/filebuffers/ITextFileBufferManager;
    //   115: astore 11
    //   117: aload 8
    //   119: invokevirtual 534	org/eclipse/jdt/core/dom/CompilationUnit:getJavaElement	()Lorg/eclipse/jdt/core/IJavaElement;
    //   122: invokeinterface 571 1 0
    //   127: astore 12
    //   129: aload 11
    //   131: aload 12
    //   133: getstatic 494	org/eclipse/core/filebuffers/LocationKind:IFILE	Lorg/eclipse/core/filebuffers/LocationKind;
    //   136: aconst_null
    //   137: invokeinterface 566 4 0
    //   142: aload 11
    //   144: aload 12
    //   146: getstatic 494	org/eclipse/core/filebuffers/LocationKind:IFILE	Lorg/eclipse/core/filebuffers/LocationKind;
    //   149: invokeinterface 565 3 0
    //   154: astore 13
    //   156: aload 13
    //   158: invokeinterface 564 1 0
    //   163: astore 14
    //   165: aload 9
    //   167: aload 14
    //   169: aconst_null
    //   170: invokevirtual 538	org/eclipse/jdt/core/dom/rewrite/ASTRewrite:rewriteAST	(Lorg/eclipse/jface/text/IDocument;Ljava/util/Map;)Lorg/eclipse/text/edits/TextEdit;
    //   173: astore 15
    //   175: aload 15
    //   177: invokevirtual 560	org/eclipse/text/edits/TextEdit:getChildrenSize	()I
    //   180: ifgt +11 -> 191
    //   183: aload 15
    //   185: invokevirtual 561	org/eclipse/text/edits/TextEdit:getLength	()I
    //   188: ifeq +85 -> 273
    //   191: aload 6
    //   193: invokeinterface 569 1 0
    //   198: checkcast 271	org/eclipse/core/resources/IFile
    //   201: astore 16
    //   203: aload 4
    //   205: aload 16
    //   207: invokeinterface 562 2 0
    //   212: checkcast 264	java/util/HashSet
    //   215: astore 17
    //   217: aload 17
    //   219: ifnonnull +25 -> 244
    //   222: new 264	java/util/HashSet
    //   225: dup
    //   226: iconst_3
    //   227: invokespecial 514	java/util/HashSet:<init>	(I)V
    //   230: astore 17
    //   232: aload 4
    //   234: aload 16
    //   236: aload 17
    //   238: invokeinterface 563 3 0
    //   243: pop
    //   244: aload 17
    //   246: aload 15
    //   248: invokevirtual 515	java/util/HashSet:add	(Ljava/lang/Object;)Z
    //   251: pop
    //   252: goto +21 -> 273
    //   255: astore 18
    //   257: aload 11
    //   259: aload 12
    //   261: getstatic 494	org/eclipse/core/filebuffers/LocationKind:IFILE	Lorg/eclipse/core/filebuffers/LocationKind;
    //   264: aconst_null
    //   265: invokeinterface 567 4 0
    //   270: aload 18
    //   272: athrow
    //   273: aload 11
    //   275: aload 12
    //   277: getstatic 494	org/eclipse/core/filebuffers/LocationKind:IFILE	Lorg/eclipse/core/filebuffers/LocationKind;
    //   280: aconst_null
    //   281: invokeinterface 567 4 0
    //   286: return
    // Line number table:
    //   Java source line #524	-> byte code offset #0
    //   Java source line #525	-> byte code offset #6
    //   Java source line #526	-> byte code offset #14
    //   Java source line #527	-> byte code offset #19
    //   Java source line #528	-> byte code offset #26
    //   Java source line #529	-> byte code offset #41
    //   Java source line #530	-> byte code offset #53
    //   Java source line #531	-> byte code offset #60
    //   Java source line #532	-> byte code offset #77
    //   Java source line #533	-> byte code offset #82
    //   Java source line #534	-> byte code offset #92
    //   Java source line #535	-> byte code offset #105
    //   Java source line #536	-> byte code offset #112
    //   Java source line #537	-> byte code offset #117
    //   Java source line #539	-> byte code offset #129
    //   Java source line #540	-> byte code offset #142
    //   Java source line #541	-> byte code offset #156
    //   Java source line #542	-> byte code offset #165
    //   Java source line #543	-> byte code offset #175
    //   Java source line #544	-> byte code offset #191
    //   Java source line #545	-> byte code offset #203
    //   Java source line #546	-> byte code offset #217
    //   Java source line #547	-> byte code offset #222
    //   Java source line #548	-> byte code offset #232
    //   Java source line #550	-> byte code offset #244
    //   Java source line #552	-> byte code offset #255
    //   Java source line #553	-> byte code offset #257
    //   Java source line #554	-> byte code offset #270
    //   Java source line #553	-> byte code offset #273
    //   Java source line #556	-> byte code offset #286
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	287	0	type	IType
    //   0	287	1	desc	IReferenceTypeDescriptor
    //   0	287	2	description	IApiDescription
    //   0	287	3	members	List
    //   0	287	4	collector	Map
    //   4	57	5	parser	org.eclipse.jdt.core.dom.ASTParser
    //   12	180	6	cunit	org.eclipse.jdt.core.ICompilationUnit
    //   39	17	7	options	Map
    //   75	43	8	cast	org.eclipse.jdt.core.dom.CompilationUnit
    //   90	76	9	rewrite	ASTRewrite
    //   103	5	10	visitor	ASTTagVisitor
    //   115	159	11	bm	org.eclipse.core.filebuffers.ITextFileBufferManager
    //   127	149	12	path	org.eclipse.core.runtime.IPath
    //   154	3	13	tfb	org.eclipse.core.file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd