/*
  * (non-Javadoc)
  * @see
  * org.eclipse.pde.api.tools.internal.search.AbstractProblemDetector#isProblem
  * (org.eclipse.pde.api.tools.internal.provisional.model.IReference)
  */
 @Override
 protected boolean isProblem(IReference reference) {
   // the reference must be in the system library
   try {
     IApiMember member = reference.getMember();
     IApiComponent apiComponent = member.getApiComponent();
     String[] lowestEEs = apiComponent.getLowestEEs();
     if (lowestEEs == null) {
       // this should not be true for Eclipse bundle as they should
       // always have a EE set
       return false;
     }
     loop:
     for (int i = 0, max = lowestEEs.length; i < max; i++) {
       String lowestEE = lowestEEs[i];
       int eeValue = ProfileModifiers.getValue(lowestEE);
       if (eeValue == ProfileModifiers.NO_PROFILE_VALUE) {
         return false;
       }
       if (!((Reference) reference).resolve(eeValue)) {
         /*
          * Make sure that the resolved reference doesn't below to
          * one of the imported package of the current component
          */
         if (apiComponent instanceof BundleComponent) {
           BundleDescription bundle = ((BundleComponent) apiComponent).getBundleDescription();
           ImportPackageSpecification[] importPackages = bundle.getImportPackages();
           String referencedTypeName = reference.getReferencedTypeName();
           int index = referencedTypeName.lastIndexOf('.');
           String packageName = referencedTypeName.substring(0, index);
           for (int j = 0, max2 = importPackages.length; j < max2; j++) {
             ImportPackageSpecification importPackageSpecification = importPackages[j];
             // get the IPackageDescriptor for the element
             // descriptor
             String importPackageName = importPackageSpecification.getName();
             if (importPackageName.equals(packageName)) {
               continue loop;
             }
           }
         }
         if (this.referenceEEs == null) {
           this.referenceEEs = new HashMap<IReference, Integer>(3);
         }
         this.referenceEEs.put(reference, new Integer(eeValue));
         return true;
       }
     }
   } catch (CoreException e) {
     ApiPlugin.log(e);
   }
   return false;
 }
 /*
  * (non-Javadoc)
  * @see org.eclipse.pde.api.tools.internal.builder.AbstractProblemDetector#
  * getMessageArgs
  * (org.eclipse.pde.api.tools.internal.provisional.builder.IReference)
  */
 @Override
 protected String[] getMessageArgs(IReference reference) throws CoreException {
   IApiMember member = reference.getMember();
   String eeValue = ProfileModifiers.getName(this.referenceEEs.get(reference).intValue());
   String simpleTypeName = Signatures.getSimpleTypeName(reference.getReferencedTypeName());
   if (simpleTypeName.indexOf('$') != -1) {
     simpleTypeName = simpleTypeName.replace('$', '.');
   }
   switch (reference.getReferenceType()) {
     case IReference.T_TYPE_REFERENCE:
       {
         return new String[] {
           getDisplay(member, false), simpleTypeName, eeValue,
         };
       }
     case IReference.T_FIELD_REFERENCE:
       {
         return new String[] {
           getDisplay(member, false), simpleTypeName,
           reference.getReferencedMemberName(), eeValue,
         };
       }
     case IReference.T_METHOD_REFERENCE:
       {
         String referenceMemberName = reference.getReferencedMemberName();
         if (Util.isConstructor(referenceMemberName)) {
           return new String[] {
             getDisplay(member, false),
             Signature.toString(
                 reference.getReferencedSignature(), simpleTypeName, null, false, false),
             eeValue,
           };
         } else {
           return new String[] {
             getDisplay(member, false),
             simpleTypeName,
             Signature.toString(
                 reference.getReferencedSignature(), referenceMemberName, null, false, false),
             eeValue,
           };
         }
       }
     default:
       break;
   }
   return null;
 }
Exemple #3
0
 /**
  * Returns whether the referenced type name matches a non-API package.
  *
  * @param reference
  * @return whether the referenced type name matches a non-API package
  */
 protected boolean isNonAPIReference(IReference reference) {
   String packageName = Signatures.getPackageName(reference.getReferencedTypeName());
   if (fNonApiPackageNames.contains(packageName)) {
     return true;
   }
   // could be a reference to a package visible type
   IApiMember member = reference.getMember();
   IApiType type = null;
   if (member.getType() == IApiElement.TYPE) {
     type = (IApiType) member;
   } else {
     type = (IApiType) member.getAncestor(IApiElement.TYPE);
   }
   String origin = Signatures.getPackageName(type.getName());
   if (packageName.equals(origin)) {
     return true; // possible package visible reference
   }
   return false;
 }
 /*
  * (non-Javadoc)
  * @see
  * org.eclipse.pde.api.tools.internal.provisional.builder.IApiProblemDetector
  * #
  * considerReference(org.eclipse.pde.api.tools.internal.provisional.builder.
  * IReference)
  */
 @Override
 public boolean considerReference(IReference reference) {
   try {
     IApiComponent apiComponent = reference.getMember().getApiComponent();
     IApiBaseline baseline = apiComponent.getBaseline();
     if (baseline == null) {
       return false;
     }
     String referencedTypeName = reference.getReferencedTypeName();
     // extract the package name
     int index = referencedTypeName.lastIndexOf('.');
     if (index == -1) {
       return false;
     }
     String substring = referencedTypeName.substring(0, index);
     IApiComponent[] resolvePackages = baseline.resolvePackage(apiComponent, substring);
     switch (resolvePackages.length) {
       case 1:
         {
           if (resolvePackages[0].isSystemComponent()) {
             switch (reference.getReferenceKind()) {
               case IReference.REF_OVERRIDE:
               case IReference.REF_CONSTANTPOOL:
                 return false;
               default:
                 break;
             }
             ((Reference) reference).setResolveStatus(false);
             retainReference(reference);
             return true;
           }
           break;
         }
       default:
         break;
     }
   } catch (CoreException e) {
     ApiPlugin.log(e);
   }
   return false;
 }
 /*
  * (non-Javadoc)
  * @see org.eclipse.pde.api.tools.internal.builder.AbstractProblemDetector#
  * getSourceRange(org.eclipse.jdt.core.IType,
  * org.eclipse.jface.text.IDocument,
  * org.eclipse.pde.api.tools.internal.provisional.builder.IReference)
  */
 @Override
 protected Position getSourceRange(IType type, IDocument document, IReference reference)
     throws CoreException, BadLocationException {
   switch (reference.getReferenceType()) {
     case IReference.T_TYPE_REFERENCE:
       {
         int linenumber = reference.getLineNumber();
         if (linenumber > 0) {
           // line number starts at 0 for the
           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 {
             // optimistically select the whole line since we can't
             // find the correct variable name and we can't just
             // select
             // the first occurrence
             pos = new Position(offset, line.length());
           }
           return pos;
         } else {
           IApiMember apiMember = reference.getMember();
           switch (apiMember.getType()) {
             case IApiElement.FIELD:
               {
                 IApiField field = (IApiField) reference.getMember();
                 return getSourceRangeForField(type, reference, field);
               }
             case IApiElement.METHOD:
               {
                 // reference in a method declaration
                 IApiMethod method = (IApiMethod) reference.getMember();
                 return getSourceRangeForMethod(type, reference, method);
               }
             default:
               break;
           }
           // reference in a type declaration
           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 IReference.T_FIELD_REFERENCE:
       {
         int linenumber = reference.getLineNumber();
         if (linenumber > 0) {
           return getFieldNameRange(
               reference.getReferencedTypeName(),
               reference.getReferencedMemberName(),
               document,
               reference);
         }
         // reference in a field declaration
         IApiField field = (IApiField) reference.getMember();
         return getSourceRangeForField(type, reference, field);
       }
     case IReference.T_METHOD_REFERENCE:
       {
         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;
         }
         // reference in a method declaration
         IApiMethod method = (IApiMethod) reference.getMember();
         return getSourceRangeForMethod(type, reference, method);
       }
     default:
       return null;
   }
 }