List of usage examples for java.lang.reflect Modifier STATIC
int STATIC
To view the source code for java.lang.reflect Modifier STATIC.
Click Source Link
From source file:com.industrieit.ohr.OHRJavassister.java
private static void setBaseMixinsPre(CtClass cc, boolean includeChecks) throws CannotCompileException, IOException, NotFoundException { //add fields// w w w . jav a2 s . c o m //add basePtr //CtField cf = new CtField(CtClass.longType, "crapField", cc); //cf.setModifiers(Modifier.PRIVATE | Modifier.VOLATILE); //cc.addField(cf); //add basePtr CtField f = new CtField(CtClass.longType, "basePtr", cc); f.setModifiers(Modifier.PRIVATE | Modifier.VOLATILE); cc.addField(f); //add instmarker CtField fm = new CtField(CtClass.intType, "instmarker", cc); fm.setModifiers(Modifier.PRIVATE | Modifier.VOLATILE); cc.addField(fm); CtClass cu = getDefault().get("sun.misc.Unsafe"); CtField f2 = new CtField(cu, "u", cc); f2.setModifiers(Modifier.STATIC | Modifier.PRIVATE); cc.addField(f2); //add check method String checkmeth = "public void doOHRCheck() { if (u.getInt(basePtr+4)!=instmarker) throw new com.industrieit.ohr.StaleHandleException(\"bad instmarker\"); }"; //PL.pl(checkmeth); CtMethod cm = CtNewMethod.make(checkmeth, cc); cc.addMethod(cm); String str = IOUtils.toString(OHRJavassister.class.getResourceAsStream("/ohr/base/basemethodspre.txt")); String checkplace = ""; if (includeChecks) { checkplace = "doOHRCheck();"; } //place in prechecks if desired str = str.replace("<<READCHECK>>", checkplace); str = str.replace("<<WRITECHECK>>", checkplace); StringTokenizer st = new StringTokenizer(str, "~~~"); while (st.hasMoreElements()) { String meth = st.nextToken(); //PL.pl("adding method: " + meth); CtMethod wmethod = CtNewMethod.make(meth, cc); cc.addMethod(wmethod); } }
From source file:info.raack.appliancelabeler.web.MainController.java
@RequestMapping(value = "/energy/{frequency}", method = RequestMethod.GET) public void getEnergyData(@PathVariable("frequency") String frequency, @RequestParam(value = "start", required = false) Double startMillis, @RequestParam(value = "end", required = false) Double endMillis, @RequestParam(value = "ticks", required = false) Integer ticks, HttpServletRequest request, HttpServletResponse response) throws IOException { // need to get latest values from stepgreen service EnergyMonitor energyMonitor = getCurrentEnergyMonitor(request, response); Date start = new Date(); Date end = new Date(); if (startMillis != null && endMillis != null) { start = new Date(startMillis.longValue()); end = new Date(endMillis.longValue()); } else if (startMillis != null && endMillis == null) { // if only start or end are provided, create a one day span Calendar c = new GregorianCalendar(); c.setTimeInMillis(startMillis.longValue()); start = new Date(); start.setTime(startMillis.longValue()); c.add(Calendar.DATE, 1);//from w ww . j a va 2s . c o m end = c.getTime(); } else if (startMillis == null && endMillis != null) { // if only start or end are provided, create a one day span Calendar c = new GregorianCalendar(); c.setTimeInMillis(endMillis.longValue()); end = new Date(); end.setTime(endMillis.longValue()); c.add(Calendar.DATE, -1); start = c.getTime(); } else { createOneDaySpan(energyMonitor, start, end); } if (ticks == null) { ticks = 300; } Date queryStart = null; Date queryEnd = null; // if the time window is less than 5 minutes, then just take the window as is; otherwise, enlarge the window to the 5 minute interval requested if (end.getTime() - start.getTime() > (5 * 60 * 1000)) { Calendar cal = new GregorianCalendar(); cal.setTime(start); queryStart = dateUtils.getPreviousFiveMinuteIncrement(cal).getTime(); cal = new GregorianCalendar(); cal.setTime(end); queryEnd = dateUtils.getNextFiveMinuteIncrement(cal).getTime(); } else { queryStart = start; queryEnd = end; } List<SecondData> data = getEnergyDataWithLimits(energyMonitor, DataService.DataFrequency.valueOf(frequency.toUpperCase()), queryStart, queryEnd, ticks); Map<UserAppliance, List<EnergyTimestep>> predictedEnergyUsage = dataService .getApplianceEnergyConsumptionForMonitor(energyMonitor, algorithm.getId(), queryStart, queryEnd); Map<UserAppliance, List<ApplianceStateTransition>> predictedApplianceStateTransitions = dataService .getPredictedApplianceStateTransitionsForMonitor(energyMonitor, algorithm.getId(), queryStart, queryEnd); JsonSerializer<EnergyTimestep> dateSerializer = new JsonSerializer<EnergyTimestep>() { // serialize date to milliseconds since epoch public JsonElement serialize(EnergyTimestep energyTimestep, Type me, JsonSerializationContext arg2) { JsonArray object = new JsonArray(); object.add(new JsonPrimitive(energyTimestep.getStartTime().getTime())); object.add(new JsonPrimitive(energyTimestep.getEnergyConsumed())); return object; } }; EnergyWrapper energyWrapper = new EnergyWrapper(data, predictedEnergyUsage, predictedApplianceStateTransitions, database.getEnergyCost(energyMonitor)); String dataJS = new GsonBuilder().registerTypeAdapter(EnergyTimestep.class, dateSerializer) .excludeFieldsWithModifiers(Modifier.STATIC).setExclusionStrategies(new ExclusionStrategy() { // skip logger public boolean shouldSkipClass(Class<?> clazz) { return clazz.equals(Logger.class); } public boolean shouldSkipField(FieldAttributes fieldAttributes) { // skip endTime of energytimestep return (fieldAttributes.getName().equals("endTime") && fieldAttributes.getDeclaringClass() == EnergyTimestep.class) || // skip userAppliance, detectionAlgorithmId of appliance state transition ((fieldAttributes.getName().equals("userAppliance") || fieldAttributes.getName().equals("detectionAlgorithmId")) && fieldAttributes.getDeclaringClass() == ApplianceStateTransition.class); } }).create().toJson(energyWrapper); response.getWriter().write(dataJS); // set appropriate JSON response type response.setContentType("application/json"); }
From source file:com.jeeframework.util.classes.ClassUtils.java
/** * Return a static method of a class.//from www. j av a2s .com * @param methodName the static method name * @param clazz the class which defines the method * @param args the parameter types to the method * @return the static method, or <code>null</code> if no static method was found * @throws IllegalArgumentException if the method name is blank or the clazz is null */ public static Method getStaticMethod(Class clazz, String methodName, Class[] args) { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(methodName, "Method name must not be null"); try { Method method = clazz.getDeclaredMethod(methodName, args); if ((method.getModifiers() & Modifier.STATIC) != 0) { return method; } } catch (NoSuchMethodException ex) { } return null; }
From source file:com.taobao.weex.wson.Wson.java
private static final List<Field> getBeanFields(String key, Class targetClass) { List<Field> fieldList = fieldsCache.get(key); if (fieldList == null) { Field[] fields = targetClass.getFields(); fieldList = new ArrayList<>(fields.length); for (Field field : fields) { if ((field.getModifiers() & Modifier.STATIC) != 0) { continue; }/*w ww .j av a2 s. c om*/ if (field.getAnnotation(JSONField.class) != null) { throw new UnsupportedOperationException( "getBeanMethod JSONField Annotation Not Handled, Use toJSON"); } fieldList.add(field); } fieldsCache.put(key, fieldList); } return fieldList; }
From source file:org.gvnix.web.screen.roo.addon.AbstractPatternMetadata.java
protected FieldMetadata getDefinedPatternField() { String definedPatternIds = ""; for (String definedPattern : patterns) { if (definedPatternIds.length() > 0) { definedPatternIds = definedPatternIds.concat(", "); }/*w w w . ja v a 2s .c om*/ definedPatternIds = definedPatternIds.concat("\"").concat(definedPattern.split("=")[0]).concat("\""); } FieldMetadataBuilder fmb = null; JavaSymbolName fieldName = new JavaSymbolName("definedPatterns"); JavaType stringArray = new JavaType(JavaType.STRING.getFullyQualifiedTypeName(), 1, DataType.TYPE, null, null); FieldMetadata field = fieldExists(fieldName, stringArray); if (field != null) { String initializer = field.getFieldInitializer(); initializer = initializer.replace("{", "").replace("}", "").replace(" ", "").replace("\"", ""); for (String pattern : initializer.split(",")) { if (!definedPatternIds.contains(pattern)) { if (definedPatternIds.length() > 0) { definedPatternIds = definedPatternIds.concat(", "); } definedPatternIds = definedPatternIds.concat("\"").concat(pattern).concat("\""); } } fmb = new FieldMetadataBuilder(field); fmb.setFieldInitializer("{ ".concat(definedPatternIds).concat(" }")); } if (fmb == null) { fmb = new FieldMetadataBuilder(getId(), Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL, fieldName, stringArray, "{ ".concat(definedPatternIds).concat(" }")); } field = fmb.build(); controllerFields.add(field); return field; }
From source file:org.gvnix.web.screen.roo.addon.AbstractPatternMetadata.java
protected void addStaticFields() { FieldMetadataBuilder field = new FieldMetadataBuilder(getId(), Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL, new JavaSymbolName("INDEX_PARAM_NAME"), JavaType.STRING, "\"index\""); builder.addField(field);/* ww w .j a va 2s.c om*/ field = new FieldMetadataBuilder(getId(), Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL, new JavaSymbolName("FORM_PARAM_NAME"), JavaType.STRING, "\"gvnixform\""); builder.addField(field); field = new FieldMetadataBuilder(getId(), Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL, new JavaSymbolName("REFERER_PARAM_NAME"), JavaType.STRING, "\"Referer\""); builder.addField(field); }
From source file:org.gvnix.addon.jpa.addon.audit.JpaAuditMetadata.java
/** * @return gets or creates getXXXRevisions(id, fromData,toDate,start,limit) * method//from www . j a v a 2 s . co m */ private MethodMetadata getGetRevisionsMethod() { // method name JavaSymbolName methodName = getRevisionsMethodName; // Define method parameter types List<AnnotatedJavaType> parameterTypes = helper.toAnnotedJavaType(identifier.getFieldType(), JdkJavaType.DATE, JdkJavaType.DATE, JavaType.INT_OBJECT, JavaType.INT_OBJECT); // Check if a method exist in type final MethodMetadata method = helper.methodExists(methodName, parameterTypes); if (method != null) { // If it already exists, just return the method return method; } // Define method annotations (none in this case) List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Define method throws types (none in this case) List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter names (none in this case) List<JavaSymbolName> parameterNames = helper.toSymbolName(identifier.getFieldName().getSymbolName(), "fromDate", "toDate", "start", "limit"); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); revisionLogBuilder.buildBodyGetRevisions(bodyBuilder, parameterNames); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.STATIC, methodName, revisonItemListType, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata }
From source file:org.gvnix.addon.jpa.addon.audit.JpaAuditMetadata.java
/** * @return gets or creates findXXX(id, revision) method *///from ww w. j ava 2s.c o m private MethodMetadata getFindFromRevisionMethod() { // method name JavaSymbolName methodName = findMethodName; // Define method parameter types List<AnnotatedJavaType> parameterTypes = helper.toAnnotedJavaType(identifier.getFieldType(), JavaType.LONG_PRIMITIVE); // Check if a method exist in type final MethodMetadata method = helper.methodExists(methodName, parameterTypes); if (method != null) { // If it already exists, just return the method return method; } // Define method annotations (none in this case) List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Define method throws types (none in this case) List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter names (none in this case) List<JavaSymbolName> parameterNames = helper.toSymbolName(identifier.getFieldName().getSymbolName(), "revision"); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); revisionLogBuilder.buildBodyFindFromRevision(bodyBuilder, parameterNames); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.STATIC, methodName, entity, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata }
From source file:com.googlecode.android_scripting.facade.AndroidFacade.java
@Rpc(description = "Get list of constants (static final fields) for a class") public Bundle getConstants( @RpcParameter(name = "classname", description = "Class to get constants from") String classname) throws Exception { Bundle result = new Bundle(); int flags = Modifier.FINAL | Modifier.PUBLIC | Modifier.STATIC; Class<?> clazz = Class.forName(classname); for (Field field : clazz.getFields()) { if ((field.getModifiers() & flags) == flags) { Class<?> type = field.getType(); String name = field.getName(); if (type == int.class) { result.putInt(name, field.getInt(null)); } else if (type == long.class) { result.putLong(name, field.getLong(null)); } else if (type == double.class) { result.putDouble(name, field.getDouble(null)); } else if (type == char.class) { result.putChar(name, field.getChar(null)); } else if (type instanceof Object) { result.putString(name, field.get(null).toString()); }/*w ww . j a v a2 s. com*/ } } return result; }
From source file:org.gvnix.addon.jpa.addon.audit.JpaAuditMetadata.java
/** * @return gets or creates findXXX(id, date) method *///w w w .j av a2s .c o m private MethodMetadata getFindFromDateMethod() { // method name JavaSymbolName methodName = findMethodName; // Define method parameter types List<AnnotatedJavaType> parameterTypes = helper.toAnnotedJavaType(identifier.getFieldType(), JdkJavaType.DATE); // Check if a method exist in type final MethodMetadata method = helper.methodExists(methodName, parameterTypes); if (method != null) { // If it already exists, just return the method return method; } // Define method annotations (none in this case) List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Define method throws types (none in this case) List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter names (none in this case) List<JavaSymbolName> parameterNames = helper.toSymbolName(identifier.getFieldName().getSymbolName(), "atDate"); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); revisionLogBuilder.buildBodyFindFromDate(bodyBuilder, parameterNames); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.STATIC, methodName, entity, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); helper.addJavaDocToMethod(methodBuilder, "Find a ".concat(entity.getSimpleTypeName()).concat("with values on specified date"), null); return methodBuilder.build(); // Build and return a MethodMetadata }