/** * Compute the textual representation of a 'static' 'final' field's constant initializer value. * * @param activePart the part that triggered the computation, or <code>null</code> * @param selection the selection that references the field, or <code>null</code> * @param resolvedField the filed whose constant value will be computed * @param monitor the progress monitor * * @return the textual representation of the constant, or <code>null</code> if the * field is not a constant field, the initializer value could not be computed, or * the progress monitor was cancelled * @since 3.4 */ private String computeFieldConstant(IWorkbenchPart activePart, ISelection selection, IField resolvedField, IProgressMonitor monitor) { if (!JavadocHover.isStaticFinal(resolvedField)) return null; Object constantValue; if (selection instanceof ITextSelection && activePart instanceof JavaEditor) { IEditorPart editor= (IEditorPart) activePart; ITypeRoot activeType= JavaUI.getEditorInputTypeRoot(editor.getEditorInput()); constantValue= getConstantValueFromActiveEditor(activeType, resolvedField, (ITextSelection) selection, monitor); if (constantValue == null) // fall back - e.g. when selection is inside Javadoc of the element constantValue= computeFieldConstantFromTypeAST(resolvedField, monitor); } else { constantValue= computeFieldConstantFromTypeAST(resolvedField, monitor); } if (constantValue != null) return JavadocHover.CONSTANT_VALUE_SEPARATOR + formatCompilerConstantValue(constantValue); return null; }
/** * Compute the textual representation of a 'static' 'final' field's constant initializer value. * * @param activePart the part that triggered the computation, or <code>null</code> * @param selection the selection that references the field, or <code>null</code> * @param resolvedField the field whose constant value will be computed * @param monitor the progress monitor * * @return the textual representation of the constant, or <code>null</code> if the * field is not a constant field, the initializer value could not be computed, or * the progress monitor was cancelled * @since 3.4 */ private String computeFieldConstant(IWorkbenchPart activePart, ISelection selection, IField resolvedField, IProgressMonitor monitor) { if (!JavadocHover.isStaticFinal(resolvedField)) return null; Object constantValue; if (selection instanceof ITextSelection && activePart instanceof JavaEditor) { IEditorPart editor= (IEditorPart) activePart; ITypeRoot activeType= JavaUI.getEditorInputTypeRoot(editor.getEditorInput()); constantValue= getConstantValueFromActiveEditor(activeType, resolvedField, (ITextSelection) selection, monitor); if (constantValue == null) // fall back - e.g. when selection is inside Javadoc of the element constantValue= computeFieldConstantFromTypeAST(resolvedField, monitor); } else { constantValue= computeFieldConstantFromTypeAST(resolvedField, monitor); } if (constantValue != null) return JavadocHover.CONSTANT_VALUE_SEPARATOR + formatCompilerConstantValue(constantValue); return null; }