List of usage examples for java.lang.reflect Modifier PRIVATE
int PRIVATE
To view the source code for java.lang.reflect Modifier PRIVATE.
Click Source Link
From source file:org.gvnix.flex.ui.FormTemplateTests.java
@Test public void testFormWithNumberFieldSingleValidation() throws SAXException, IOException { ActionScriptType entityType = new ActionScriptType("com.foo.Person"); StringTemplate listViewTemplate = templateGroup.getInstanceOf("org/gvnix/flex/roo/addon/ui/entity_form"); listViewTemplate.setAttribute("entityType", entityType); listViewTemplate.setAttribute("flexScaffoldMetadata", flexScaffoldMetadata); List<FieldMetadata> elegibleFields = new ArrayList<FieldMetadata>(); AnnotationMetadataBuilder annotation = new AnnotationMetadataBuilder( new JavaType("javax.validation.constraints.NotNull"), Collections.EMPTY_LIST); FieldMetadata field = new FieldMetadataBuilder("MID:person#1", Modifier.PRIVATE, Collections.singletonList(annotation), new JavaSymbolName("age"), JavaType.INT_OBJECT).build(); elegibleFields.add(field);// w w w .j a v a2 s . c o m listViewTemplate.setAttribute("fields", FlexUIMetadataProvider.wrapFields(elegibleFields)); String result = listViewTemplate.toString(); log.debug(result); assertTrue(result.contains("mx:NumberValidator")); assertTrue(result.contains("s:TextInput")); ByteArrayInputStream stream = new ByteArrayInputStream(result.getBytes("UTF-8")); XmlUtils.getDocumentBuilder().parse(stream); }
From source file:hu.bme.mit.sette.common.model.snippet.SnippetContainer.java
/** * Validates the constructor of the class. * * @param validator/*from w w w.jav a2 s . c o m*/ * a validator */ private void validateConstructor(final AbstractValidator<?> validator) { if (javaClass.getDeclaredConstructors().length != 1) { // constructor count is validated with the class return; } Constructor<?> constructor = javaClass.getDeclaredConstructors()[0]; ConstructorValidator v = new ConstructorValidator(constructor); v.withModifiers(Modifier.PRIVATE).parameterCount(0); v.synthetic(false); // check: constructor throws new // UnsupportedOperationException("Static class") Throwable exception = null; try { // call the private ctor constructor.setAccessible(true); constructor.newInstance(); } catch (Exception e) { exception = e.getCause(); } finally { // restore visibility constructor.setAccessible(false); } if (exception == null || !exception.getClass().equals(UnsupportedOperationException.class) || !exception.getMessage().equals("Static class")) { v.addException("The constructor must throw an " + "UnsupportedOperationException with " + "the message \"Static class\""); } validator.addChildIfInvalid(v); }
From source file:org.springframework.flex.roo.addon.ui.FormTemplateTests.java
@Test public void testFormWithNumberFieldSingleValidation() throws SAXException, IOException { ActionScriptType entityType = new ActionScriptType("com.foo.Person"); StringTemplate listViewTemplate = templateGroup .getInstanceOf("org/springframework/flex/roo/addon/ui/entity_form"); listViewTemplate.setAttribute("entityType", entityType); listViewTemplate.setAttribute("flexScaffoldMetadata", flexScaffoldMetadata); List<FieldMetadata> elegibleFields = new ArrayList<FieldMetadata>(); AnnotationMetadataBuilder annotation = new AnnotationMetadataBuilder( new JavaType("javax.validation.constraints.NotNull"), Collections.EMPTY_LIST); FieldMetadata field = new FieldMetadataBuilder("MID:person#1", Modifier.PRIVATE, Collections.singletonList(annotation), new JavaSymbolName("age"), JavaType.INT_OBJECT).build(); elegibleFields.add(field);//w w w .j a v a 2 s. co m listViewTemplate.setAttribute("fields", FlexUIMetadataProvider.wrapFields(elegibleFields)); String result = listViewTemplate.toString(); log.debug(result); assertTrue(result.contains("mx:NumberValidator")); assertTrue(result.contains("s:TextInput")); ByteArrayInputStream stream = new ByteArrayInputStream(result.getBytes("UTF-8")); XmlUtils.getDocumentBuilder().parse(stream); }
From source file:hd3gtv.mydmam.db.orm.CassandraOrm.java
private ArrayList<Field> getOrmobjectUsableFields() { ArrayList<Field> result = new ArrayList<Field>(); Field[] fields = this.reference.getFields(); Field field;/*from w w w . j ava 2s . c om*/ int mod; for (int pos_df = 0; pos_df < fields.length; pos_df++) { field = fields[pos_df]; if (field.isAnnotationPresent(Transient.class)) { /** * Is transient ? */ continue; } if (field.getName().equals("key")) { /** * Not this (primary key) */ continue; } mod = field.getModifiers(); if ((mod & Modifier.PROTECTED) != 0) continue; if ((mod & Modifier.PRIVATE) != 0) continue; if ((mod & Modifier.ABSTRACT) != 0) continue; if ((mod & Modifier.STATIC) != 0) continue; if ((mod & Modifier.FINAL) != 0) continue; if ((mod & Modifier.TRANSIENT) != 0) continue; if ((mod & Modifier.INTERFACE) != 0) continue; try { result.add(field); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } } return result; }
From source file:com.github.mbenson.privileged.weaver.PrivilegedMethodWeaver.java
private CtClass createAction(CtClass type, CtMethod impl, Class<?> iface) throws NotFoundException, CannotCompileException, IOException { final boolean exc = impl.getExceptionTypes().length > 0; final CtClass actionType = classPool.get(iface.getName()); final String simpleName = generateActionClassname(impl); debug("Creating action type %s for method %s", simpleName, toString(impl)); final CtClass result = type.makeNestedClass(simpleName, true); result.addInterface(actionType);//w w w. j a va 2 s . c o m final CtField owner; if (Modifier.isStatic(impl.getModifiers())) { owner = null; } else { owner = new CtField(type, generateName("owner"), result); owner.setModifiers(Modifier.PRIVATE | Modifier.FINAL); debug("Adding owner field %s to %s", owner.getName(), simpleName); result.addField(owner); } final List<String> propagatedParameters = new ArrayList<String>(); int index = -1; for (final CtClass param : impl.getParameterTypes()) { final String f = String.format("arg%s", Integer.valueOf(++index)); final CtField fld = new CtField(param, f, result); fld.setModifiers(Modifier.PRIVATE | Modifier.FINAL); debug("Copying parameter %s from %s to %s.%s", index, toString(impl), simpleName, f); result.addField(fld); propagatedParameters.add(f); } { final StrBuilder constructor = new StrBuilder(simpleName).append('('); boolean sep = false; final Body body = new Body(); for (final CtField fld : result.getDeclaredFields()) { if (sep) { constructor.append(", "); } else { sep = true; } constructor.append(fld.getType().getName()).append(' ').append(fld.getName()); body.appendLine("this.%1$s = %1$s;", fld.getName()); } constructor.append(") ").append(body.complete()); final String c = constructor.toString(); debug("Creating action constructor:"); debug(c); result.addConstructor(CtNewConstructor.make(c, result)); } { final StrBuilder run = new StrBuilder("public Object run() "); if (exc) { run.append("throws Exception "); } final Body body = new Body(); final CtClass rt = impl.getReturnType(); final boolean isVoid = rt.equals(CtClass.voidType); if (!isVoid) { body.append("return "); } final String deref = Modifier.isStatic(impl.getModifiers()) ? type.getName() : owner.getName(); final String call = String.format("%s.%s(%s)", deref, impl.getName(), StringUtils.join(propagatedParameters, ", ")); if (!isVoid && rt.isPrimitive()) { body.appendLine("%2$s.valueOf(%1$s);", call, ((CtPrimitiveType) rt).getWrapperName()); } else { body.append(call).append(';').appendNewLine(); if (isVoid) { body.appendLine("return null;"); } } run.append(body.complete()); final String r = run.toString(); debug("Creating run method:"); debug(r); result.addMethod(CtNewMethod.make(r, result)); } getClassFileWriter().write(result); debug("Returning action type %s", result); return result; }
From source file:fr.imag.model2roo.addon.graph.GraphOperationsImpl.java
@Override public void newRelationshipEntity(final JavaType name, final String type, final JavaType startNode, final JavaType endNode, List<String> properties) { String entityId;/* w ww.j av a 2 s . c o m*/ GraphProvider graphProvider; FieldMetadataBuilder fieldBuilder; ClassOrInterfaceTypeDetails entityDetails; ClassOrInterfaceTypeDetailsBuilder entityBuilder; List<AnnotationMetadataBuilder> relationshipAnnotations; // Create relationship class entityId = PhysicalTypeIdentifier.createIdentifier(name, pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA)); entityBuilder = new ClassOrInterfaceTypeDetailsBuilder(entityId, Modifier.PUBLIC, name, PhysicalTypeCategory.CLASS); // Associate appropriate annotations graphProvider = this.getCurrentGraphProvider(); relationshipAnnotations = graphProvider.getRelationshipEntityAnnotations(); for (AnnotationMetadataBuilder annotation : relationshipAnnotations) { annotation.addStringAttribute("type", type); } entityBuilder.setAnnotations(relationshipAnnotations); entityBuilder.addAnnotation(ROO_JAVA_BEAN_BUILDER); entityBuilder.addAnnotation(ROO_TO_STRING_BUILDER); typeManagementService.createOrUpdateTypeOnDisk(entityBuilder.build()); // Id entityDetails = typeLocationService.getTypeDetails(name); fieldBuilder = new FieldMetadataBuilder(entityDetails.getDeclaredByMetadataId(), Modifier.PRIVATE, graphProvider.getIdAnnotations(), new JavaSymbolName("relationshipId"), JavaType.LONG_OBJECT); entityBuilder.addField(fieldBuilder.build()); // Start node fieldBuilder = new FieldMetadataBuilder(entityDetails.getDeclaredByMetadataId(), Modifier.PRIVATE, graphProvider.getRelationshipStartNodeAnnotations(), new JavaSymbolName("startNode"), startNode); entityBuilder.addField(fieldBuilder.build()); // End node fieldBuilder = new FieldMetadataBuilder(entityDetails.getDeclaredByMetadataId(), Modifier.PRIVATE, graphProvider.getRelationshipEndNodeAnnotations(), new JavaSymbolName("endNode"), endNode); entityBuilder.addField(fieldBuilder.build()); // Properties if (properties != null) { // One field of type String for each property for (String property : properties) { fieldBuilder = new FieldMetadataBuilder(entityDetails.getDeclaredByMetadataId(), Modifier.PRIVATE, new ArrayList<AnnotationMetadataBuilder>(), new JavaSymbolName(property), JavaType.STRING); entityBuilder.addField(fieldBuilder.build()); } } typeManagementService.createOrUpdateTypeOnDisk(entityBuilder.build()); }
From source file:org.xulux.dataprovider.bean.BeanMapping.java
/** * Will discover the fields in the bean. * if discovery is set and discovery has not yet taken * place. Discovery will methods which are private or protected. * //from www . ja v a 2s . co m * It will also try to discover the set method that is connected * to the getter (assuming it is not a read only field). * * @todo What to do with collections ? */ public void discover() { if (!isDiscovered && isDiscovery()) { Method[] methods = bean.getMethods(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; if ((!method.getName().equals("getClass") && method.getModifiers() != Modifier.PRIVATE && method.getModifiers() != Modifier.PROTECTED)) { BeanField field = new BeanField(method); // try to find the setter.. String fieldName = field.getName(); if (fieldName.length() > 0) { fieldName = field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1); } Method setMethod = findMethod(fieldName, true); field.setChangeMethod(setMethod); BeanField previousField = (BeanField) getField(fieldName); if (previousField != null) { if (previousField.getMethod().getParameterTypes().length == 0) { continue; } else { if (field.getMethod().getParameterTypes().length == 0) { fields.remove(previousField); } } } addField(field); } } isDiscovered = true; } }
From source file:org.codehaus.groovy.grails.compiler.injection.test.TestMixinTransformation.java
protected FieldNode addTestRuleMixinFieldIfNonExistent(ClassNode classNode, ClassNode fieldType, String fieldName, boolean implementsClassRuleFactory, boolean implementsRuleFactory) { if (classNode != null && classNode.getField(fieldName) == null) { FieldNode mixinInstanceFieldNode = classNode.addField(fieldName, Modifier.PRIVATE | (implementsClassRuleFactory ? Modifier.STATIC : 0), fieldType, new ConstructorCallExpression(fieldType, MethodCallExpression.NO_ARGUMENTS)); String ruleFieldNameBase = fieldName; boolean spockTest = isSpockTest(classNode); if (implementsClassRuleFactory) { FieldNode staticRuleFieldNode = classNode.addField(ruleFieldNameBase + "StaticClassRule", Modifier.PRIVATE | Modifier.STATIC, ClassHelper.make(TestRule.class), new MethodCallExpression(new FieldExpression(mixinInstanceFieldNode), "newClassRule", new ClassExpression(classNode))); AnnotationNode classRuleAnnotation = new AnnotationNode(ClassHelper.make(ClassRule.class)); if (spockTest) { // @ClassRule must be added to @Shared field in spock FieldNode spockSharedRuleFieldNode = classNode.addField(ruleFieldNameBase + "SharedClassRule", Modifier.PUBLIC, ClassHelper.make(TestRule.class), new FieldExpression(staticRuleFieldNode)); spockSharedRuleFieldNode.addAnnotation(classRuleAnnotation); spockSharedRuleFieldNode.addAnnotation(new AnnotationNode(ClassHelper.make(Shared.class))); if (spockTest) { addSpockFieldMetadata(spockSharedRuleFieldNode, 0); }/*from w w w. ja v a 2 s .c o m*/ } else { staticRuleFieldNode.setModifiers(Modifier.PUBLIC | Modifier.STATIC); staticRuleFieldNode.addAnnotation(classRuleAnnotation); } } if (implementsRuleFactory) { FieldNode ruleFieldNode = classNode.addField(ruleFieldNameBase + "Rule", Modifier.PUBLIC, ClassHelper.make(TestRule.class), new MethodCallExpression(new FieldExpression(mixinInstanceFieldNode), "newRule", new VariableExpression("this"))); ruleFieldNode.addAnnotation(new AnnotationNode(ClassHelper.make(Rule.class))); if (spockTest) { addSpockFieldMetadata(ruleFieldNode, 0); } } return mixinInstanceFieldNode; } return null; }
From source file:org.gvnix.flex.ui.FormTemplateTests.java
@Test public void testFormWithNumberFieldMultipleValidations() throws SAXException, IOException { ActionScriptType entityType = new ActionScriptType("com.foo.Person"); StringTemplate listViewTemplate = templateGroup.getInstanceOf("org/gvnix/flex/roo/addon/ui/entity_form"); listViewTemplate.setAttribute("entityType", entityType); listViewTemplate.setAttribute("flexScaffoldMetadata", flexScaffoldMetadata); List<FieldMetadata> elegibleFields = new ArrayList<FieldMetadata>(); AnnotationMetadataBuilder annotation1 = new AnnotationMetadataBuilder( new JavaType("javax.validation.constraints.NotNull"), Collections.EMPTY_LIST); List<AnnotationAttributeValue<?>> attrs = new ArrayList<AnnotationAttributeValue<?>>(); attrs.add(new IntegerAttributeValue(new JavaSymbolName("value"), 2)); AnnotationMetadataBuilder annotation2 = new AnnotationMetadataBuilder( new JavaType("javax.validation.constraints.Min"), attrs); List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); annotations.add(annotation1);/*from ww w.j ava 2 s . c om*/ annotations.add(annotation2); FieldMetadata field = new FieldMetadataBuilder("MID:person#1", Modifier.PRIVATE, annotations, new JavaSymbolName("name"), JavaType.INT_OBJECT).build(); elegibleFields.add(field); listViewTemplate.setAttribute("fields", FlexUIMetadataProvider.wrapFields(elegibleFields)); String result = listViewTemplate.toString(); log.debug(result); assertTrue(result.contains("mx:NumberValidator")); assertTrue(result.contains("s:TextInput")); ByteArrayInputStream stream = new ByteArrayInputStream(result.getBytes("UTF-8")); XmlUtils.getDocumentBuilder().parse(stream); }