-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Generate api helper classes at compile time #410
Changes from all commits
c8c6c5a
556da48
3906239
175d16d
c5bfe3e
062753a
dba2eb0
6518644
fc801b4
fc3d52e
d7342c9
486033e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /** | ||
| * Copyright (C) 2010-2012 eBusiness Information, Excilys Group | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy of | ||
| * the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed To in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
| package org.androidannotations.api.rest; | ||
|
|
||
| public final class MediaType { | ||
|
|
||
| public final static String ALL = "*/*"; | ||
| public final static String APPLICATION_ATOM_XML = "application/atom+xml"; | ||
| public final static String APPLICATION_RSS_XML = "application/rss+xml"; | ||
| public final static String APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded"; | ||
| public final static String APPLICATION_JSON = "application/json"; | ||
| public final static String APPLICATION_OCTET_STREAM = "application/octet-stream"; | ||
| public final static String APPLICATION_XHTML_XML = "application/xhtml+xml"; | ||
| public final static String IMAGE_GIF = "image/gif"; | ||
| public final static String IMAGE_JPEG = "image/jpeg"; | ||
| public final static String IMAGE_PNG = "image/png"; | ||
| public final static String APPLICATION_XML = "application/xml"; | ||
| public final static String APPLICATION_WILDCARD_XML = "application/*+xml"; | ||
| public final static String MULTIPART_FORM_DATA = "multipart/form-data"; | ||
| public final static String TEXT_HTML = "text/html"; | ||
| public final static String TEXT_PLAIN = "text/plain"; | ||
| public final static String TEXT_XML = "text/xml"; | ||
|
|
||
| private MediaType() { | ||
|
|
||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ | |
| * Reflection utils to call SharedPreferences$Editor.apply when possible, | ||
| * falling back to commit when apply isn't available. | ||
| */ | ||
| abstract class SharedPreferencesCompat { | ||
| public abstract class SharedPreferencesCompat { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this stay package protected?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, but i made that to be able to reference it from processor (https://github.com/excilys/androidannotations/blob/129_GenerateApiHelperClasses/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/SharedPrefProcessor.java#L291)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ow. Interesting. |
||
|
|
||
| private SharedPreferencesCompat() { | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /** | ||
| * Copyright (C) 2010-2012 eBusiness Information, Excilys Group | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy of | ||
| * the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed To in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
| package org.androidannotations.generation; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.OutputStream; | ||
| import java.util.Set; | ||
|
|
||
| import javax.annotation.processing.Filer; | ||
| import javax.lang.model.element.Element; | ||
| import javax.tools.JavaFileObject; | ||
|
|
||
| import org.androidannotations.processing.OriginatingElements; | ||
|
|
||
| public class ApiCodeGenerator { | ||
|
|
||
| private static final byte[] BUFFER = new byte[4096]; | ||
|
|
||
| private static void copyStream(InputStream input, OutputStream output) throws IOException { | ||
| int read; | ||
| while ((read = input.read(BUFFER)) != -1) { | ||
| output.write(BUFFER, 0, read); | ||
| } | ||
| } | ||
|
|
||
| private final Filer filer; | ||
|
|
||
| public ApiCodeGenerator(Filer filer) { | ||
| this.filer = filer; | ||
| } | ||
|
|
||
| public void writeApiClasses(Set<Class<?>> apiClassesToGenerate, OriginatingElements originatingElements) { | ||
|
|
||
| for (Class<?> apiClassToGenerate : apiClassesToGenerate) { | ||
|
|
||
| String canonicalApiClassName = apiClassToGenerate.getCanonicalName(); | ||
|
|
||
| String apiClassFileName = canonicalApiClassName.replace(".", "/") + ".java"; | ||
|
|
||
| InputStream apiClassStream = getClass().getClassLoader().getResourceAsStream(apiClassFileName); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Different options, worth looking at: http://stackoverflow.com/questions/1921975/java-convert-package-name-to-path |
||
| try { | ||
|
|
||
| if (apiClassStream == null) { | ||
| /* | ||
| * This happens when in AA dev environment, when the | ||
| * processor classes are not coming from a jar | ||
| */ | ||
| apiClassStream = getClass().getClassLoader().getResourceAsStream('/' + apiClassFileName); | ||
| } | ||
|
|
||
| Element[] apiClassOriginatingElements = originatingElements.getClassOriginatingElements(canonicalApiClassName); | ||
|
|
||
| JavaFileObject targetedClassFile; | ||
| if (apiClassOriginatingElements == null) { | ||
| targetedClassFile = filer.createSourceFile(canonicalApiClassName); | ||
| } else { | ||
| targetedClassFile = filer.createSourceFile(canonicalApiClassName, apiClassOriginatingElements); | ||
| } | ||
|
|
||
| OutputStream classFileOutputStream = targetedClassFile.openOutputStream(); | ||
| copyStream(apiClassStream, classFileOutputStream); | ||
| classFileOutputStream.close(); | ||
|
|
||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is that related to your changes? Moving Scope means breaking package retro compatibility.. of course we already broke it by changing to
org.androidannotations, but I'd like a clear explanation on this change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made this change to enhance consistency.
We have already an enum named Scope to deal with @SharedPreference declared as an inner class of this annotation. This Scope class related to @ebean was declared into the api package (org.androidannotations.api.Scope) like the helper classes and the @ebean annotation in the annotation package (org.androidannotations.annotations).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Then we should update the release notes of 3.0 to write this as one of the non backward compatible changes.