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 testFormWithTextFieldMultipleValidations() 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("min"), 2)); AnnotationMetadataBuilder annotation2 = new AnnotationMetadataBuilder( new JavaType("javax.validation.constraints.Size"), attrs); List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); annotations.add(annotation1);/*w w w . j ava2 s.c om*/ annotations.add(annotation2); FieldMetadata field = new FieldMetadataBuilder("MID:person#1", Modifier.PRIVATE, annotations, new JavaSymbolName("name"), JavaType.STRING_OBJECT).build(); elegibleFields.add(field); listViewTemplate.setAttribute("fields", FlexUIMetadataProvider.wrapFields(elegibleFields)); String result = listViewTemplate.toString(); log.debug(result); assertTrue(result.contains("mx:StringValidator")); assertTrue(result.contains("s:TextInput")); ByteArrayInputStream stream = new ByteArrayInputStream(result.getBytes("UTF-8")); XmlUtils.getDocumentBuilder().parse(stream); }
From source file:org.codehaus.griffon.ast.GriffonASTUtils.java
public static void addReadOnlyProperty(ClassNode classNode, String propertyName, ClassNode propertyClass, Object value) {/*from w w w .j a v a 2 s.co m*/ final boolean hasProperty = hasOrInheritsProperty(classNode, propertyName); if (!hasProperty) { int visibility = Modifier.PRIVATE | Modifier.FINAL; Expression initialValue = value != null && !(value instanceof Expression) ? initialValue = new ConstantExpression(value) : (Expression) value; classNode.addField(propertyName, visibility, propertyClass, initialValue); addMethod(classNode, new MethodNode("get" + MetaClassHelper.capitalize(propertyName), Modifier.PUBLIC, propertyClass, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, new ReturnStatement( new ExpressionStatement(new FieldExpression(classNode.getField(propertyName)))))); } }
From source file:org.springframework.flex.roo.addon.ui.FormTemplateTests.java
@Test public void testFormWithTextFieldMultipleValidations() 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 annotation1 = new AnnotationMetadataBuilder( new JavaType("javax.validation.constraints.NotNull"), Collections.EMPTY_LIST); List<AnnotationAttributeValue<?>> attrs = new ArrayList<AnnotationAttributeValue<?>>(); attrs.add(new IntegerAttributeValue(new JavaSymbolName("min"), 2)); AnnotationMetadataBuilder annotation2 = new AnnotationMetadataBuilder( new JavaType("javax.validation.constraints.Size"), attrs); List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); annotations.add(annotation1);/*from w ww . ja va 2 s. co m*/ annotations.add(annotation2); FieldMetadata field = new FieldMetadataBuilder("MID:person#1", Modifier.PRIVATE, annotations, new JavaSymbolName("name"), JavaType.STRING_OBJECT).build(); elegibleFields.add(field); listViewTemplate.setAttribute("fields", FlexUIMetadataProvider.wrapFields(elegibleFields)); String result = listViewTemplate.toString(); log.debug(result); assertTrue(result.contains("mx:StringValidator")); 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.SnippetInputFactoryContainer.java
/** * Validates the constructor of the class. * * @param validator// w ww . j a v a 2 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:fr.imag.model2roo.addon.graph.GraphOperationsImpl.java
@Override public void newEntity(final JavaType name, final JavaType superClass, final boolean isAbstract) { int modifier; String entityId;/*from w w w .j a v a 2s .c o m*/ GraphProvider graphProvider; FieldMetadataBuilder fieldBuilder; ClassOrInterfaceTypeDetails entityDetails; ClassOrInterfaceTypeDetails superClassDetails; ClassOrInterfaceTypeDetailsBuilder entityBuilder; // Class modifier modifier = Modifier.PUBLIC; if (isAbstract) { modifier = Modifier.ABSTRACT; } // Create entity class entityId = PhysicalTypeIdentifier.createIdentifier(name, pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA)); entityBuilder = new ClassOrInterfaceTypeDetailsBuilder(entityId, modifier, name, PhysicalTypeCategory.CLASS); // Base class if (!superClass.equals(OBJECT)) { superClassDetails = typeLocationService.getTypeDetails(superClass); if (superClassDetails != null) { entityBuilder.setSuperclass(new ClassOrInterfaceTypeDetailsBuilder(superClassDetails)); } } entityBuilder.setExtendsTypes(Arrays.asList(superClass)); // Associate appropriate annotations graphProvider = this.getCurrentGraphProvider(); entityBuilder.setAnnotations(graphProvider.getClassAnnotations()); entityBuilder.addAnnotation(ROO_JAVA_BEAN_BUILDER); entityBuilder.addAnnotation(ROO_TO_STRING_BUILDER); typeManagementService.createOrUpdateTypeOnDisk(entityBuilder.build()); // Add id field entityDetails = typeLocationService.getTypeDetails(name); fieldBuilder = new FieldMetadataBuilder(entityDetails.getDeclaredByMetadataId(), Modifier.PRIVATE, graphProvider.getIdAnnotations(), new JavaSymbolName("nodeId"), JavaType.LONG_OBJECT); typeManagementService.addField(fieldBuilder.build()); }
From source file:org.ops4j.gaderian.strategy.TestStrategyFactory.java
public void testBuildImplementationClassImproperMethod() { Location l = newLocation();/*from www . j av a 2 s . c o m*/ ClassFactory factory = createMock(ClassFactory.class); ClassFab cf = createMock(ClassFab.class); MethodFab mf = createMock(MethodFab.class); ServiceImplementationFactoryParameters fp = createMock(ServiceImplementationFactoryParameters.class); ErrorLog log = createMock(ErrorLog.class); expect(fp.getServiceInterface()).andReturn(Runnable.class); final StrategyParameter param = new StrategyParameter(); expect(fp.getFirstParameter()).andReturn(param); expect(factory.newClass("NewClass", Object.class)).andReturn(cf); cf.addInterface(Runnable.class); cf.addField("_registry", StrategyRegistry.class); Capture<Class[]> classCapture = new Capture<Class[]>(); cf.addConstructor(capture(classCapture), (Class[]) eq(null), eq("_registry = $1;")); expect(cf.addMethod(Modifier.PRIVATE, new MethodSignature(Runnable.class, "_getStrategy", new Class[] { Object.class }, null), "return (java.lang.Runnable) _registry.getStrategy($1.getClass());")).andReturn(mf); MethodSignature sig = new MethodSignature(void.class, "run", null, null); expect(cf.addMethod(Modifier.PUBLIC, sig, "{ }")).andReturn(mf); expect(fp.getErrorLog()).andReturn(log); // Slight fudge: we return the location itself when we should return // an object with this location. expect(fp.getFirstParameter()).andReturn(l); log.error(StrategyMessages.improperServiceMethod(sig), l, null); expect(fp.getServiceId()).andReturn("foo.Bar"); ClassFabUtils.addToStringMethod(cf, StrategyMessages.toString("foo.Bar", Runnable.class)); expectLastCall().andReturn(mf); expect(cf.createClass()).andReturn(String.class); replayAllRegisteredMocks(); StrategyFactory f = new StrategyFactory(); f.setClassFactory(factory); f.buildImplementationClass(fp, "NewClass"); verifyAllRegisteredMocks(); }
From source file:org.gvnix.flex.ui.FormTemplateTests.java
@Test public void testFormWithNumberFieldNoValidations() 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>(); FieldMetadata field = new FieldMetadataBuilder("MID:person#1", Modifier.PRIVATE, new JavaSymbolName("age"), JavaType.INT_OBJECT, null).build(); elegibleFields.add(field);/*from w w w . ja v a2s . com*/ listViewTemplate.setAttribute("fields", FlexUIMetadataProvider.wrapFields(elegibleFields)); String result = listViewTemplate.toString(); log.debug(result); assertFalse(result.contains("mx:NumberValidator")); assertTrue(result.contains("s:TextInput")); ByteArrayInputStream stream = new ByteArrayInputStream(result.getBytes("UTF-8")); XmlUtils.getDocumentBuilder().parse(stream); }
From source file:fr.imag.model2roo.addon.graph.NodeEntityMetadata.java
private FieldMetadata getIdentifierField() { if (parent != null) { final FieldMetadata parentIdField = parent.getIdentifierField(); if (parentIdField.getFieldType().equals(idType)) { return parentIdField; }/* w ww. ja v a 2 s . com*/ } // Try to locate an existing field with DATA_ID final List<FieldMetadata> idFields = governorTypeDetails.getFieldsWithAnnotation(SpringJavaType.DATA_ID); if (!idFields.isEmpty()) { return idFields.get(0); } final JavaSymbolName idFieldName = governorTypeDetails.getUniqueFieldName("id"); final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(getId(), Modifier.PRIVATE, idFieldName, idType, null); fieldBuilder.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.DATA_ID)); return fieldBuilder.build(); }
From source file:org.springframework.flex.roo.addon.ui.FormTemplateTests.java
@Test public void testFormWithNumberFieldNoValidations() 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>(); FieldMetadata field = new FieldMetadataBuilder("MID:person#1", Modifier.PRIVATE, new JavaSymbolName("age"), JavaType.INT_OBJECT, null).build(); elegibleFields.add(field);/*from w w w.jav a 2 s. c om*/ listViewTemplate.setAttribute("fields", FlexUIMetadataProvider.wrapFields(elegibleFields)); String result = listViewTemplate.toString(); log.debug(result); assertFalse(result.contains("mx:NumberValidator")); assertTrue(result.contains("s:TextInput")); ByteArrayInputStream stream = new ByteArrayInputStream(result.getBytes("UTF-8")); XmlUtils.getDocumentBuilder().parse(stream); }
From source file:org.eclipse.skalli.testutil.PropertyTestUtil.java
private static boolean hasPrivateField(Class<?> clazz, String fieldName) { for (Field field : clazz.getDeclaredFields()) { if (fieldName.equals(field.getName()) && ((field.getModifiers() & Modifier.PRIVATE) == Modifier.PRIVATE) && !((field.getModifiers() & Modifier.STATIC) == Modifier.STATIC)) { return true; }//from w w w . j av a 2 s.co m } return false; }