X Tutup
Skip to content
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 @@ -30,6 +30,7 @@
import javax.lang.model.element.TypeElement;

import org.androidannotations.AndroidAnnotationsEnvironment;
import org.androidannotations.Option;
import org.androidannotations.helper.APTCodeModelHelper;
import org.androidannotations.internal.process.ProcessHolder;

Expand All @@ -41,6 +42,8 @@

public abstract class BaseGeneratedClassHolder implements GeneratedClassHolder {

public static final Option OPTION_GENERATE_FINAL_CLASSES = new Option("generateFinalClasses", "true");

protected final AndroidAnnotationsEnvironment environment;
protected JDefinedClass generatedClass;
protected AbstractJClass annotatedClass;
Expand All @@ -64,10 +67,18 @@ protected void setGeneratedClass() throws Exception {
Element enclosingElement = annotatedElement.getEnclosingElement();
GeneratedClassHolder enclosingHolder = environment.getGeneratedClassHolder(enclosingElement);
String generatedBeanSimpleName = annotatedElement.getSimpleName().toString() + classSuffix();
generatedClass = enclosingHolder.getGeneratedClass()._class(PUBLIC | FINAL | STATIC, generatedBeanSimpleName, EClassType.CLASS);
int modifier = PUBLIC | STATIC;
if (environment.getOptionBooleanValue(OPTION_GENERATE_FINAL_CLASSES)) {
modifier |= FINAL;
}
generatedClass = enclosingHolder.getGeneratedClass()._class(modifier, generatedBeanSimpleName, EClassType.CLASS);
} else {
String generatedClassQualifiedName = annotatedComponentQualifiedName + classSuffix();
generatedClass = getCodeModel()._class(PUBLIC | FINAL, generatedClassQualifiedName, EClassType.CLASS);
int modifier = PUBLIC;
if (environment.getOptionBooleanValue(OPTION_GENERATE_FINAL_CLASSES)) {
modifier |= FINAL;
}
generatedClass = getCodeModel()._class(modifier, generatedClassQualifiedName, EClassType.CLASS);
}
codeModelHelper.generify(generatedClass, annotatedElement);
setExtends();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.androidannotations.Option;
import org.androidannotations.helper.ModelConstants;
import org.androidannotations.holder.BaseGeneratedClassHolder;
import org.androidannotations.internal.helper.AndroidManifestFinder;
import org.androidannotations.internal.rclass.ProjectRClassFinder;
import org.androidannotations.logger.LoggerContext;
Expand All @@ -43,6 +44,7 @@ public Options(ProcessingEnvironment processingEnvironment) {
addSupportedOption(LoggerContext.OPTION_LOG_LEVEL);
addSupportedOption(LoggerContext.OPTION_LOG_APPENDER_CONSOLE);
addSupportedOption(LoggerContext.OPTION_LOG_APPENDER_FILE);
addSupportedOption(BaseGeneratedClassHolder.OPTION_GENERATE_FINAL_CLASSES);
}

public void addAllSupportedOptions(List<Option> options) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright (C) 2010-2015 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.File;
import java.io.IOException;

import org.androidannotations.internal.AndroidAnnotationProcessor;
import org.androidannotations.testutils.AAProcessorTestHelper;
import org.junit.Before;
import org.junit.Test;

public class GenerateFinalClassesFlagTest extends AAProcessorTestHelper {

@Before
public void setUp() {
addManifestProcessorParameter(ActivityInManifest.class);
addProcessor(AndroidAnnotationProcessor.class);
ensureOutputDirectoryIsEmpty();
}

@Test
public void generateFinalClass() throws IOException {
addProcessorParameter("generateFinalClasses", "true");

CompileResult result = compileFiles(ActivityInManifest.class);
File generatedFile = toGeneratedFile(ActivityInManifest.class);

assertCompilationSuccessful(result);

assertGeneratedClassMatches(generatedFile, "public final class ActivityInManifest_");
}

@Test
public void generateNonFinalClass() throws IOException {
addProcessorParameter("generateFinalClasses", "false");

CompileResult result = compileFiles(ActivityInManifest.class);
File generatedFile = toGeneratedFile(ActivityInManifest.class);

assertCompilationSuccessful(result);

assertGeneratedClassMatches(generatedFile, "public class ActivityInManifest_");
}
}
X Tutup