/**
  * Returns the signature to display for found problems
  *
  * @param member the member to get the signature from
  * @param qualified if the returned signature should be type-qualified or not
  * @return
  * @throws CoreException
  */
 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 IApiElement.FIELD:
       {
         StringBuffer buffer = new StringBuffer();
         IApiField field = (IApiField) member;
         buffer.append(typeName).append('.').append(field.getName());
         return String.valueOf(buffer);
       }
     case IApiElement.METHOD:
       {
         // reference in a method declaration
         IApiMethod method = (IApiMethod) member;
         if (qualified) {
           return Signatures.getMethodSignature(method);
         }
         return Signatures.getQualifiedMethodSignature(method);
       }
     default:
       break;
   }
   return typeName;
 }
Exemple #2
0
 /**
  * Returns the source range to use for the given field within the given {@link IType}
  *
  * @param type the type to look in for the given {@link IApiField}
  * @param reference the reference the field is involved in
  * @param field the field to find the range for
  * @return the {@link ISourceRange} in the given {@link IType} that encloses the given {@link
  *     IApiField}
  * @throws JavaModelException
  * @throws CoreException
  */
 protected Position getSourceRangeForField(IType type, IReference reference, IApiField field)
     throws JavaModelException, CoreException {
   IField javaField = type.getField(field.getName());
   Position pos = null;
   if (javaField.exists()) {
     ISourceRange range = javaField.getNameRange();
     if (range != null) {
       pos = new Position(range.getOffset(), range.getLength());
     }
   }
   if (pos == null) {
     return defaultSourcePosition(type, reference);
   }
   return pos;
 }
Exemple #3
0
 /**
  * Returns the range of the name of the given {@link IApiField} to select when creating {@link
  * IApiProblem}s. Source ranges are computed and tried in the following order:
  *
  * <ol>
  *   <li>Try the type-qualified name of the variable
  *   <li>Try looking for 'super.variable'
  *   <li>Try looking for 'this.variable'
  *   <li>Try looking for pattern '*.variable'
  *   <li>Else select the entire line optimistically
  * </ol>
  *
  * @param field the field to find the name range for
  * @param document the document to look within
  * @param reference the reference the field is from
  * @return the range of text to select, or <code>null</code> if one could not be computed
  * @throws BadLocationException
  * @throws CoreException
  */
 protected Position getFieldNameRange(IApiField field, IDocument document, IReference reference)
     throws BadLocationException, CoreException {
   return getFieldNameRange(
       field.getEnclosingType().getName(), field.getName(), document, reference);
 }