/** * Gets the appropriate {@link Type} for the given type. * * @param type The type * @return The type */ static Type of(final String type) { return new TypeReader(type).readType(); }
/** * Reads the next {@link ArrayType} from source. * * @return The type * @throws IllegalStateException If the descriptor is invalid */ public ArrayType readArrayType() { int count = 0; while (this.hasNext() && this.peek() == '[') { this.advance(); count++; } return new ArrayType(count, this.readFieldType()); }
/** * Gets the appropriate {@link FieldType} for the given type. * * @param type The field type * @return The field type */ static FieldType of(final String type) { return new TypeReader(type).readFieldType(); }
/** * Reads the next {@link Type} from source. * * @return The type * @throws IllegalStateException If the descriptor is invalid */ public Type readType() { // Void Type if (this.peek() == 'V') { this.advance(); return VoidType.INSTANCE; } // Field Type return this.readFieldType(); }
/** * Reads the next {@link FieldType} from source. * * @return The type * @throws IllegalStateException If the descriptor is invalid */ public FieldType readFieldType() { // Array Type if (this.peek() == '[') { return this.readArrayType(); } // Base Type if (BaseType.isValidBase(this.peek())) { return this.readBaseType(); } // Object Type if (this.peek() == 'L') { return this.readObjectType(); } throw new IllegalStateException("Invalid descriptor provided!"); }
/** * Reads the next {@link ObjectType} from source. * * @return The type * @throws IllegalStateException If the descriptor is invalid */ public ObjectType readObjectType() { final int start = this.current; this.advance(); while (this.hasNext() && this.peek() != ';') { this.advance(); } if (this.peek() != ';') throw new IllegalStateException("Incomplete descriptor provided!"); this.advance(); return new ObjectType(this.source.substring(start + 1, this.current - 1)); }
/** * Reads the next {@link PrimitiveType} from source. * * @return The type * @throws IllegalStateException If the descriptor is invalid */ public PrimitiveType readPrimitiveType() { // Void Type if (this.peek() == 'V') { this.advance(); return VoidType.INSTANCE; } // Base Type if (BaseType.isValidBase(this.peek())) { return this.readBaseType(); } throw new IllegalStateException("Invalid descriptor provided!"); }
/** * Reads the next {@link BaseType} from source. * * @return The type * @throws IllegalStateException If the descriptor is invalid */ public BaseType readBaseType() { return BaseType.getFromKey(this.advance()); }