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 @@ -94,6 +94,10 @@ public void process(Element element, JCodeModel codeModel, EBeansHolder eBeansHo
holder.initActivityRef = helper.castContextToActivity(holder, holder.initIfActivityBody);
}

EBean eBeanAnnotation = element.getAnnotation(EBean.class);
EBean.Scope eBeanScope = eBeanAnnotation.scope();
boolean hasSingletonScope = eBeanScope == EBean.Scope.Singleton;

{
// Constructor

Expand All @@ -113,13 +117,11 @@ public void process(Element element, JCodeModel codeModel, EBeansHolder eBeansHo

constructorBody.assign(contextField, constructorContextParam);

constructorBody.invoke(init);
if (!hasSingletonScope) {
constructorBody.invoke(init);
}
}

EBean eBeanAnnotation = element.getAnnotation(EBean.class);
EBean.Scope eBeanScope = eBeanAnnotation.scope();
boolean hasSingletonScope = eBeanScope == EBean.Scope.Singleton;

{
// Factory method

Expand All @@ -141,6 +143,7 @@ public void process(Element element, JCodeModel codeModel, EBeansHolder eBeansHo
._then();
JVar previousNotifier = holder.replacePreviousNotifierWithNull(creationBlock);
creationBlock.assign(instanceField, _new(holder.generatedClass).arg(factoryMethodContextParam.invoke("getApplicationContext")));
creationBlock.invoke(instanceField, init);
holder.resetPreviousNotifier(creationBlock, previousNotifier);

factoryMethodBody._return(instanceField);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.androidannotations.test15.ebean;

import static org.fest.assertions.Assertions.assertThat;

import org.junit.Test;
import org.junit.runner.RunWith;

import org.androidannotations.test15.AndroidAnnotationsTestRunner;
import org.androidannotations.test15.EmptyActivityWithoutLayout_;

@RunWith(AndroidAnnotationsTestRunner.class)
public class CyclicSingletonTest {

@Test
public void cyclic_singleton() {
EmptyActivityWithoutLayout_ context = new EmptyActivityWithoutLayout_();
SomeCyclicSingletonA_ singletonA = SomeCyclicSingletonA_.getInstance_(context);
SomeCyclicSingletonB_ singletonB = SomeCyclicSingletonB_.getInstance_(context);
assertThat(singletonA.singletonB).isSameAs(singletonB);
assertThat(singletonB.singletonA).isSameAs(singletonA);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (C) 2010-2013 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.test15.ebean;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean;

@EBean(scope = EBean.Scope.Singleton)
public class SomeCyclicSingletonA {

@Bean
SomeCyclicSingletonB singletonB;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (C) 2010-2013 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.test15.ebean;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean;

@EBean(scope = EBean.Scope.Singleton)
public class SomeCyclicSingletonB {

@Bean
SomeCyclicSingletonA singletonA;

}