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

   linePositionTracker.addLocation((Reference)iterator.next());
          }
        }
        break;
      }
      if (kind != -1)
      {
        Reference reference = addTypeReference(type, kind);
        if (reference != null) {
          linePositionTracker.addLocation(reference);
        }
      }
    }
    
    public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index)
    {
      if (desc.length() == 1) {
        return;
      }
      if (index > argumentcount)
      {
        Object object = labelsToLocalMarkers.get(start);
        int lineNumber = -1;
        if (object != null) {
          if ((object instanceof List))
          {
            List markersList = (List)object;
            ReferenceExtractor.LocalLineNumberMarker removeMarker = null;
            for (Iterator iterator = markersList.iterator(); iterator.hasNext();)
            {
              ReferenceExtractor.LocalLineNumberMarker marker = (ReferenceExtractor.LocalLineNumberMarker)iterator.next();
              if (varIndex == index)
              {
                lineNumber = lineNumber;
                removeMarker = marker;
                break;
              }
            }
            if (removeMarker != null)
            {
              markersList.remove(removeMarker);
              if (markersList.isEmpty()) {
                labelsToLocalMarkers.remove(start);
              }
            }
          }
          else
          {
            ReferenceExtractor.LocalLineNumberMarker marker = (ReferenceExtractor.LocalLineNumberMarker)object;
            if (varIndex == index)
            {
              lineNumber = lineNumber;
              labelsToLocalMarkers.remove(start);
            }
          }
        }
        if (lineNumber == -1) {
          return;
        }
        if (signature != null)
        {
          List references = processSignature(name, signature, 16777216, ReferenceExtractor.METHOD);
          for (Iterator iterator = references.iterator(); iterator.hasNext();)
          {
            Reference reference = (Reference)iterator.next();
            reference.setLineNumber(lineNumber);
          }
        }
        else
        {
          Type type = Type.getType(desc);
          if (type.getSort() == 10)
          {
            Reference reference = addTypeReference(type, 33554432);
            if (reference != null) {
              reference.setLineNumber(lineNumber);
            }
          }
        }
      }
    }
    
    public void visitLdcInsn(Object cst)
    {
      if ((cst instanceof Type))
      {
        Type type = (Type)cst;
        Reference reference = addTypeReference(type, 67108864);
        if (reference != null) {
          linePositionTracker.addLocation(reference);
        }
      }
      else if ((cst instanceof String))
      {
        String str = (String)cst;
        stringLiteral = ("".equals(str) ? null : str);
      }
    }
  }
  
  static class FieldTracker
  {
    HashMap accessors = new HashMap();
    ArrayList fields = new ArrayList();
    ReferenceExtractor extractor = null;
    
    public FieldTracker(ReferenceExtractor extractor)
    {
      this.extractor = extractor;
    }
    
    public void addField(Reference ref)
    {
      if (ref != null) {
        fields.add(ref);
      }
    }
    
    public void addAccessor(Reference ref)
    {
      if (ref != null)
      {
        String key = ref.getReferencedMemberName();
        List refs = (List)accessors.get(key);
        if (refs == null)
        {
          refs = new ArrayList();
          accessors.put(key, refs);
        }
        refs.add(ref);
      }
    }
    
    public void resolveSyntheticFields()
    {
      Reference accessor = null;Reference field = null;
      List refs = null;
      for (int i = 0; i < fields.size(); i++)
      {
        field = (Reference)fields.get(i);
        refs = (List)accessors.get(field.getMember().getName());
        if (refs != null)
        {
          for (Iterator iter = refs.iterator(); iter.hasNext();)
          {
            accessor = (Reference)iter.next();
            Reference refer = Reference.fieldReference(accessor.getMember(), 
              field.getReferencedTypeName(), 
              field.getReferencedMemberName(), 
              field.getReferenceKind());
            refer.setLineNumber(accessor.getLineNumber());
            extractor.collector.add(refer);
          }
          extractor.collector.remove(field);
        }
      }
    }
  }
  
  static class LinePositionTracker
  {
    List labelsAndLocations;
    SortedSet lineInfos;
    List catchLabelInfos;
    HashMap lineMap;
    
    public LinePositionTracker()
    {
      labelsAndLocations = new ArrayList();
      lineInfos = new TreeSet();
      catchLabelInfos = new ArrayList();
      lineMap = new HashMap();
    }
    
    void addLocation(Reference location)
    {
      labelsAndLocations.add(location);
    }
    
    void addLineInfo(int line, Label label)
    {
      lineInfos.add(new ReferenceExtractor.LineInfo(line, label));
      lineMap.put(label, new Integer(line));
    }
    
    void addCatchLabelInfos(Reference location, Label label)
    {
      catchLabelInfos.add(new ReferenceExtractor.LabelInfo(location, label));
    }
    
    void addLabel(Label label)
    {
      labelsAndLocations.add(label);
    }
    
    public void computeLineNumbers()
    {
      if ((lineInfos.size() < 1) || (labelsAndLocations.size() < 1)) {
        return;
      }
      Iterator lineInfosIterator = lineInfos.iterator();
      ReferenceExtractor.LineInfo firstLineInfo = (ReferenceExtractor.LineInfo)lineInfosIterator.next();
      int currentLineNumber = line;
      
      List remainingCatchLabelInfos = new ArrayList();
      for (Iterator iterator = catchLabelInfos.iterator(); iterator.hasNext();)
      {
        ReferenceExtractor.LabelInfo catchLabelInfo = (ReferenceExtractor.LabelInfo)iterator.next();
        Integer lineValue = (Integer)lineMap.get(label);
        if (lineValue != null) {
          location.setLineNumber(lineValue.intValue());
        } else {
          remainingCatchLabelInfos.add(catchLabelInfo);
        }
      }
      List computedEntries = new ArrayList();
      for (Iterator iterator = labelsAndLocations.iterator(); iterator.hasNext();)
      {
        Object current = iterator.next();
        if ((current instanceof Label))
        {
          Integer lineValue = (Integer)lineMap.get(current);
          if (lineValue != null) {
            computedEntries.add(new ReferenceExtractor.LineInfo(lineValue.intValue(), (Label)current));
          } else {
            computedEntries.add(current);
          }
        }
        else
        {
          computedEntries.add(current);
        }
      }
      for (Iterator iterator = computedEntries.iterator(); iterator.hasNext();)
      {
        Object current = iterator.next();
        if ((current instanceof Label))
        {
          if (remainingCatchLabelInfos != null)
          {
            List remaingEntriesTemp = new ArrayList();
            for (Iterator catchLabelInfosIterator = remainingCatchLabelInfos.iterator(); catchLabelInfosIterator.hasNext();)
            {
              ReferenceExtractor.LabelInfo catchLabelInfo = (ReferenceExtractor.LabelInfo)catchLabelInfosIterator.next();
              if (!current.equals(label)) {
                remaingEntriesTemp.add(catchLabelInfo);
              } else {
                location.setLineNumber(currentLineNumber);
              }
            }
            if (remaingEntriesTemp.size() == 0) {
              remainingCatchLabelInfos = null;
            } else {
              remainingCatchLabelInfos = remaingEntriesTemp;
            }
          }
        }
        else if ((current instanceof Reference))
        {
          Reference ref = (Reference)current;
          if (ref.getLineNumber() == -1) {
            ref.setLineNumber(currentLineNumber);
          } else {
            currentLineNumber = ref.getLineNumber();
          }
        }
        else if ((current instanceof ReferenceExtractor.LineInfo))
        {
          ReferenceExtractor.LineInfo lineInfo = (ReferenceExtractor.LineInfo)current;
          currentLineNumber = line;
        }
      }
    }
  }
  
  static class LabelInfo
  {
    public Reference location;
    public Label label;
    
    public LabelInfo(Reference location, Label label)
    {
      this.location = location;
      this.label = label;
    }
    
    public String toString()
    {
      StringBuffer buffer = new StringBuffer();
      buffer.append('(').append(label).append(',').append(location).append(')');
      return String.valueOf(buffer);
    }
  }
  
  static class LineInfo
    implements Comparable
  {
    int line;
    Label label;
    
    LineInfo(int line, Label label)
    {
      this.line = line;
      this.label = label;
    }
    
    public int compareTo(Object o)
    {
      return line - line;
    }
    
    public boolean equals(Object obj)
    {
      if ((obj instanceof LineInfo))
      {
        LineInfo lineInfo2 = (LineInfo)obj;
        
        return (line == line) && (label.equals(label));
      }
      return super.equals(obj);
    }
    
    public String toString()
    {
      StringBuffer buffer = new StringBuffer();
      buffer.append('(').append(line).append(',').append(label).append(')');
      return String.valueOf(buffer);
    }
  }
  
  static class LocalLineNumberMarker
  {
    int lineNumber;
    int varIndex;
    
    public LocalLineNumberMarker(int line, int varIndex)
    {
      lineNumber = line;
      this.varIndex = varIndex;
    }
    
    public boolean equals(Object obj)
    {
      if ((obj instanceof LocalLineNumberMarker))
      {
        LocalLineNumberMarker marker = (LocalLineNumberMarker)obj;
        return (lineNumber == lineNumber) && (varIndex == varIndex);
      }
      return false;
    }
    
    public int hashCode()
    {
      return varIndex;
    }
  }
  
  Set collector = null;
  private String classname = null;
  IApiType fType;
  Stack fMemberStack = new Stack();
  Stack fSuperStack = new Stack();
  HashMap fAnonymousTypes = new HashMap();
  private boolean fIncludeLocalRefs = false;
  private int fReferenceKinds = 0;
  FieldTracker fieldtracker = null;
  private static final int VISIT_MEMBERS_MASK = 2147483644;
  private boolean fIsVisitMembers = false;
  private ClassFileSignatureVisitor signaturevisitor = new ClassFileSignatureVisitor();
  static int TYPE = 0;
  static int FIELD = 1;
  static int METHOD = 2;
  
  public ReferenceExtractor(IApiType type, Set collector, int referenceKinds)
  {
    super(new ClassNode());
    fType = type;
    this.collector = collector;
    fReferenceKinds = referenceKinds;
    fIsVisitMembers = ((0x7FFFFFFC & fReferenceKinds) > 0);
    fieldtracker = new FieldTracker(this);
  }
  
  protected ReferenceExtractor(IApiType type, Set collector, int referenceKinds, FieldTracker tracker)
  {
    super(new ClassNode());
    fType = type;
    this.collector = collector;
    fReferenceKinds = referenceKinds;
    fIsVisitMembers = ((0x7FFFFFFC & fReferenceKinds) > 0);
    fieldtracker = tracker;
  }
  
  public String toString()
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append("Reference extractor for: ");
    buffer.append(fType.getName());
    buffer.append("\n");
    buffer.append("Reference kinds: ");
    buffer.append(Reference.getReferenceText(fReferenceKinds));
    buffer.append("\n");
    buffer.append("Is visiting members: ");
    buffer.append(fIsVisitMembers);
    return buffer.toString();
  }
  
  protected boolean consider(String owner)
  {
    if (fIncludeLocalRefs) {
      return true;
    }
    return (!classname.equals(owner)) && (!classname.startsWith(owner)) && (!"<clinit>".equals(owner)) && (!"this".equals(owner));
  }
  
  protected boolean consider(Reference ref)
  {
    int kind = ref.getReferenceKind();
    if ((kind & fReferenceKinds) == 0) {
      return false;
    }
    if (fIncludeLocalRefs) {
      return true;
    }
    String referencedTypeName = ref.getReferencedTypeName();
    if ((kind == 256) || (kind == 268435456) || 
      (kind == 8192) || (kind == 16384)) {
      return true;
    }
    if (referencedTypeName.startsWith(fType.getName()))
    {
      if (referencedTypeName.length() > fType.getName().length()) {
        return referencedTypeName.charAt(fType.getName().length()) != '$';
      }
      return false;
    }
    return true;
  }
  
  protected String processName(String name)
  {
    String newname = name;
    Type type = Type.getObjectType(name);
    if ((type != null) && (type.getSort() == 10)) {
      newname = type.getInternalName();
    }
    return newname.replaceAll("/", ".");
  }
  
  protected Reference addTypeReference(Type type, int kind)
  {
    Type rtype = resolveType(type.getDescriptor());
    if (rtype != null) {
      return addReference(
        Reference.typeReference(getMember(), rtype.getClassName(), kind));
    }
    return null;
  }
  
  protected Reference addFieldReference(Type declaringType, String name, int kind)
  {
    Type rtype = resolveType(declaringType.getDescriptor());
    if (rtype != null) {
      return addReference(
        Reference.fieldReference(getMember(), rtype.getClassName(), name, kind));
    }
    return null;
  }
  
  protected Reference addMethodReference(Type declaringType, String name, String signature, int kind)
  {
    Type rtype = resolveType(declaringType.getDescriptor());
    if (rtype != null) {
      return addReference(
        Reference.methodReference(getMember(), rtype.getClassName(), name, signature, kind));
    }
    return null;
  }
  
  protected Reference addReference(Reference target)
  {
    if (consider(target))
    {
      collector.add(target);
      return target;
    }
    return null;
  }
  
  protected List processSignature(String name, String signature, int kind, int type)
  {
    SignatureReader reader = new SignatureReader(signature);
    signaturevisitor.kind = kind;
    signaturevisitor.name = processName(name);
    signaturevisitor.signature = signature;
    signaturevisitor.originalkind = kind;
    signaturevisitor.argumentcount = 0;
    signaturevisitor.type = type;
    if ((kind == 2097152) || (kind == 8388608)) {
      reader.accept(signaturevisitor);
    } else {
      reader.acceptType(signaturevisitor);
    }
    List result = new ArrayList();
    result.addAll(signaturevisitor.references);
    collector.addAll(signaturevisitor.references);
    signaturevisitor.reset();
    return result;
  }
  
  protected Type resolveType(String desc)
  {
    Type type = Type.getType(desc);
    if (type.getSort() == 10) {
      return type;
    }
    if (type.getSort() == 9)
    {
      type = type.getElementType();
      if (type.getSort() == 10) {
        return type;
      }
    }
    return null;
  }
  
  public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
  {
    classname = processName(name);
    if (DEBUG) {
      System.out.println("Starting visit of type: [" + fType.getName() + "]");
    }
    enterMember(fType);
    if (signature != null)
    {
      processSignature(name, signature, 2097152, TYPE);
    }
    else if ((access & 0x200) != 0)
    {
      Type supertype = null;
      for (int i = 0; i < interfaces.length; i++)
      {
        supertype = Type.getObjectType(interfaces[i]);
        addTypeReference(supertype, 1);
        fSuperStack.add(supertype.getClassName());
      }
    }
    else
    {
      Type supertype = null;
      if (superName != null)
      {
        supertype = Type.getObjectType(superName);
        addTypeReference(supertype, 1);
        fSuperStack.add(supertype.getClassName());
      }
      for (int i = 0; i < interfaces.length; i++)
      {
        supertype = Type.getObjectType(interfaces[i]);
        addTypeReference(supertype, 2);
      }
    }
  }
  
  public void visitEnd()
  {
    exitMember();
    if (!fSuperStack.isEmpty())
    {
      String typeName = (String)fSuperStack.pop();
      if (DEBUG) {
        System.out.println("ending visit of type: [" + typeName + "]");
      }
    }
    if (!fType.isMemberType()) {
      fieldtracker.resolveSyntheticFields();
    }
  }
  
  public FieldVisitor visitField(int access, String name, String desc, String signature, Object value)
  {
    if (fIsVisitMembers)
    {
      IApiType owner = (IApiType)getMember();
      IApiField field = owner.getField(name);
      if (field == null)
      {
        ApiPlugin.log(
          new Status(
          2, 
          "org.eclipse.pde.api.tools", 
          NLS.bind(BuilderMessages.ReferenceExtractor_failed_to_lookup_field, 
          new String[] { name, Signatures.getQualifiedTypeSignature(owner) })));
        
        return null;
      }
      enterMember(field);
      if ((access & 0x1000) == 0)
      {
        if (signature != null) {
          processSignature(name, signature, 4194304, FIELD);
        } else {
          addTypeReference(Type.getType(desc), 4);
        }
      }
      else {
        fieldtracker.addField(addTypeReference(Type.getType(desc), 4));
      }
      exitMember();
    }
    return null;
  }
  
  public void visitInnerClass(String name, String outerName, String innerName, int access)
  {
    try
    {
      String pname = processName(name);
      if ((fType.getName().equals(pname)) || (!pname.startsWith(fType.getName()))) {
        return;
      }
      IApiComponent comp = fType.getApiComponent();
      if (comp == null) {
        return;
      }
      AbstractApiTypeRoot root = (AbstractApiTypeRoot)comp.findTypeRoot(pname);
      if (root != null)
      {
        IApiType type = root.getStructure();
        if (type == null) {
          return;
        }
        Set refs = processInnerClass(type, fReferenceKinds);
        if ((type.isAnonymous()) || (type.isLocal()))
        {
          List allRefs = new ArrayList();
          for (Iterator iterator = refs.iterator(); iterator.hasNext();)
          {
            Reference reference = (Reference)iterator.next();
            if (reference.getLineNumber() < 0) {
              allRefs.add(reference);
            }
          }
          fAnonymousTypes.put(pname, allRefs);
        }
        if ((refs != null) && (!refs.isEmpty())) {
          collector.addAll(refs);
        }
      }
    }
    catch (CoreException localCoreException) {}
  }
  
  private Set processInnerClass(IApiType type, int refkinds)
    throws CoreException
  {
    HashSet refs = new HashSet();
    ReferenceExtractor extractor = new ReferenceExtractor(type, refs, refkinds, fieldtracker);
    ClassReader reader = new ClassReader(((AbstractApiTypeRoot)type.getTypeRoot()).getContents());
    reader.accept(extractor, 4);
    return refs;
  }
  
  public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)
  {
    if (fIsVisitMembers)
    {
      IApiMember member = getMember();
      IApiType owner = null;
      if ((member instanceof IApiType)) {
        owner = (IApiType)member;
      } else {
        try
        {
          owner = member.getEnclosingType();
        }
        catch (CoreException e)
        {
          ApiPlugin.log(e.getStatus());
        }
      }
      IApiMethod method = owner.getMethod(name, desc);
      if (method == null)
      {
        ApiPlugin.log(
          new Status(
          2, 
          "org.eclipse.pde.api.tools", 
          NLS.bind(BuilderMessages.ReferenceExtractor_failed_to_lookup_method, 
          new String[] { name, desc, Signatures.getQualifiedTypeSignature(owner) })));
        
        return null;
      }
      enterMember(method);
      if (((access & 0x5) > 0) && 
        (!fSuperStack.isEmpty()))
      {
        String superTypeName = (String)fSuperStack.peek();
        addReference(
          Reference.methodReference(method, superTypeName, method.getName(), method.getSignature(), 268435456));
      }
      int argumentcount = 0;
      if ((access & 0x1000) == 0) {
        if (signature != null)
        {
          processSignature(name, signature, 8388608, METHOD);
          argumentcount = signaturevisitor.argumentcount;
        }
        else
        {
          Type[] arguments = Type.getArgumentTypes(desc);
          for (int i = 0; i < arguments.length; i++)
          {
            Type type = arguments[i];
            addTypeReference(type, 16);
            argumentcount += type.getSize();
          }
          addTypeReference(Type.getReturnType(desc), 8);
          if (exceptions != null) {
            for (int i = 0; i < exceptions.length; i++) {
              addTypeReference(Type.getObjectType(exceptions[i]), 32);
            }
          }
        }
      }
      MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
      if ((mv != null) && ((access & 0x500) == 0)) {
        return new ClassFileMethodVisitor(mv, name, argumentcount);
      }
    }
    return null;
  }
  
  protected void enterMember(IApiMember member)
  {
    fMemberStack.push(member);
  }
  
  protected void exitMember()
  {
    fMemberStack.pop();
  }
  
  protected IApiMember getMember()
  {
    return (IApiMember)fMemberStack.peek();
  }
}

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

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.pde.api.tools.internal.provisional.builder.IReference;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiMember;
import org.eclipse.pde.api.tools.internal.util.Util;

public final class ReferenceResolver
{
  private static boolean DEBUG = Util.DEBUG;
  
  public static void setDebug(boolean debugValue)
  {
    DEBUG = (debugValue) || (Util.DEBUG);
  }
  
  public static void resolveReferences(List references, IProgressMonitor monitor)
    throws CoreException
  {
    int refcount = references.size();
    Map sigtoref = new HashMap(refcount);
    
    List refs = null;
    IReference ref = null;
    String key = null;
    List methodDecls = new ArrayList(refcount);
    long start = System.currentTimeMillis();
    Iterator iterator = references.iterator();
    while (iterator.hasNext())
    {
      ref = (IReference)iterator.next();
      if (ref.getReferenceKind() == 268435456)
      {
        methodDecls.add(ref);
      }
      else
      {
        key = createSignatureKey(ref);
        refs = (List)sigtoref.get(key);
        if (refs == null)
        {
          refs = new ArrayList(20);
          sigtoref.put(key, refs);
        }
        refs.add(ref);
      }
    }
    if (monitor.isCanceled()) {
      return;
    }
    long end = System.currentTimeMillis();
    if (DEBUG) {
      System.out.println("Reference resolver: split into " + methodDecls.size() + " method overrides and " + sigtoref.size() + " unique references (" + (end - start) + "ms)");
    }
    start = System.currentTimeMillis();
    resolveReferenceSets(sigtoref, monitor);
    end = System.currentTimeMillis();
    if (DEBUG) {
      System.out.println("Reference resolver: resolved unique references in " + (end - start) + "ms");
    }
    start = System.currentTimeMillis();
    iterator = methodDecls.iterator();
    while (iterator.hasNext())
    {
      Reference reference = (Reference)iterator.next();
      reference.resolve();
    }
    end = System.currentTimeMillis();
    if (DEBUG) {
      System.out.println("Reference resolver: resolved method overrides in " + (end - start) + "ms");
    }
  }
  
  private static void resolveReferenceSets(Map map, IProgressMonitor monitor)
    throws CoreException
  {
    Iterator iterator = map.values().iterator();
    List refs = null;
    IReference ref = null;
    while (iterator.hasNext())
    {
      if (monitor.isCanceled()) {
        return;
      }
      refs = (List)iterator.next();
      ref = (IReference)refs.get(0);
      ((Reference)ref).resolve();
      IApiMember resolved = ref.getResolvedReference();
      if (resolved != null)
      {
        Iterator iterator2 = refs.iterator();
        while (iterator2.hasNext())
        {
          Reference ref2 = (Reference)iterator2.next();
          ref2.setResolution(resolved);
        }
      }
    }
  }
  
  private static String createSignatureKey(IReference reference)
    throws CoreException
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append(reference.getMember().getApiComponent().getSymbolicName());
    buffer.append("#");
    buffer.append(reference.getReferencedTypeName());
    switch (reference.getReferenceType())
    {
    case 2: 
      buffer.append("#");
      buffer.append(reference.getReferencedMemberName());
      break;
    case 3: 
      buffer.append("#");
      buffer.append(reference.getReferencedMemberName());
      buffer.append("#");
      buffer.append(reference.getReferencedSignature());
    }
    return buffer.toString();
  }
}

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

import java.util.Iterator;
import java.util.List;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration;
import org.eclipse.jdt.core.dom.BodyDeclaration;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.EnumConstantDeclaration;
import org.eclipse.jdt.core.dom.EnumDeclaration;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.Initializer;
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.TextElement;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;

public class SinceTagChecker
  extends ASTVisitor
{
  private static final int ABORT = 1;
  private static final int MISSING = 2;
  private static final int HAS_JAVA_DOC = 4;
  private static final int HAS_NO_COMMENT = 16;
  private int nameStart;
  int bits;
  private String sinceVersion;
  
  public SinceTagChecker(int nameStart)
  {
    this.nameStart = nameStart;
  }
  
  public boolean visit(CompilationUnit compilationUnit)
  {
    return true;
  }
  
  public boolean visit(VariableDeclarationFragment node)
  {
    if ((bits & 0x1) != 0) {
      return false;
    }
    if (node.getName().getStartPosition() == nameStart)
    {
      bits |= 0x1;
      ASTNode parent = node.getParent();
      if (parent.getNodeType() == 23)
      {
        FieldDeclaration fieldDeclaration = (FieldDeclaration)parent;
        processJavadoc(fieldDeclaration);
      }
    }
    return false;
  }
  
  public boolean visit(EnumDeclaration node)
  {
    return visitAbstractTypeDeclaration(node);
  }
  
  public boolean visit(TypeDeclaration node)
  {
    return visitAbstractTypeDeclaration(node);
  }
  
  private boolean visitAbstractTypeDeclaration(AbstractTypeDeclaration declaration)
  {
    if ((bits & 0x1) != 0) {
      return false;
    }
    if (declaration.getName().getStartPosition() == nameStart)
    {
      bits |= 0x1;
      processJavadoc(declaration);
    }
    return true;
  }
  
  public boolean visit(AnnotationTypeDeclaration node)
  {
    return visitAbstractTypeDeclaration(node);
  }
  
  public boolean visit(MethodDeclaration node)
  {
    if ((bits & 0x1) != 0) {
      return false;
    }
    if (node.getName().getStartPosition() == nameStart)
    {
      bits |= 0x1;
      processJavadoc(node);
    }
    return false;
  }
  
  public boolean visit(AnnotationTypeMemberDeclaration node)
  {
    if ((bits & 0x1) != 0) {
      return false;
    }
    if (node.getName().getStartPosition() == nameStart)
    {
      bits |= 0x1;
      processJavadoc(node);
    }
    return false;
  }
  
  public boolean visit(Initializer node)
  {
    return false;
  }
  
  public boolean visit(EnumConstantDeclaration node)
  {
    if ((bits & 0x1) != 0) {
      return false;
    }
    if (node.getName().getStartPosition() == nameStart)
    {
      bits |= 0x1;
      processJavadoc(node);
    }
    return false;
  }
  
  private void processJavadoc(BodyDeclaration bodyDeclaration)
  {
    Javadoc javadoc = bodyDeclaration.getJavadoc();
    boolean found = false;
    if (javadoc != null)
    {
      bits |= 0x4;
      List tags = javadoc.tags();
      for (Iterator iterator = tags.iterator(); iterator.hasNext();)
      {
        TagElement element = (TagElement)iterator.next();
        String tagName = element.getTagName();
        if ("@since".equals(tagName))
        {
          found = true;
          List fragments = element.fragments();
          if (fragments.size() >= 1)
          {
            ASTNode fragment = (ASTNode)fragments.get(0);
            if (fragment.getNodeType() != 66) {
              break;
            }
            sinceVersion = ((TextElement)fragment).getText(); break;
          }
          sinceVersion = "";
          
          break;
        }
      }
      if (!found) {
        bits |= 0x2;
      }
    }
    else
    {
      bits |= 0x10;
    }
  }
  
  public boolean isMissing()
  {
    return (bits & 0x2) != 0;
  }
  
  public boolean hasNoComment()
  {
    return (bits & 0x10) != 0;
  }
  
  public boolean hasJavadocComment()
  {
    return (bits & 0x4) != 0;
  }
  
  public String getSinceVersion()
  {
    if (sinceVersion != null) {
      return sinceVersion.trim();
    }
    return null;
  }
}

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

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
import org.eclipse.pde.api.tools.internal.model.BundleComponent;
import org.eclipse.pde.api.tools.internal.model.ProjectComponent;
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
import org.eclipse.pde.api.tools.internal.provisional.ProfileModifiers;
import org.eclipse.pde.api.tools.internal.provisional.builder.IReference;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiField;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiMember;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiMethod;
import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem;
import org.eclipse.pde.api.tools.internal.util.Signatures;
import org.eclipse.pde.api.tools.internal.util.Util;

public class SystemApiDetector
  extends AbstractProblemDetector
{
  private Map referenceEEs;
  
  protected int getElementType(IReference reference)
  {
    IApiMember member = reference.getMember();
    switch (member.getType())
    {
    case 2: 
      return 2;
    case 6: 
      return 6;
    case 5: 
      return 5;
    }
    return 0;
  }
  
  protected String[] getMessageArgs(IReference reference)
    throws CoreException
  {
    IApiMember member = reference.getMember();
    String eeValue = ProfileModifiers.getName(((Integer)referenceEEs.get(reference)).intValue());
    String simpleTypeName = Signatures.getSimpleTypeName(reference.getReferencedTypeName());
    if (simpleTypeName.indexOf('$') != -1) {
      simpleTypeName = simpleTypeName.replace('$', '.');
    }
    switch (reference.getReferenceType())
    {
    case 1: 
      return new String[] {
        getDisplay(member, false), 
        simpleTypeName, 
        eeValue };
    case 2: 
      return new String[] {
        getDisplay(member, false), 
        simpleTypeName, 
        reference.getReferencedMemberName(), 
        eeValue };
    case 3: 
      String referenceMemberName = reference.getReferencedMemberName();
      if (Util.isConstructor(referenceMemberName)) {
        return new String[] {
          getDisplay(member, false), 
          Signature.toString(reference.getReferencedSignature(), simpleTypeName, null, false, false), 
          eeValue };
      }
      return new String[] {
        getDisplay(member, false), 
        simpleTypeName, 
        Signature.toString(reference.getReferencedSignature(), referenceMemberName, null, false, false), 
        eeValue };
    }
    return null;
  }
  
  private String getDisplay(IApiMember member, boolean qualified)
    throws CoreException
  {
    String typeName = qualified ? getTypeName(member) : getSimpleTypeName(member);
    if (typeName.indexOf('$') != -1) {
      typeName = typeName.replace('$', '.');
    }
    switch (member.getType())
    {
    case 5: 
      StringBuffer buffer = new StringBuffer();
      IApiField field = (IApiField)member;
      buffer
        .append(typeName)
        .append('.')
        .append(field.getName());
      return String.valueOf(buffer);
    case 6: 
      IApiMethod method = (IApiMethod)member;
      if (qualified) {
        return Signatures.getMethodSignature(method);
      }
      return Signatures.getQualifiedMethodSignature(method);
    }
    return typeName;
  }
  
  protected int getProblemFlags(IReference reference)
  {
    switch (reference.getReferenceType())
    {
    case 1: 
      return 0;
    case 3: 
      if (Util.isConstructor(reference.getReferencedMemberName())) {
        return 7;
      }
      return 8;
    case 2: 
      return 9;
    }
    return 0;
  }
  
  protected int getProblemKind()
  {
    return 9;
  }
  
  protected String[] getQualifiedMessageArgs(IReference reference)
    throws CoreException
  {
    IApiMember member = reference.getMember();
    String eeValue = ProfileModifiers.getName(((Integer)referenceEEs.get(reference)).intValue());
    String simpleTypeName = reference.getReferencedTypeName();
    if (simpleTypeName.indexOf('$') != -1) {
      simpleTypeName = simpleTypeName.replace('$', '.');
    }
    switch (reference.getReferenceType())
    {
    case 1: 
      return new String[] {
        getDisplay(member, false), 
        simpleTypeName, 
        eeValue };
    case 2: 
      return new String[] {
        getDisplay(member, false), 
        simpleTypeName, 
        reference.getReferencedMemberName(), 
        eeValue };
    case 3: 
      String referenceMemberName = reference.getReferencedMemberName();
      if (Util.isConstructor(referenceMemberName)) {
        return new String[] {
          getDisplay(member, false), 
          Signature.toString(reference.getReferencedSignature(), simpleTypeName, null, false, false), 
          eeValue };
      }
      return new String[] {
        getDisplay(member, false), 
        simpleTypeName, 
        Signature.toString(reference.getReferencedSignature(), referenceMemberName, null, false, false), 
        eeValue };
    }
    return null;
  }
  
  protected String getSeverityKey()
  {
    return "INVALID_REFERENCE_IN_SYSTEM_LIBRARIES";
  }
  
  protected Position getSourceRange(IType type, IDocument document, IReference reference)
    throws CoreException, BadLocationException
  {
    switch (reference.getReferenceType())
    {
    case 1: 
      int linenumber = reference.getLineNumber();
      if (linenumber > 0) {
        linenumber--;
      }
      if (linenumber > 0)
      {
        int offset = document.getLineOffset(linenumber);
        String line = document.get(offset, document.getLineLength(linenumber));
        String qname = reference.getReferencedTypeName().replace('$', '.');
        int first = line.indexOf(qname);
        if (first < 0)
        {
          qname = Signatures.getSimpleTypeName(reference.getReferencedTypeName());
          qname = qname.replace('$', '.');
          first = line.indexOf(qname);
        }
        Position pos = null;
        if (first > -1) {
          pos = new Position(offset + first, qname.length());
        } else {
          pos = new Position(offset, line.length());
        }
        return pos;
      }
      IApiMember apiMember = reference.getMember();
      switch (apiMember.getType())
      {
      case 5: 
        IApiField field = (IApiField)reference.getMember();
        return getSourceRangeForField(type, reference, field);
      case 6: 
        IApiMethod method = (IApiMethod)reference.getMember();
        return getSourceRangeForMethod(type, reference, method);
      }
      ISourceRange range = type.getNameRange();
      Position pos = null;
      if (range != null) {
        pos = new Position(range.getOffset(), range.getLength());
      }
      if (pos == null) {
        return defaultSourcePosition(type, reference);
      }
      return pos;
    case 2: 
      int linenumber = reference.getLineNumber();
      if (linenumber > 0) {
        return getFieldNameRange(reference.getReferencedTypeName(), reference.getReferencedMemberName(), document, reference);
      }
      IApiField field = (IApiField)reference.getMember();
      return getSourceRangeForField(type, reference, field);
    case 3: 
      if (reference.getLineNumber() >= 0)
      {
        String referenceMemberName = reference.getReferencedMemberName();
        String methodName = null;
        boolean isConstructor = Util.isConstructor(referenceMemberName);
        if (isConstructor) {
          methodName = Signatures.getSimpleTypeName(reference.getReferencedTypeName().replace('$', '.'));
        } else {
          methodName = referenceMemberName;
        }
        Position pos = getMethodNameRange(isConstructor, methodName, document, reference);
        if (pos == null) {
          return defaultSourcePosition(type, reference);
        }
        return pos;
      }
      IApiMethod method = (IApiMethod)reference.getMember();
      return getSourceRangeForMethod(type, reference, method);
    }
    return null;
  }
  
  protected boolean isProblem(IReference reference)
  {
    try
    {
      IApiMember member = reference.getMember();
      IApiComponent apiComponent = member.getApiComponent();
      String[] lowestEEs = apiComponent.getLowestEEs();
      if (lowestEEs == null) {
        return false;
      }
      int i = 0;
      for (int max = lowestEEs.length; i < max; i++)
      {
        String lowestEE = lowestEEs[i];
        int eeValue = ProfileModifiers.getValue(lowestEE);
        if (eeValue == 0) {
          return false;
        }
        if (!((Reference)reference).resolve(eeValue))
        {
          if ((apiComponent instanceof BundleComponent))
          {
            BundleDescription bundle = ((BundleComponent)apiComponent).getBundleDescription();
            ImportPackageSpecification[] importPackages = bundle.getImportPackages(
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