/* (non-Javadoc)
  * @see org.eclipse.pde.api.tools.builder.tests.ApiBuilderTest#getDefaultProblemId()
  */
 protected int getDefaultProblemId() {
   if (pid == -1) {
     pid =
         ApiProblemFactory.createProblemId(
             IApiProblem.CATEGORY_USAGE,
             IElementDescriptor.METHOD,
             IApiProblem.API_LEAK,
             IApiProblem.LEAK_RETURN_TYPE);
   }
   return pid;
 }
Exemple #2
0
 /**
  * @param reference
  * @return
  * @throws CoreException
  */
 public IApiProblem createProblem(IReference reference) throws CoreException {
   int lineNumber = reference.getLineNumber();
   if (lineNumber > 0) {
     lineNumber--;
   }
   String ltypename = getTypeName(reference.getMember());
   return ApiProblemFactory.newApiUsageProblem(
       null,
       ltypename,
       getQualifiedMessageArgs(reference),
       new String[] {IApiMarkerConstants.API_MARKER_ATTR_ID},
       new Object[] {new Integer(IApiMarkerConstants.API_USAGE_MARKER_ID)},
       lineNumber,
       IApiProblem.NO_CHARRANGE,
       IApiProblem.NO_CHARRANGE,
       getElementType(reference),
       getProblemKind(),
       getProblemFlags(reference));
 }
Exemple #3
0
 /**
  * Creates a problem for a specific reference in the workspace
  *
  * @param reference reference
  * @param associated java project (with reference source location)
  * @return problem or <code>null</code> if none
  * @exception CoreException if something goes wrong
  */
 protected IApiProblem createProblem(IReference reference, IJavaProject javaProject) {
   IProject project = javaProject.getProject();
   if (ApiPlugin.getDefault().getSeverityLevel(getSeverityKey(), project)
       == ApiPlugin.SEVERITY_IGNORE) {
     return null;
   }
   try {
     String lookupName = getTypeName(reference.getMember()).replace('$', '.');
     IType type = javaProject.findType(lookupName, new NullProgressMonitor());
     if (type == null) {
       return null;
     }
     ICompilationUnit compilationUnit = type.getCompilationUnit();
     if (compilationUnit == null) {
       return null;
     }
     IResource resource = Util.getResource(project, type);
     if (resource == null) {
       return null;
     }
     int charStart = -1;
     int charEnd = -1;
     int lineNumber = reference.getLineNumber();
     IJavaElement element = compilationUnit;
     if (!Util.isManifest(resource.getProjectRelativePath()) && !type.isBinary()) {
       IDocument document = Util.getDocument(compilationUnit);
       // retrieve line number, char start and char end
       if (lineNumber > 0) {
         lineNumber--;
       }
       // get the source range for the problem
       try {
         Position pos = getSourceRange(type, document, reference);
         if (pos != null) {
           charStart = pos.getOffset();
           if (charStart != -1) {
             charEnd = charStart + pos.getLength();
             lineNumber = document.getLineOfOffset(charStart);
           }
         }
       } catch (CoreException e) {
         ApiPlugin.log(e);
         return null;
       } catch (BadLocationException e) {
         ApiPlugin.log(e);
         return null;
       }
       if (charStart > -1) {
         element = compilationUnit.getElementAt(charStart);
       }
     }
     return ApiProblemFactory.newApiUsageProblem(
         resource.getProjectRelativePath().toPortableString(),
         type.getFullyQualifiedName(),
         getMessageArgs(reference),
         new String[] {
           IApiMarkerConstants.MARKER_ATTR_HANDLE_ID, IApiMarkerConstants.API_MARKER_ATTR_ID
         },
         new Object[] {
           (element == null
               ? compilationUnit.getHandleIdentifier()
               : element.getHandleIdentifier()),
           new Integer(IApiMarkerConstants.API_USAGE_MARKER_ID)
         },
         lineNumber,
         charStart,
         charEnd,
         getElementType(reference),
         getProblemKind(),
         getProblemFlags(reference));
   } catch (CoreException e) {
     ApiPlugin.log(e);
   }
   return null;
 }