/** * 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; }
/** * 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; }
/** * Returns the constant value for the given field. * * @param field the field * @param editorInputElement the editor input element * @param hoverRegion the hover region in the editor * @return the constant value for the given field or <code>null</code> if none * @since 3.4 */ private static String getConstantValue(IField field, ITypeRoot editorInputElement, IRegion hoverRegion) { if (!isStaticFinal(field)) return null; Object constantValue; if (editorInputElement == null || hoverRegion == null) { constantValue= JavadocView.computeFieldConstantFromTypeAST(field, null); } else { ASTNode node= getHoveredASTNode(editorInputElement, hoverRegion); if (node == null) return null; constantValue= getVariableBindingConstValue(node, field); } if (constantValue == null) return null; if (constantValue instanceof String) { return ASTNodes.getEscapedStringLiteral((String) constantValue); } else { return getHexConstantValue(constantValue); } }
/** * Returns the constant value for the given field. * * @param field the field * @param editorInputElement the editor input element * @param hoverRegion the hover region in the editor * @return the constant value for the given field or <code>null</code> if none * @since 3.4 */ private static String getConstantValue(IField field, ITypeRoot editorInputElement, IRegion hoverRegion) { if (!isStaticFinal(field)) return null; Object constantValue; if (editorInputElement == null || hoverRegion == null) { constantValue= JavadocView.computeFieldConstantFromTypeAST(field, null); } else { ASTNode node= getHoveredASTNode(editorInputElement, hoverRegion); if (node == null) return null; constantValue= getVariableBindingConstValue(node, field); } if (constantValue == null) return null; if (constantValue instanceof String) { return ASTNodes.getEscapedStringLiteral((String) constantValue); } else { return getHexConstantValue(constantValue); } }