List of usage examples for java.lang Void TYPE
Class TYPE
To view the source code for java.lang Void TYPE.
Click Source Link
From source file:org.apache.bval.jsr.ClassValidator.java
/** * {@inheritDoc}/*from w ww .ja va 2 s .c om*/ */ public <T> Set<ConstraintViolation<T>> validateReturnValue(T object, Method method, Object returnValue, Class<?>... groups) { notNull("object", object); notNull("method", method); notNull("groups", groups); final MethodDescriptorImpl methodDescriptor = findMethodDescriptor(object, method); if (methodDescriptor == null) { throw new ValidationException("Method " + method + " doesn't belong to class " + object.getClass()); } if (method.getReturnType() == Void.TYPE) { checkValidationAppliesTo(methodDescriptor.getReturnValueDescriptor().getConstraintDescriptors(), ConstraintTarget.RETURN_VALUE); } @SuppressWarnings("unchecked") final Set<ConstraintViolation<T>> result = Set.class.cast(validaReturnedValue( new NodeImpl.MethodNodeImpl(method.getName(), Arrays.asList(method.getParameterTypes())), returnValue, object.getClass(), methodDescriptor, groups, object)); return result; }
From source file:org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils.java
private static void addPropertyDescriptor(List<PropertyDescriptor> descriptors, String qualifiedPropertyName, Map<String, Method> propertyToGetter, Map<String, Method> propertyToSetter) throws Exception { if (qualifiedPropertyName.startsWith("(")) { return;/* w w w.j a va 2 s. c om*/ } // prepare methods Method getMethod = propertyToGetter.get(qualifiedPropertyName); Method setMethod = propertyToSetter.get(qualifiedPropertyName); if (!isValidForJavaIBM(getMethod) || !isValidForJavaIBM(setMethod)) { return; } if (getMethod != null && getMethod.getReturnType() == Void.TYPE) { return; } // add property descriptors.add(new PropertyDescriptor(qualifiedPropertyName, getMethod, setMethod)); }
From source file:org.apache.axis.wsdl.fromJava.Emitter.java
/** * Create a Part//from w w w .j a v a2 s .c o m * * @param def * @param msg * @param request message is for a request * @param param ParamRep object * @return The parameter name added or null * @throws WSDLException * @throws AxisFault */ public String writePartToMessage(Definition def, Message msg, boolean request, ParameterDesc param) throws WSDLException, AxisFault { // Return if this is a void type if ((param == null) || (param.getJavaType() == java.lang.Void.TYPE)) { return null; } // If Request message, only continue if IN or INOUT // If Response message, only continue if OUT or INOUT if (request && (param.getMode() == ParameterDesc.OUT)) { return null; } if (!request && (param.getMode() == ParameterDesc.IN)) { return null; } // Create the Part Part part = def.createPart(); if (param.getDocumentation() != null) { part.setDocumentationElement(createDocumentationElement(param.getDocumentation())); } // Get the java type to represent in the wsdl // (if the mode is OUT or INOUT and this // parameter does not represent the return type, // the type held in the Holder is the one that should // be written.) Class javaType = param.getJavaType(); if ((param.getMode() != ParameterDesc.IN) && (param.getIsReturn() == false)) { javaType = JavaUtils.getHolderValueType(javaType); } if ((use == Use.ENCODED) || (style == Style.RPC)) { // Add the type representing the param // Write <part name=param_name type=param_type> QName typeQName = param.getTypeQName(); if (javaType != null) { typeQName = types.writeTypeAndSubTypeForPart(javaType, typeQName); } // types.writeElementForPart(javaType, param.getTypeQName()); if (typeQName != null) { part.setName(param.getName()); part.setTypeName(typeQName); msg.addPart(part); } } else if (use == Use.LITERAL) { // This is doc/lit. So we should write out an element // declaration whose name and type may be found in the // ParameterDesc. QName qname = param.getQName(); if (param.getTypeQName() == null) { log.warn(Messages.getMessage("registerTypeMappingFor01", param.getJavaType().getName())); QName qName = types.writeTypeForPart(param.getJavaType(), null); if (qName != null) { param.setTypeQName(qName); } else { param.setTypeQName(Constants.XSD_ANYTYPE); } } if (param.getTypeQName().getNamespaceURI().equals("")) { param.setTypeQName(new QName(intfNS, param.getTypeQName().getLocalPart())); } if (param.getQName().getNamespaceURI().equals("")) { qname = new QName(intfNS, param.getQName().getLocalPart()); param.setQName(qname); } // Make sure qname's value is unique. ArrayList names = (ArrayList) usedElementNames.get(qname.getNamespaceURI()); if (names == null) { names = new ArrayList(1); usedElementNames.put(qname.getNamespaceURI(), names); } else if (names.contains(qname.getLocalPart())) { qname = new QName(qname.getNamespaceURI(), JavaUtils.getUniqueValue(names, qname.getLocalPart())); } names.add(qname.getLocalPart()); types.writeElementDecl(qname, param.getJavaType(), param.getTypeQName(), false, param.getItemQName()); part.setName(param.getName()); part.setElementName(qname); msg.addPart(part); } // return the name of the parameter added return param.getName(); }
From source file:org.apache.axis2.jaxws.description.impl.OperationDescriptionImpl.java
public boolean isOperationReturningResult() { boolean isResult = false; if (!isAnnoOneWay()) { if (!isDBC() && seiMethod != null) { if (seiMethod.getReturnType() != Void.TYPE) { isResult = true;/*from w w w.j a v a2 s . c o m*/ } } else if (methodComposite != null) { if (!DescriptionUtils.isEmpty(methodComposite.getReturnType()) && !methodComposite.getReturnType().equals("void")) isResult = true; } else { if (log.isDebugEnabled()) { log.debug("No class to determine if result is returned"); } } } return isResult; }
From source file:org.apache.geode.internal.InternalDataSerializer.java
/** * Writes the type code for a primitive type Class to {@code DataOutput}. *//*from ww w.java 2 s .c om*/ public static void writePrimitiveClass(Class c, DataOutput out) throws IOException { if (c == Boolean.TYPE) { out.writeByte(BOOLEAN_TYPE); } else if (c == Character.TYPE) { out.writeByte(CHARACTER_TYPE); } else if (c == Byte.TYPE) { out.writeByte(BYTE_TYPE); } else if (c == Short.TYPE) { out.writeByte(SHORT_TYPE); } else if (c == Integer.TYPE) { out.writeByte(INTEGER_TYPE); } else if (c == Long.TYPE) { out.writeByte(LONG_TYPE); } else if (c == Float.TYPE) { out.writeByte(FLOAT_TYPE); } else if (c == Double.TYPE) { out.writeByte(DOUBLE_TYPE); } else if (c == Void.TYPE) { out.writeByte(VOID_TYPE); } else if (c == null) { out.writeByte(NULL); } else { throw new InternalGemFireError(LocalizedStrings.InternalDataSerializer_UNKNOWN_PRIMITIVE_TYPE_0 .toLocalizedString(c.getName())); } }
From source file:org.apache.geode.internal.InternalDataSerializer.java
public static Class decodePrimitiveClass(byte typeCode) { switch (typeCode) { case BOOLEAN_TYPE: return Boolean.TYPE; case CHARACTER_TYPE: return Character.TYPE; case BYTE_TYPE: return Byte.TYPE; case SHORT_TYPE: return Short.TYPE; case INTEGER_TYPE: return Integer.TYPE; case LONG_TYPE: return Long.TYPE; case FLOAT_TYPE: return Float.TYPE; case DOUBLE_TYPE: return Double.TYPE; case VOID_TYPE: return Void.TYPE; case NULL:/* w w w .ja v a 2s. c o m*/ return null; default: throw new InternalGemFireError( LocalizedStrings.InternalDataSerializer_UNEXPECTED_TYPECODE_0.toLocalizedString(typeCode)); } }
From source file:org.apache.flink.api.java.typeutils.TypeExtractor.java
/** * Checks if the given field is a valid pojo field: * - it is public/*from w w w . j a v a2 s .c o m*/ * OR * - there are getter and setter methods for the field. * * @param f field to check * @param clazz class of field * @param typeHierarchy type hierarchy for materializing generic types */ private boolean isValidPojoField(Field f, Class<?> clazz, ArrayList<Type> typeHierarchy) { if (Modifier.isPublic(f.getModifiers())) { return true; } else { boolean hasGetter = false, hasSetter = false; final String fieldNameLow = f.getName().toLowerCase().replaceAll("_", ""); Type fieldType = f.getGenericType(); Class<?> fieldTypeWrapper = ClassUtils.primitiveToWrapper(f.getType()); TypeVariable<?> fieldTypeGeneric = null; if (fieldType instanceof TypeVariable) { fieldTypeGeneric = (TypeVariable<?>) fieldType; fieldType = materializeTypeVariable(typeHierarchy, (TypeVariable<?>) fieldType); } for (Method m : clazz.getMethods()) { final String methodNameLow = m.getName().endsWith("_$eq") ? m.getName().toLowerCase().replaceAll("_", "").replaceFirst("\\$eq$", "_\\$eq") : m.getName().toLowerCase().replaceAll("_", ""); // check for getter if ( // The name should be "get<FieldName>" or "<fieldName>" (for scala) or "is<fieldName>" for boolean fields. (methodNameLow.equals("get" + fieldNameLow) || methodNameLow.equals("is" + fieldNameLow) || methodNameLow.equals(fieldNameLow)) && // no arguments for the getter m.getParameterTypes().length == 0 && // return type is same as field type (or the generic variant of it) (m.getGenericReturnType().equals(fieldType) || (fieldTypeWrapper != null && m.getReturnType().equals(fieldTypeWrapper)) || (fieldTypeGeneric != null && m.getGenericReturnType().equals(fieldTypeGeneric)))) { if (hasGetter) { throw new IllegalStateException("Detected more than one getter"); } hasGetter = true; } // check for setters (<FieldName>_$eq for scala) if ((methodNameLow.equals("set" + fieldNameLow) || methodNameLow.equals(fieldNameLow + "_$eq")) && m.getParameterTypes().length == 1 && // one parameter of the field's type (m.getGenericParameterTypes()[0].equals(fieldType) || (fieldTypeWrapper != null && m.getParameterTypes()[0].equals(fieldTypeWrapper)) || (fieldTypeGeneric != null && m.getGenericParameterTypes()[0].equals(fieldTypeGeneric))) && // return type is void. m.getReturnType().equals(Void.TYPE)) { if (hasSetter) { throw new IllegalStateException("Detected more than one setter"); } hasSetter = true; } } if (hasGetter && hasSetter) { return true; } else { if (!hasGetter) { LOG.debug(clazz + " does not contain a getter for field " + f.getName()); } if (!hasSetter) { LOG.debug(clazz + " does not contain a setter for field " + f.getName()); } return false; } } }
From source file:org.apache.geode.internal.InternalDataSerializer.java
public static Object basicReadObject(final DataInput in) throws IOException, ClassNotFoundException { checkIn(in);// w w w . j a va2 s . c o m // Read the header byte byte header = in.readByte(); if (logger.isTraceEnabled(LogMarker.SERIALIZER)) { logger.trace(LogMarker.SERIALIZER, "basicReadObject: header={}", header); } switch (header) { case DS_FIXED_ID_BYTE: return DSFIDFactory.create(in.readByte(), in); case DS_FIXED_ID_SHORT: return DSFIDFactory.create(in.readShort(), in); case DS_FIXED_ID_INT: return DSFIDFactory.create(in.readInt(), in); case DS_NO_FIXED_ID: return readDataSerializableFixedID(in); case NULL: return null; case NULL_STRING: case STRING: case HUGE_STRING: case STRING_BYTES: case HUGE_STRING_BYTES: return readString(in, header); case CLASS: return readClass(in); case DATE: return readDate(in); case FILE: return readFile(in); case INET_ADDRESS: return readInetAddress(in); case BOOLEAN: return readBoolean(in); case CHARACTER: return readCharacter(in); case BYTE: return readByte(in); case SHORT: return readShort(in); case INTEGER: return readInteger(in); case LONG: return readLong(in); case FLOAT: return readFloat(in); case DOUBLE: return readDouble(in); case BYTE_ARRAY: return readByteArray(in); case ARRAY_OF_BYTE_ARRAYS: return readArrayOfByteArrays(in); case SHORT_ARRAY: return readShortArray(in); case STRING_ARRAY: return readStringArray(in); case INT_ARRAY: return readIntArray(in); case LONG_ARRAY: return readLongArray(in); case FLOAT_ARRAY: return readFloatArray(in); case DOUBLE_ARRAY: return readDoubleArray(in); case BOOLEAN_ARRAY: return readBooleanArray(in); case CHAR_ARRAY: return readCharArray(in); case OBJECT_ARRAY: return readObjectArray(in); case ARRAY_LIST: return readArrayList(in); case LINKED_LIST: return readLinkedList(in); case HASH_SET: return readHashSet(in); case LINKED_HASH_SET: return readLinkedHashSet(in); case HASH_MAP: return readHashMap(in); case IDENTITY_HASH_MAP: return readIdentityHashMap(in); case HASH_TABLE: return readHashtable(in); case CONCURRENT_HASH_MAP: return readConcurrentHashMap(in); case PROPERTIES: return readProperties(in); case TIME_UNIT: return readTimeUnit(in); case USER_CLASS: return readUserObject(in, in.readByte()); case USER_CLASS_2: return readUserObject(in, in.readShort()); case USER_CLASS_4: return readUserObject(in, in.readInt()); case VECTOR: return readVector(in); case STACK: return readStack(in); case TREE_MAP: return readTreeMap(in); case TREE_SET: return readTreeSet(in); case BOOLEAN_TYPE: return Boolean.TYPE; case CHARACTER_TYPE: return Character.TYPE; case BYTE_TYPE: return Byte.TYPE; case SHORT_TYPE: return Short.TYPE; case INTEGER_TYPE: return Integer.TYPE; case LONG_TYPE: return Long.TYPE; case FLOAT_TYPE: return Float.TYPE; case DOUBLE_TYPE: return Double.TYPE; case VOID_TYPE: return Void.TYPE; case USER_DATA_SERIALIZABLE: return readUserDataSerializable(in, in.readByte()); case USER_DATA_SERIALIZABLE_2: return readUserDataSerializable(in, in.readShort()); case USER_DATA_SERIALIZABLE_4: return readUserDataSerializable(in, in.readInt()); case DATA_SERIALIZABLE: return readDataSerializable(in); case SERIALIZABLE: { final boolean isDebugEnabled_SERIALIZER = logger.isTraceEnabled(LogMarker.SERIALIZER); Object serializableResult; if (in instanceof DSObjectInputStream) { serializableResult = ((DSObjectInputStream) in).readObject(); } else { InputStream stream; if (in instanceof InputStream) { stream = (InputStream) in; } else { stream = new InputStream() { @Override public int read() throws IOException { try { return in.readUnsignedByte(); // fix for bug 47249 } catch (EOFException ignored) { return -1; } } }; } ObjectInput ois = new DSObjectInputStream(stream); if (stream instanceof VersionedDataStream) { Version v = ((VersionedDataStream) stream).getVersion(); if (v != null && v != Version.CURRENT) { ois = new VersionedObjectInput(ois, v); } } serializableResult = ois.readObject(); if (isDebugEnabled_SERIALIZER) { logger.trace(LogMarker.SERIALIZER, "Read Serializable object: {}", serializableResult); } } if (isDebugEnabled_SERIALIZER) { logger.trace(LogMarker.SERIALIZER, "deserialized instanceof {}", serializableResult.getClass()); } return serializableResult; } case PDX: return readPdxSerializable(in); case PDX_ENUM: return readPdxEnum(in); case GEMFIRE_ENUM: return readGemFireEnum(in); case PDX_INLINE_ENUM: return readPdxInlineEnum(in); case BIG_INTEGER: return readBigInteger(in); case BIG_DECIMAL: return readBigDecimal(in); case UUID: return readUUID(in); case TIMESTAMP: return readTimestamp(in); default: String s = "Unknown header byte: " + header; throw new IOException(s); } }
From source file:org.openTwoFactor.client.util.TwoFactorClientCommonUtils.java
/** * if the method name starts with get, and takes no args, and returns something, * then getter/* ww w . ja v a 2s .co m*/ * @param method * @return true if getter */ public static boolean isGetter(Method method) { //must start with get String methodName = method.getName(); if (!methodName.startsWith("get") && !methodName.startsWith("is")) { return false; } //must not be void if (method.getReturnType() == Void.TYPE) { return false; } //must not take args if (length(method.getParameterTypes()) != 0) { return false; } //must not be static if (Modifier.isStatic(method.getModifiers())) { return false; } return true; }
From source file:org.openTwoFactor.client.util.TwoFactorClientCommonUtils.java
/** * if the method name starts with get, and takes no args, and returns something, * then getter/*from w w w. j a v a 2 s . co m*/ * @param method * @return true if getter */ public static boolean isSetter(Method method) { //must start with get if (!method.getName().startsWith("set")) { return false; } //must be void if (method.getReturnType() != Void.TYPE) { return false; } //must take one arg if (length(method.getParameterTypes()) != 1) { return false; } //must not be static if (Modifier.isStatic(method.getModifiers())) { return false; } return true; }