Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.

Fixed some ClassCastException. #247

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ nogit/
RemoteSystemsTempFiles
/.gradle
.DS_Store
pom.xml.versionsBackup
.classpath
.settings
.project
bin
.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.raml.jaxrs.parser.source.SourceParser;

import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
Expand Down Expand Up @@ -58,7 +59,6 @@ static JerseyJaxRsEntity create(Parameter input, SourceParser sourceParser) {
return new JerseyJaxRsEntity(input.getType(), sourceParser);
}


static Optional<JaxRsEntity> create(Type input, SourceParser sourceParser) {

if (input == null) {
Expand All @@ -72,6 +72,13 @@ static Optional<JaxRsEntity> create(Type input, SourceParser sourceParser) {
@Override
public <T extends Annotation> Optional<T> getAnnotation(Class<T> annotationType) {

return (Optional<T>) Optional.fromNullable(((Class) input).getAnnotation(annotationType));
Type type = input;
if (type instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) type;
type = pt.getRawType();
}

Class c = (Class) type;
return (Optional<T>) Optional.fromNullable(((Class) type).getAnnotation(annotationType));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
public class AnnotationInstanceEmitter implements LocalEmitter {

private final IndentedAppendable writer;
private final List<RamlSupportedAnnotation> suportedAnnotations;
private final List<RamlSupportedAnnotation> supportedAnnotations;

public AnnotationInstanceEmitter(IndentedAppendable writer, List<RamlSupportedAnnotation> supportedAnnotation) {
this.writer = writer;
this.suportedAnnotations = supportedAnnotation;
this.supportedAnnotations = supportedAnnotation;
}

@Override
Expand All @@ -65,7 +65,7 @@ public void emit(RamlResourceMethod method) throws IOException {
}

private void annotate(Annotable annotable) throws IOException {
for (RamlSupportedAnnotation suportedAnnotation : suportedAnnotations) {
for (RamlSupportedAnnotation suportedAnnotation : supportedAnnotations) {

Optional<Annotation> annotationOptional = suportedAnnotation.getAnnotationInstance(annotable);
if (annotationOptional.isPresent() == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.ParameterizedType;

/**
* Created by Jean-Philippe Belanger on 3/26/17. Just potential zeroes and ones
Expand Down Expand Up @@ -61,11 +63,19 @@ private void writeBody(TypeRegistry registry, IndentedAppendable writer,
private static class SimpleJaxbTypeScanner implements TypeScanner {

@Override
public void scanType(TypeRegistry typeRegistry, RamlEntity type, RamlType ramlType) {
public void scanType(TypeRegistry typeRegistry, RamlEntity ramlEntity, RamlType ramlType) {
Type type = ramlEntity.getType();
if (type instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) type;
type = pt.getRawType();
};
if (type instanceof TypeVariable) {
type = (Class) ((TypeVariable) type).getGenericDeclaration();
}

Class c = (Class) type.getType();
forFields(typeRegistry, type, ramlType, c);
forProperties(typeRegistry, type, ramlType, c);
Class c = (Class) type;
forFields(typeRegistry, ramlEntity, ramlType, c);
forProperties(typeRegistry, ramlEntity, ramlType, c);
}

private void forProperties(TypeRegistry typeRegistry, RamlEntity type, RamlType ramlType, Class c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.raml.api.Annotable;
import org.raml.api.RamlData;
import org.raml.api.ScalarType;
import org.raml.jaxrs.common.Example;
import org.raml.jaxrs.emitters.AnnotationInstanceEmitter;
import org.raml.jaxrs.emitters.Emittable;
import org.raml.jaxrs.emitters.ExampleEmitter;
Expand All @@ -30,6 +29,9 @@

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -71,8 +73,19 @@ public void addProperty(RamlProperty property) {
}

public void write(AnnotationInstanceEmitter emitter, IndentedAppendable writer) throws IOException {
Type ttype = type.getType();
if (ttype instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) ttype;
ttype = pt.getRawType();
}
if (ttype instanceof TypeVariable) {
System.out.println("Ignored type: " + type);
System.out.println("emitter: " + emitter);
System.out.println("type.getType(): " + ttype);
return;
}

Class c = (Class) type.getType();
Class c = (Class) ttype;
writer.appendLine(c.getSimpleName() + ":");
writer.indent();

Expand Down Expand Up @@ -110,6 +123,7 @@ public void writeExample(IndentedAppendable writer) throws IOException {
}


@SuppressWarnings({"rawtypes"})
public String getTypeName() {

Optional<ScalarType> st = ScalarType.fromType(type.getType());
Expand All @@ -120,12 +134,23 @@ public String getTypeName() {
return st.get().getRamlSyntax();
}
} else {
Type typeType = type.getType();
if (typeType instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) typeType;
typeType = pt.getRawType();
}
String name;
if (typeType instanceof TypeVariable) {
name = ((TypeVariable) typeType).getName();
} else {
Class c = (Class) typeType;
name = c.getSimpleName();
}

Class c = (Class) type.getType();
if (collection == true) {
return c.getSimpleName() + "[]";
return name + "[]";
} else {
return c.getSimpleName();
return name;
}
}
}
Expand Down