List of usage examples for java.lang.reflect Modifier FINAL
int FINAL
To view the source code for java.lang.reflect Modifier FINAL.
Click Source Link
From source file:be.fedict.eid.applet.maven.DocbookMojo.java
private void describeClass(Class<?> catalogClass, PrintWriter writer) throws IllegalArgumentException, IllegalAccessException { writer.println("<section id=\"" + catalogClass.getSimpleName() + "\">"); writer.println("<title>" + catalogClass.getSimpleName() + "</title>"); StartRequestMessage startRequestMessage = catalogClass.getAnnotation(StartRequestMessage.class); if (null != startRequestMessage) { writer.println("<para>"); writer.println(/*from www.j a va 2 s . c o m*/ "This message starts a communication session between eID Applet and eID Applet Service."); writer.println("It sets the protocol state to: " + startRequestMessage.value()); writer.println("</para>"); } StopResponseMessage stopResponseMessage = catalogClass.getAnnotation(StopResponseMessage.class); if (null != stopResponseMessage) { writer.println("<para>"); writer.println( "This message stops a communication session between eID Applet and the eID Applet Service."); writer.println("</para>"); } ProtocolStateAllowed protocolStateAllowed = catalogClass.getAnnotation(ProtocolStateAllowed.class); if (null != protocolStateAllowed) { writer.println("<para>"); writer.println("This message is only accepted if the eID Applet Service protocol state is: " + protocolStateAllowed.value()); writer.println("</para>"); } Field bodyField = null; writer.println("<table>"); writer.println("<title>" + catalogClass.getSimpleName() + " HTTP headers</title>"); writer.println("<tgroup cols=\"3\">"); { writer.println("<colspec colwidth=\"2*\" />"); writer.println("<colspec colwidth=\"1*\" />"); writer.println("<colspec colwidth=\"2*\" />"); writer.println("<thead>"); writer.println("<row>"); writer.println("<entry>Header name</entry>"); writer.println("<entry>Required</entry>"); writer.println("<entry>Value</entry>"); writer.println("</row>"); writer.println("</thead>"); writer.println("<tbody>"); { Field[] fields = catalogClass.getFields(); for (Field field : fields) { if (field.getAnnotation(HttpBody.class) != null) { bodyField = field; } HttpHeader httpHeaderAnnotation = field.getAnnotation(HttpHeader.class); if (null == httpHeaderAnnotation) { continue; } writer.println("<row>"); writer.println("<entry>"); writer.println("<code>" + httpHeaderAnnotation.value() + "</code>"); writer.println("</entry>"); writer.println("<entry>"); writer.println((null != field.getAnnotation(NotNull.class)) || (0 != (field.getModifiers() & Modifier.FINAL))); writer.println("</entry>"); writer.println("<entry>"); if (0 != (field.getModifiers() & Modifier.FINAL)) { Object value = field.get(null); writer.println("<code>" + value.toString() + "</code>"); } else { writer.println("Some " + field.getType().getSimpleName() + " value."); } writer.println("</entry>"); writer.println("</row>"); } } writer.println("</tbody>"); } writer.println("</tgroup>"); writer.println("</table>"); if (null != bodyField) { writer.println("<para>HTTP body should contain the data.</para>"); Description description = bodyField.getAnnotation(Description.class); if (null != description) { writer.println("<para>Body content: "); writer.println(description.value()); writer.println("</para>"); } } ResponsesAllowed responsesAllowedAnnotation = catalogClass.getAnnotation(ResponsesAllowed.class); if (null != responsesAllowedAnnotation) { Class<?>[] responsesAllowed = responsesAllowedAnnotation.value(); writer.println("<para>"); writer.println("Allowed eID Applet Service response messages are: "); for (Class<?> responseAllowed : responsesAllowed) { writer.println("<xref linkend=\"" + responseAllowed.getSimpleName() + "\"/>"); } writer.println("</para>"); } StateTransition stateTransition = catalogClass.getAnnotation(StateTransition.class); if (null != stateTransition) { writer.println("<para>"); writer.println("This message will perform an eID Applet protocol state transition to: " + stateTransition.value()); writer.println("</para>"); } writer.println("</section>"); }
From source file:de.micromata.genome.util.bean.PrivateBeanUtils.java
/** * Write final static field.//ww w . j a va 2s. com * * @param field the field * @param value the value */ public static void writeFinalStaticField(Field field, Object value) { AccessibleScope ascope = new AccessibleScope(field); try { Field modifiersField = Field.class.getDeclaredField("modifiers"); AccessibleScope modscope = new AccessibleScope(field); try { int oldmods = field.getModifiers(); modifiersField.setInt(field, oldmods & ~Modifier.FINAL); writeField(null, field, value); modifiersField.setInt(field, oldmods); } finally { modscope.restore(); } } catch (RuntimeException ex) { // NOSONAR "Illegal Catch" framework throw ex; // NOSONAR "Illegal Catch" framework } catch (Exception ex) { // NOSONAR "Illegal Catch" framework throw new RuntimeException( "Cannot write field: " + field.getDeclaringClass().getName() + "." + field.getName());// NOSONAR "Illegal Catch" framework } finally { ascope.restore(); } }
From source file:com.serli.chell.framework.form.FormStructure.java
private static boolean isFormField(Field field, Class<?> fieldType) { return ((field.getModifiers() & (Modifier.STATIC | Modifier.FINAL)) == 0) && (fieldType.equals(String.class) || fieldType.equals(String[].class) && !field.isAnnotationPresent(HtmlTransient.class)); }
From source file:co.cask.cdap.filetailer.FileTailerIT.java
private void mockMetricsProcessor(PipeManager manager) throws IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException { List<Pipe> pipeList = new ArrayList<Pipe>(); StreamClient client = null;//from w w w . j av a 2 s .co m StreamWriter writer = null; try { Method method1 = manager.getClass().getDeclaredMethod("getPipeConfigs"); method1.setAccessible(true); List<PipeConfiguration> pipeConfList = (List<PipeConfiguration>) method1.invoke(manager); for (PipeConfiguration pipeConf : pipeConfList) { FileTailerQueue queue = new FileTailerQueue(pipeConf.getQueueSize()); client = pipeConf.getSinkConfiguration().getStreamClient(); String streamName = pipeConf.getSinkConfiguration().getStreamName(); Method method2 = manager.getClass().getDeclaredMethod("getStreamWriterForPipe", StreamClient.class, String.class); method2.setAccessible(true); writer = (StreamWriter) method2.invoke(manager, client, streamName); FileTailerStateProcessor stateProcessor = new FileTailerStateProcessorImpl(pipeConf.getDaemonDir(), pipeConf.getStateFile()); FileTailerMetricsProcessor metricsProcessor = new FileTailerMetricsProcessor( pipeConf.getDaemonDir(), pipeConf.getStatisticsFile(), pipeConf.getStatisticsSleepInterval(), pipeConf.getPipeName(), pipeConf.getSourceConfiguration().getFileName()) { @Override public void onReadEventMetric(int eventSize) { super.onReadEventMetric(eventSize); read.incrementAndGet(); } @Override public void onIngestEventMetric(int latency) { super.onIngestEventMetric(latency); ingest.incrementAndGet(); } }; pipeList.add(new Pipe(new LogTailer(pipeConf, queue, stateProcessor, metricsProcessor, null), new FileTailerSink(queue, writer, SinkStrategy.LOADBALANCE, stateProcessor, metricsProcessor, null, pipeConf.getSinkConfiguration().getPackSize()), metricsProcessor)); client = null; writer = null; } Field field = manager.getClass().getDeclaredField("serviceManager"); field.setAccessible(true); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.set(manager, new ServiceManager(pipeList)); } finally { if (client != null) { client.close(); } if (writer != null) { writer.close(); } } }
From source file:com.adobe.cq.wcm.core.components.extension.contentfragment.internal.models.v1.ContentFragmentImplTest.java
@Before public void setTestFixture() throws NoSuchFieldException, IllegalAccessException { cfmLogger = spy(LoggerFactory.getLogger("FakeLogger")); Field field = ContentFragmentImpl.class.getDeclaredField("LOG"); Field modifiersField = Field.class.getDeclaredField("modifiers"); field.setAccessible(true);// w w w .j a v a2s. c o m // remove final modifier from field modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.set(null, cfmLogger); }
From source file:de.tuberlin.uebb.jbop.access.ClassAccessor.java
/** * Tests whether the given field of input is final. * //from ww w . ja v a 2 s. c om * @param input * the object * @param fieldName * the field name * @return true, if is final */ public static boolean isFinal(final Object input, final String fieldName) { final Field declaredField = getField(input, fieldName); if (declaredField == null) { return false; } return (declaredField.getModifiers() & Modifier.FINAL) != 0; }
From source file:hu.bme.mit.sette.common.model.snippet.SnippetContainer.java
/** * Validates methods of the class.// www.ja v a 2s. co m * * @param validator * a validator * @return a map containing the snippet methods by their name */ private Map<String, Method> validateMethods(final AbstractValidator<?> validator) { // check: only "[public|private] static" or synthetic methods Map<String, Method> snippetMethods = new HashMap<String, Method>(); for (Method method : javaClass.getDeclaredMethods()) { if (method.isSynthetic()) { // skip synthetic methods continue; } MethodValidator v = new MethodValidator(method); if (snippetMethods.get(method.getName()) != null) { v.addException("The method must have a unique name"); } int methodModifiers = method.getModifiers(); if (!Modifier.isPublic(methodModifiers) && !Modifier.isPrivate(methodModifiers)) { v.addException("The method must be public or private"); } v.withModifiers(Modifier.STATIC); v.withoutModifiers(Modifier.ABSTRACT | Modifier.FINAL | Modifier.NATIVE | Modifier.SYNCHRONIZED); AnnotationMap methodAnns = SetteAnnotationUtils.getSetteAnnotations(method); if (Modifier.isPublic(methodModifiers)) { if (methodAnns.get(SetteNotSnippet.class) == null) { // should be snippet, validated by Snippet class and added // later snippetMethods.put(method.getName(), method); } else { // not snippet snippetMethods.put(method.getName(), null); if (methodAnns.size() != 1) { v.addException("The method must not have " + "any other SETTE annotations " + "if it is not a snippet."); } } } else { // method is private if (methodAnns.size() != 0) { v.addException("The method must not have " + "any SETTE annotations"); } } validator.addChildIfInvalid(v); } return snippetMethods; }
From source file:net.minecraftforge.common.util.EnumHelper.java
@SuppressWarnings({ "unchecked", "serial" }) @Nullable/* w w w . j a va2s . c o m*/ private static <T extends Enum<?>> T addEnum(boolean test, final Class<T> enumType, @Nullable String enumName, final Class<?>[] paramTypes, @Nullable Object[] paramValues) { if (!isSetup) { setup(); } Field valuesField = null; Field[] fields = enumType.getDeclaredFields(); for (Field field : fields) { String name = field.getName(); if (name.equals("$VALUES") || name.equals("ENUM$VALUES")) //Added 'ENUM$VALUES' because Eclipse's internal compiler doesn't follow standards { valuesField = field; break; } } int flags = (FMLForgePlugin.RUNTIME_DEOBF ? Modifier.PUBLIC : Modifier.PRIVATE) | Modifier.STATIC | Modifier.FINAL | 0x1000 /*SYNTHETIC*/; if (valuesField == null) { String valueType = String.format("[L%s;", enumType.getName().replace('.', '/')); for (Field field : fields) { if ((field.getModifiers() & flags) == flags && field.getType().getName().replace('.', '/').equals(valueType)) //Apparently some JVMs return .'s and some don't.. { valuesField = field; break; } } } if (valuesField == null) { final List<String> lines = Lists.newArrayList(); lines.add(String.format("Could not find $VALUES field for enum: %s", enumType.getName())); lines.add(String.format("Runtime Deobf: %s", FMLForgePlugin.RUNTIME_DEOBF)); lines.add(String.format("Flags: %s", String.format("%16s", Integer.toBinaryString(flags)).replace(' ', '0'))); lines.add("Fields:"); for (Field field : fields) { String mods = String.format("%16s", Integer.toBinaryString(field.getModifiers())).replace(' ', '0'); lines.add(String.format(" %s %s: %s", mods, field.getName(), field.getType().getName())); } for (String line : lines) FMLLog.log.fatal(line); if (test) { throw new EnhancedRuntimeException("Could not find $VALUES field for enum: " + enumType.getName()) { @Override protected void printStackTrace(WrappedPrintStream stream) { for (String line : lines) stream.println(line); } }; } return null; } if (test) { Object ctr = null; Exception ex = null; try { ctr = getConstructorAccessor(enumType, paramTypes); } catch (Exception e) { ex = e; } if (ctr == null || ex != null) { throw new EnhancedRuntimeException( String.format("Could not find constructor for Enum %s", enumType.getName()), ex) { private String toString(Class<?>[] cls) { StringBuilder b = new StringBuilder(); for (int x = 0; x < cls.length; x++) { b.append(cls[x].getName()); if (x != cls.length - 1) b.append(", "); } return b.toString(); } @Override protected void printStackTrace(WrappedPrintStream stream) { stream.println("Target Arguments:"); stream.println(" java.lang.String, int, " + toString(paramTypes)); stream.println("Found Constructors:"); for (Constructor<?> ctr : enumType.getDeclaredConstructors()) { stream.println(" " + toString(ctr.getParameterTypes())); } } }; } return null; } valuesField.setAccessible(true); try { T[] previousValues = (T[]) valuesField.get(enumType); T newValue = makeEnum(enumType, enumName, previousValues.length, paramTypes, paramValues); setFailsafeFieldValue(valuesField, null, ArrayUtils.add(previousValues, newValue)); cleanEnumCache(enumType); return newValue; } catch (Exception e) { FMLLog.log.error("Error adding enum with EnumHelper.", e); throw new RuntimeException(e); } }
From source file:org.codehaus.groovy.grails.compiler.web.ControllerActionTransformer.java
private void processMethods(ClassNode classNode, SourceUnit source, GeneratorContext context) { List<MethodNode> deferredNewMethods = new ArrayList<MethodNode>(); for (MethodNode method : classNode.getMethods()) { if (!method.isStatic() && method.isPublic() && method.getAnnotations(ACTION_ANNOTATION_NODE.getClassNode()).isEmpty() && method.getLineNumber() >= 0) { if (method.getReturnType().getName().equals(VOID_TYPE) || isExceptionHandlingMethod(method)) continue; final List<MethodNode> declaredMethodsWithThisName = classNode.getDeclaredMethods(method.getName()); if (declaredMethodsWithThisName != null) { final int numberOfNonExceptionHandlerMethodsWithThisName = org.apache.commons.collections.CollectionUtils .countMatches(declaredMethodsWithThisName, new Predicate() { public boolean evaluate(Object object) { return !isExceptionHandlingMethod((MethodNode) object); }// w w w .j a v a2s . c o m }); if (numberOfNonExceptionHandlerMethodsWithThisName > 1) { String message = "Controller actions may not be overloaded. The [" + method.getName() + "] action has been overloaded in [" + classNode.getName() + "]."; GrailsASTUtils.error(source, method, message); } } MethodNode wrapperMethod = convertToMethodAction(classNode, method, source, context); if (wrapperMethod != null) { deferredNewMethods.add(wrapperMethod); } } } Collection<MethodNode> exceptionHandlerMethods = getExceptionHandlerMethods(classNode, source); final FieldNode exceptionHandlerMetaDataField = classNode.getField(EXCEPTION_HANDLER_META_DATA_FIELD_NAME); if (exceptionHandlerMetaDataField == null || !exceptionHandlerMetaDataField.getDeclaringClass().equals(classNode)) { final ListExpression listOfExceptionHandlerMetaData = new ListExpression(); for (final MethodNode exceptionHandlerMethod : exceptionHandlerMethods) { final Class<?> exceptionHandlerExceptionType = exceptionHandlerMethod.getParameters()[0].getType() .getPlainNodeReference().getTypeClass(); final String exceptionHandlerMethodName = exceptionHandlerMethod.getName(); final ArgumentListExpression defaultControllerExceptionHandlerMetaDataCtorArgs = new ArgumentListExpression(); defaultControllerExceptionHandlerMetaDataCtorArgs .addExpression(new ConstantExpression(exceptionHandlerMethodName)); defaultControllerExceptionHandlerMetaDataCtorArgs .addExpression(new ClassExpression(new ClassNode(exceptionHandlerExceptionType))); listOfExceptionHandlerMetaData.addExpression(new ConstructorCallExpression( new ClassNode(DefaultControllerExceptionHandlerMetaData.class), defaultControllerExceptionHandlerMetaDataCtorArgs)); } classNode.addField(EXCEPTION_HANDLER_META_DATA_FIELD_NAME, Modifier.STATIC | Modifier.PRIVATE | Modifier.FINAL, new ClassNode(List.class), listOfExceptionHandlerMetaData); } for (MethodNode newMethod : deferredNewMethods) { classNode.addMethod(newMethod); } }
From source file:org.kaaproject.kaa.server.verifiers.facebook.verifier.FacebookUserVerifierTest.java
private void setFinalStatic(Field field, Object newValue) throws Exception { field.setAccessible(true);/*from w ww . j a va 2 s . co m*/ Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.set(null, newValue); }