Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ Export-Package: org.androidannotations.annotations,
org.androidannotations.annotations.res,
org.androidannotations.annotations.rest,
org.androidannotations.annotations.sharedpreferences,
org.androidannotations.api,
org.androidannotations.api.rest,
org.androidannotations.api.sharedpreferences
org.androidannotations.api.rest
Bundle-Vendor: androidannotations
Bundle-Activator: org.androidannotations.api.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.androidannotations.api.Scope;

/**
* Should be used on custom classes to enable usage of AndroidAnnotations
*
Expand All @@ -36,6 +34,20 @@
@Target(ElementType.TYPE)
public @interface EBean {

public enum Scope {

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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).

Copy link
Copy Markdown
Contributor

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.


/**
* A new instance of the bean is created each time it is needed
*/
Default, //

/**
* A new instance of the bean is created the first time it is needed, it is
* then retained and the same instance is always returned.
*/
Singleton, //
}

Scope scope() default Scope.Default;

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.androidannotations.api.sharedpreferences.SharedPreferencesHelper;

/**
* Injects a {@link SharedPref}
*
Expand Down
8 changes: 7 additions & 1 deletion 8 AndroidAnnotations/androidannotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>1.6_r2</version>
<scope>test</scope>
<scope>provided</scope>
</dependency>
<dependency>
<!-- spring-android-rest-template is required to use the Rest API -->
Expand Down Expand Up @@ -85,6 +85,12 @@
<exclude>rebel.xml</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>org/androidannotations/api/**</include>
</includes>
</resource>
</resources>
</build>

Expand Down
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
Expand Up @@ -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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this stay package protected?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ow. Interesting.


private SharedPreferencesCompat() {
}
Expand Down
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.annotation.processing.Messager;

import org.androidannotations.processing.ModelProcessor.ProcessResult;

import com.sun.codemodel.writer.PrologCodeWriter;

public class CodeModelGenerator {
Expand All @@ -35,11 +36,13 @@ public CodeModelGenerator(Filer filer, Messager messager) {

public void generate(ProcessResult processResult) throws IOException {

SourceCodewriter sourceCodeWriter = new SourceCodewriter(filer, messager, processResult.originatingElementsByGeneratedClassQualifiedName);
ApiCodeGenerator apiCodeGenerator = new ApiCodeGenerator(filer);
apiCodeGenerator.writeApiClasses(processResult.apiClassesToGenerate, processResult.originatingElements);

SourceCodewriter sourceCodeWriter = new SourceCodewriter(filer, messager, processResult.originatingElements);

PrologCodeWriter prologCodeWriter = new PrologCodeWriter(sourceCodeWriter, "DO NOT EDIT THIS FILE, IT HAS BEEN GENERATED USING AndroidAnnotations.\n");

processResult.codeModel.build(prologCodeWriter, new ResourceCodeWriter(filer));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;

import javax.annotation.processing.Filer;
import javax.annotation.processing.FilerException;
Expand All @@ -26,6 +25,8 @@
import javax.tools.Diagnostic.Kind;
import javax.tools.JavaFileObject;

import org.androidannotations.processing.OriginatingElements;

import com.sun.codemodel.CodeWriter;
import com.sun.codemodel.JPackage;

Expand All @@ -35,7 +36,7 @@ public class SourceCodewriter extends CodeWriter {
private final Messager message;

private static final VoidOutputStream VOID_OUTPUT_STREAM = new VoidOutputStream();
private Map<String, Element> originatingElementsByGeneratedClassQualifiedName;
private OriginatingElements originatingElements;

private static class VoidOutputStream extends OutputStream {
@Override
Expand All @@ -44,28 +45,28 @@ public void write(int arg0) throws IOException {
}
}

public SourceCodewriter(Filer filer, Messager message, Map<String, Element> originatingElementsByGeneratedClassQualifiedName) {
public SourceCodewriter(Filer filer, Messager message, OriginatingElements originatingElements) {
this.filer = filer;
this.message = message;
this.originatingElementsByGeneratedClassQualifiedName = originatingElementsByGeneratedClassQualifiedName;
this.originatingElements = originatingElements;
}

@Override
public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
String qualifiedClassName = toQualifiedClassName(pkg, fileName);
message.printMessage(Kind.NOTE, "Generating source file: " + qualifiedClassName);

Element originatingElement = originatingElementsByGeneratedClassQualifiedName.get(qualifiedClassName);
Element[] classOriginatingElements = originatingElements.getClassOriginatingElements(qualifiedClassName);

try {
JavaFileObject sourceFile;
if (originatingElement != null) {
sourceFile = filer.createSourceFile(qualifiedClassName, originatingElement);
} else {

if (classOriginatingElements.length == 0) {
message.printMessage(Kind.NOTE, "Generating class with no originating element: " + qualifiedClassName);
sourceFile = filer.createSourceFile(qualifiedClassName);
}

sourceFile = filer.createSourceFile(qualifiedClassName, classOriginatingElements);

return sourceFile.openOutputStream();
} catch (FilerException e) {
message.printMessage(Kind.NOTE, "Could not generate source file for " + qualifiedClassName + ", message: " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.androidannotations.annotations.Background;
import org.androidannotations.api.BackgroundExecutor;
import org.androidannotations.helper.APTCodeModelHelper;

import com.sun.codemodel.JClass;
import com.sun.codemodel.JClassAlreadyExistsException;
import com.sun.codemodel.JCodeModel;
Expand All @@ -45,6 +46,8 @@ public void process(Element element, JCodeModel codeModel, EBeanHolder holder) t

ExecutableElement executableElement = (ExecutableElement) element;

holder.generateApiClass(element, BackgroundExecutor.class);

JMethod delegatingMethod = helper.overrideAnnotatedMethod(executableElement, holder);

JDefinedClass anonymousRunnableClass = helper.createDelegatingAnonymousRunnableClass(holder, delegatingMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package org.androidannotations.processing;

import static org.androidannotations.helper.GreenDroidConstants.GREENDROID_ACTIVITIES_LIST_CLASS;
import static com.sun.codemodel.JExpr._super;
import static com.sun.codemodel.JExpr._this;
import static com.sun.codemodel.JMod.PRIVATE;
import static com.sun.codemodel.JMod.PUBLIC;
import static org.androidannotations.helper.GreenDroidConstants.GREENDROID_ACTIVITIES_LIST_CLASS;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
Expand All @@ -41,6 +41,7 @@
import org.androidannotations.helper.ModelConstants;
import org.androidannotations.rclass.IRClass;
import org.androidannotations.rclass.IRClass.Res;

import com.sun.codemodel.ClassType;
import com.sun.codemodel.JBlock;
import com.sun.codemodel.JClass;
Expand Down Expand Up @@ -167,7 +168,11 @@ public void process(Element element, JCodeModel codeModel, EBeansHolder eBeansHo
setContentViewMethod(setContentViewMethodName, codeModel, holder, new JType[] { holder.classes().VIEW }, new String[] { "view" });

// Handling onBackPressed
if (hasOnBackPressedMethod(typeElement)) {
Element declaredOnBackPressedMethod = getOnBackPressedMethod(typeElement);
if (declaredOnBackPressedMethod != null) {

eBeansHolder.generateApiClass(declaredOnBackPressedMethod, SdkVersionHelper.class);

JMethod onKeyDownMethod = holder.generatedClass.method(PUBLIC, codeModel.BOOLEAN, "onKeyDown");
onKeyDownMethod.annotate(Override.class);
JVar keyCodeParam = onKeyDownMethod.param(codeModel.INT, "keyCode");
Expand Down Expand Up @@ -215,18 +220,18 @@ private void setContentViewMethod(String setContentViewMethodName, JCodeModel co
body.invoke(holder.afterSetContentView);
}

private boolean hasOnBackPressedMethod(TypeElement activityElement) {
private ExecutableElement getOnBackPressedMethod(TypeElement activityElement) {

List<? extends Element> allMembers = annotationHelper.getElementUtils().getAllMembers(activityElement);

List<ExecutableElement> activityInheritedMethods = ElementFilter.methodsIn(allMembers);

for (ExecutableElement activityInheritedMethod : activityInheritedMethods) {
if (isCustomOnBackPressedMethod(activityInheritedMethod)) {
return true;
return activityInheritedMethod;
}
}
return false;
return null;
}

private boolean isCustomOnBackPressedMethod(ExecutableElement method) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
import java.lang.annotation.Annotation;
import java.util.HashMap;

import javax.lang.model.element.Element;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.processing.EBeansHolder.Classes;

import com.sun.codemodel.JBlock;
import com.sun.codemodel.JCase;
import com.sun.codemodel.JClass;
Expand Down Expand Up @@ -137,4 +140,8 @@ public JClass refClass(Class<?> clazz) {
return eBeansHolder.refClass(clazz);
}

public void generateApiClass(Element originatingElement, Class<?> apiClass) {
eBeansHolder.generateApiClass(originatingElement, apiClass);
}

}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.