/** * 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; }
/** * Returns whether the given type has any visible fields base on the given visibility flags to * consider. A field is visible signals a definite leak. * * @param type type to analyze * @param modifiers visibilities to consider * @return whether there are any visible fields */ private boolean hasVisibleField(IApiType type, int modifiers) { IApiField[] fields = type.getFields(); for (int i = 0; i < fields.length; i++) { IApiField field = fields[i]; if ((field.getModifiers() & modifiers) > 0) { return true; } } return false; }
/** * 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; }
/** * 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); }