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.springframework.flex.roo.addon.ui.FormTemplateTests.java
@Test public void testFormWithNumberFieldMultipleValidations() 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("value"), 2)); AnnotationMetadataBuilder annotation2 = new AnnotationMetadataBuilder( new JavaType("javax.validation.constraints.Min"), attrs); List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); annotations.add(annotation1);/*from w w w . j a v a 2 s . c o m*/ 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); }
From source file:com.adaptc.mws.plugins.testing.transformations.TestMixinTransformation.java
public static void addFieldIfNonExistent(ClassNode classNode, ClassNode fieldType, String fieldName) { if (classNode != null && classNode.getField(fieldName) == null) { classNode.addField(fieldName, Modifier.PRIVATE, fieldType, new ConstructorCallExpression(fieldType, new ArgumentListExpression())); }//from w w w. j a v a2s. c o m }
From source file:org.gvnix.flex.ui.FormTemplateTests.java
@Test public void testFormWithDateFieldNoValidations() 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("birthday"), new JavaType("java.util.Date"), null).build(); elegibleFields.add(field);/*from w ww.j a v a2 s. c om*/ listViewTemplate.setAttribute("fields", FlexUIMetadataProvider.wrapFields(elegibleFields)); String result = listViewTemplate.toString(); log.debug(result); assertFalse(result.contains("mx:DateValidator")); assertTrue(result.contains("mx:DateField")); ByteArrayInputStream stream = new ByteArrayInputStream(result.getBytes("UTF-8")); XmlUtils.getDocumentBuilder().parse(stream); }
From source file:net.minecraftforge.common.util.EnumHelper.java
@SuppressWarnings({ "unchecked", "serial" }) @Nullable//from w w w . j a v a 2 s . 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:fr.imag.model2roo.addon.graph.GraphOperationsImpl.java
@Override public void newRelationship(final JavaType fromNode, final JavaType relationNode, final boolean isVia, final String type, final Direction direction, final String fieldName, final RelationshipType relationshipType) { List<JavaType> parameters; GraphProvider graphProvider;//from w w w . j a va 2 s . c o m FieldMetadataBuilder fieldBuilder; ClassOrInterfaceTypeDetails entityDetails; List<AnnotationMetadataBuilder> fieldAnnotations; fieldBuilder = null; entityDetails = typeLocationService.getTypeDetails(fromNode); switch (relationshipType) { case SINGLE: fieldBuilder = new FieldMetadataBuilder(entityDetails.getDeclaredByMetadataId(), Modifier.PRIVATE, new ArrayList<AnnotationMetadataBuilder>(), new JavaSymbolName(fieldName), relationNode); break; case MODIFIABLE: parameters = new ArrayList<JavaType>(); parameters.add(relationNode); fieldBuilder = new FieldMetadataBuilder(entityDetails.getDeclaredByMetadataId(), Modifier.PRIVATE, new ArrayList<AnnotationMetadataBuilder>(), new JavaSymbolName(fieldName), new JavaType("java.util.Set", 0, DataType.TYPE, null, parameters)); break; case READ_ONLY: parameters = new ArrayList<JavaType>(); parameters.add(relationNode); fieldBuilder = new FieldMetadataBuilder(entityDetails.getDeclaredByMetadataId(), Modifier.PRIVATE, new ArrayList<AnnotationMetadataBuilder>(), new JavaSymbolName(fieldName), new JavaType("java.lang.Iterable", 0, DataType.TYPE, null, parameters)); break; } if (fieldBuilder != null) { // Associate appropriate annotations graphProvider = this.getCurrentGraphProvider(); fieldAnnotations = graphProvider.getRelationshipAnnotations(); if (isVia) { fieldAnnotations = graphProvider.getRelationshipViaAnnotations(); } for (AnnotationMetadataBuilder annotation : fieldAnnotations) { if (type != null) { annotation.addStringAttribute("type", type); } if (direction != null) { annotation.addEnumAttribute("direction", Direction.class.getCanonicalName(), direction.toString()); } fieldBuilder.addAnnotation(annotation); } typeManagementService.addField(fieldBuilder.build()); } }
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); }/*from ww w .java 2 s . 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.springframework.flex.roo.addon.ui.FormTemplateTests.java
@Test public void testFormWithDateFieldNoValidations() 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("birthday"), new JavaType("java.util.Date"), null).build(); elegibleFields.add(field);/*from w ww.jav a 2 s. c o m*/ listViewTemplate.setAttribute("fields", FlexUIMetadataProvider.wrapFields(elegibleFields)); String result = listViewTemplate.toString(); log.debug(result); assertFalse(result.contains("mx:DateValidator")); assertTrue(result.contains("mx:DateField")); ByteArrayInputStream stream = new ByteArrayInputStream(result.getBytes("UTF-8")); XmlUtils.getDocumentBuilder().parse(stream); }
From source file:com.adaptc.mws.plugins.testing.transformations.TestForTransformation.java
protected MethodNode addClassUnderTestMethod(ClassNode classNode, ClassExpression targetClass, String type) { String methodName = "setup" + type + "UnderTest"; String fieldName = TestMixinTransformation.getPropertyNameRepresentation(type); String getterName = TestMixinTransformation.getGetterName(fieldName); fieldName = '$' + fieldName; if (classNode.getField(fieldName) == null) { classNode.addField(fieldName, Modifier.PRIVATE, targetClass.getType(), null); }/*w w w . j a v a 2 s. co m*/ MethodNode methodNode = classNode.getMethod(methodName, TestMixinTransformation.ZERO_PARAMETERS); VariableExpression fieldExpression = new VariableExpression(fieldName); if (methodNode == null) { BlockStatement setupMethodBody = new BlockStatement(); addMockClassUnderTest(type, fieldExpression, targetClass, setupMethodBody); methodNode = new MethodNode(methodName, Modifier.PUBLIC, ClassHelper.VOID_TYPE, TestMixinTransformation.ZERO_PARAMETERS, null, setupMethodBody); methodNode.addAnnotation(BEFORE_ANNOTATION); methodNode.addAnnotation(MIXIN_METHOD_ANNOTATION); classNode.addMethod(methodNode); } MethodNode getter = classNode.getMethod(getterName, TestMixinTransformation.ZERO_PARAMETERS); if (getter == null) { BlockStatement getterBody = new BlockStatement(); getter = new MethodNode(getterName, Modifier.PUBLIC, targetClass.getType().getPlainNodeReference(), TestMixinTransformation.ZERO_PARAMETERS, null, getterBody); getterBody.addStatement(new ReturnStatement(fieldExpression)); classNode.addMethod(getter); } return methodNode; }
From source file:org.gradle.build.docs.dsl.source.SourceMetaDataVisitor.java
private int extractModifiers(GroovySourceAST ast) { GroovySourceAST modifiers = ast.childOfType(MODIFIERS); if (modifiers == null) { return 0; }// w ww . j a va 2 s . c o m int modifierFlags = 0; for (GroovySourceAST child = (GroovySourceAST) modifiers .getFirstChild(); child != null; child = (GroovySourceAST) child.getNextSibling()) { switch (child.getType()) { case LITERAL_private: modifierFlags |= Modifier.PRIVATE; break; case LITERAL_protected: modifierFlags |= Modifier.PROTECTED; break; case LITERAL_public: modifierFlags |= Modifier.PUBLIC; break; case FINAL: modifierFlags |= Modifier.FINAL; break; case LITERAL_static: modifierFlags |= Modifier.STATIC; break; } } return modifierFlags; }
From source file:org.gvnix.flex.ui.FormTemplateTests.java
@Test public void testFormWithDateFieldSingleValidation() 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("birthday"), new JavaType("java.util.Date")).build(); elegibleFields.add(field);//from www. ja v a 2 s.c om listViewTemplate.setAttribute("fields", FlexUIMetadataProvider.wrapFields(elegibleFields)); String result = listViewTemplate.toString(); log.debug(result); assertTrue(result.contains("mx:DateValidator")); assertTrue(result.contains("mx:DateField")); ByteArrayInputStream stream = new ByteArrayInputStream(result.getBytes("UTF-8")); XmlUtils.getDocumentBuilder().parse(stream); }