I didn't follow the compiler path for Bindable yet even if I understand
globally what it does but for Singleton, the key would be to pass by an
internal Class still visible in the same package :P,
And protected and final for private classes ?
public final PrivateClass {
public function PrivateClass (privateCtor:PrivateClass ) {
if (privateCtor!= this)
//ERROR
}
}
or only thru protected (extends only):
public class BaseClass {
public function BaseClass(protectedCtor:BaseClass) {
if (protectedCtor!= this)
//ERROR
}
}
// (extends only):
public class SubClass {
public function SubClass (protectedCtor:SubClass ) {
super(this);
}
}
// public
public class SubClass2 {
public function SubClass2 () {
super(this);
}
}
Doing so we've got the same base, is this code correct ?
Frédéric THOMAS
> From: aha...@adobe.com
> To: dev@flex.apache.org
> Subject: Re: AW: [Falcon] Constructor NS (was: [Falcon] starting up)
> Date: Mon, 6 Oct 2014 22:53:16 +0000
>
> Already, the compiler knows if you do
>
> [Bindable]
> public class MyClass {
> public var foo:int;
> }
>
> that it should auto-generate some code, then the whole thing is handed
> down to the reducer/emitter. Seems like you could inject SecretToken in a
> similar way if someone did:
>
> [Singleton]
> public class MySingleton {
> }
>
>
> -Alex
>
> On 10/6/14, 3:44 PM, "Frédéric THOMAS" <webdoubl...@hotmail.com> wrote:
>
> >Actually, I guess I would find where and maybe how as I've seen it while
> >I was debugging the constructor, at emit time, but would mean to generate
> >"
> >internal class SecretToken {}" and that I've got no idea when and how.
> >Frédéric THOMAS
> >
> >> From: webdoubl...@hotmail.com
> >> To: dev@flex.apache.org
> >> Subject: RE: AW: [Falcon] Constructor NS (was: [Falcon] starting up)
> >> Date: Mon, 6 Oct 2014 23:27:58 +0100
> >>
> >> Hi Alex,
> >>
> >> > I have no idea what the right answer is, but I was wondering if you
> >>could
> >> > try to describe (in AS code) what scenarios you want to support and
> >>not
> >> > support. Is this just for Singletons or are there other use cases?
> >>And
> >> > what edge cases are allowed, if any?
> >>
> >> It is not only for the singleton, for examle, at some point, I would
> >>like to be able to do that:
> >> [Abstract]
> >> public class BaseClass {
> >>
> >> public static const INSTANCE:BaseClass = new BaseClass(11);
> >>
> >> private var _p:int;
> >>
> >> protected function BaseClass(p:int) {
> >> _p = p;
> >> }
> >>
> >> public function get p():int;
> >> }
> >> }
> >>
> >> ---
> >>
> >> // Error, p not implemented
> >> public class SubClass extends BaseClass {
> >>
> >> public function SubClass() {
> >> super(12);
> >> }
> >> }
> >>
> >> ---
> >> public class AnotherClass {
> >>
> >> public function AnotherClass() {
> >> const a:BaseClass = new BaseClass(13); // Error, can't
> >>instantiate a non public ctor.
> >> }
> >> }> Maybe some metadata can cause the compiler to generate different AS
> >>that
> >> > is sufficient for your needs. You could even change any call to the
> >> > constructor from within the Singleton source code to some other
> >>function
> >> > that initializes the single instance.
> >>
> >> Yes, I guess we could eventually generate some ABC code to simulate the
> >>behavior, just for now, I'm not sure when and how exactly to tell the
> >>compiler to generate that in case of private ctor, this in case of
> >>protected, I'm just discovering it but will continue to dig into.
> >>
> >> Frédéric THOMAS
> >>
> >> > From: aha...@adobe.com
> >> > To: dev@flex.apache.org
> >> > Subject: Re: AW: [Falcon] Constructor NS (was: [Falcon] starting up)
> >> > Date: Mon, 6 Oct 2014 21:57:09 +0000
> >> >
> >> > Hi Fred,
> >> >
> >> > I have no idea what the right answer is, but I was wondering if you
> >>could
> >> > try to describe (in AS code) what scenarios you want to support and
> >>not
> >> > support. Is this just for Singletons or are there other use cases?
> >>And
> >> > what edge cases are allowed, if any?
> >> >
> >> > For example, if you have code like:
> >> >
> >> > var c:Class = MySingleton;
> >> > var instance:MySingleton = new c();
> >> >
> >> > what would you want to have happen? I¹d guess the compiler cannot
> >>check
> >> > it.
> >> >
> >> > Similarly, are there any AS Singleton patterns that are sufficient?
> >>Such
> >> > as:
> >> >
> >> > public class MySingleton
> >> > {
> >> > public function MySingleton(secretToken:SecretToken)
> >> > {
> >> > }
> >> > }
> >> > internal class SecretToken
> >> > {
> >> > }
> >> >
> >> > Maybe some metadata can cause the compiler to generate different AS
> >>that
> >> > is sufficient for your needs. You could even change any call to the
> >> > constructor from within the Singleton source code to some other
> >>function
> >> > that initializes the single instance.
> >> >
> >> > Thanks,
> >> > -Alex
> >> >
> >> >
> >> > On 10/6/14, 2:33 PM, "Frédéric THOMAS" <webdoubl...@hotmail.com>
> >>wrote:
> >> >
> >> > >
> >> > >
> >> > >
> >> > >Hi Gordon, Darrell, Alex,
> >> > >
> >> > >I've been able to work on it a bit tonight and realized that I was
> >>wrong,
> >> > >actually, I can get the right NS infos parsed and emitted but can't
> >>get
> >> > >it back thru the ABCParser.
> >> > >I've been confused because I didn't check the Qualifier NS but
> >>instead
> >> > >its kind which was 5 (private) as I wanted but it was actually the
> >>one of
> >> > >the CMImplicitNS (aka, invalid NS) and wasn,'t able to find in the
> >>chain
> >> > >where it has been forced as I thought having removed all the one
> >> > >implicated in defining a ctor NS, I wonder now if the fact that the
> >>ctor
> >> > >is not part of a trait is the cause ?
> >> > >
> >> > >Any way, I started to explore other possibilities, one of them is to
> >>pass
> >> > >the NS info via MetaTag as done for go_to_definition and use this
> >>info in
> >> > >the semantic checker as I can't at the time of the ABC Parsing, set
> >>the
> >> > >NS because the Metadata are checked after the methodbody and in more,
> >> > >I've got no info at this point about the super class except its name
> >> > >coming from InstanceInfo (or indirectly via IReference) but would
> >>like to
> >> > >think I can manage to use the MetaTag (like
> >> > >"[constructor(ns:'protected')] in the semantic checker, do you see
> >>any
> >> > >problem in doing so or if there's a better place and moment to do it
> >> > >except it could be erased by the optimiser ?
> >> > >
> >> > >The last possibility as I didn't see any drawback yet in debugging
> >>it in
> >> > >the emitter, is to pass the info directly in the name at FunctionNode
> >> > >construction time and either set the NS accordingly or use this info
> >>in
> >> > >the semantic checker, as far as I've debugged it (didn't to the
> >>test yet
> >> > >but followed all the emitter chain), I didn't see any problem that
> >>could
> >> > >be to emit it and don't think there are any in reading it either
> >>thru the
> >> > >ABCParser, I would pass for example pass
> >>"protected:MyConstructorName",
> >> > >tweak the FunctionNode:isConstructor accordingly and remove the
> >> > >CMImplitNS checks as I did until now, what do you think, do you see
> >>any
> >> > >problem with this approach ?
> >> > >
> >> > >More over if the latter appears to be a valid option, it could be
> >>used
> >> > >for the method overloading.
> >> > >
> >> > >Thanks,
> >> > >Frédéric THOMAS
> >> > >
> >> > >> Subject: Re: AW: [Falcon] Constructor NS (was: [Falcon] starting
> >>up)
> >> > >> From: gsmit...@hotmail.com
> >> > >> Date: Sun, 5 Oct 2014 09:24:14 -0700
> >> > >> To: dev@flex.apache.org
> >> > >>
> >> > >> It's a bit different in that the AVM is strict about access
> >>modifiers;
> >> > >>you cannot use reflection to call a private method from outside its
> >> > >>class. However I know developers have wanted non-public
> >>constructors for
> >> > >>a long time and most won't care if they're not enforced at runtime,
> >>so I
> >> > >>don't object to the compiler enhancement. I just wanted to mention
> >> > >>something that folks should be aware of.
> >> > >>
> >> > >> Another thing to be aware of is that this mean there will be source
> >> > >>code that compiles under a Falcon that doesn't compile under the old
> >> > >>compiler. Would we change the old compiler as we'll or not bother?
> >>I'd
> >> > >>say don't bother.
> >> > >>
> >> > >> - Gordon
> >> > >>
> >> > >> > On Oct 5, 2014, at 8:09 AM, "Christofer Dutz"
> >> > >><christofer.d...@c-ware.de> wrote:
> >> > >> >
> >> > >> > But in java this is not much different. Unless you explicitly
> >>tell
> >> > >>your Java VM to be strict, you can get a private constructor via
> >> > >>Reflection, make this accesslible at runtime and instantiate it, no
> >> > >>matter what the source-code says. Same with the type of generics.
> >> > >> >
> >> > >> > So I guess it would be a great addition to Flex to at least have
> >> > >>features checked by the compiler, even if the runtime doesn't
> >>enforce it.
> >> > >> >
> >> > >> > Chris
> >> > >> >
> >> > >> >
> >> > >> > -----Ursprüngliche Nachricht-----
> >> > >> > Von: Gordon Smith [mailto:gsmit...@hotmail.com]
> >> > >> > Gesendet: Sonntag, 5. Oktober 2014 04:36
> >> > >> > An: dev@flex.apache.org
> >> > >> > Betreff: Re: [Falcon] Constructor NS (was: [Falcon] starting up)
> >> > >> >
> >> > >> > In general the ActionScript Virtual Machine enforces access
> >>modifiers
> >> > >>(so that, for example, something marked private is truly
> >>inaccessible by
> >> > >>any means outside the class) but I don't think the AVM enforces
> >> > >>non-public constructors. I'm guessing that a constructor in the ABC
> >>is
> >> > >>public regardless of what the source code says, which would mean
> >>that
> >> > >>the constructor could be invoked by any code via reflection. If
> >>this is
> >> > >>the case, I'm not convinced we should pretend that constructors can
> >>be
> >> > >>non-public.
> >> > >> >
> >> > >> > - Gordon
> >> > >> >
> >> > >> > Sent from my iPad
> >> > >> >
> >> > >> >>> On Oct 4, 2014, at 4:14 PM, "OmPrakash Muppirala"
> >> > >><bigosma...@gmail.com> wrote:
> >> > >> >>>
> >> > >> >>> On Oct 4, 2014 12:55 PM, "Frédéric THOMAS"
> >> > >><webdoubl...@hotmail.com> wrote:
> >> > >> >>>
> >> > >> >>> Hi,
> >> > >> >>>
> >> > >> >>> I started to check if it was possible to have private and
> >>protected
> >> > >> >> constructor in Falcon and I have to admit it was tricky
> >>especially
> >> > >> >> because I never seen a compiler from inside before but it is
> >> > >> >> apparently possible, I've been able to compile successfully:
> >> > >> >>> package myLib {
> >> > >> >>> public class CTORTest {
> >> > >> >>> private var _p:int;
> >> > >> >>>
> >> > >> >>> private function CTORTest(p:int) {
> >> > >> >>> _p = p;
> >> > >> >>> }
> >> > >> >>>
> >> > >> >>> private function anotherFct():CTORTest {
> >> > >> >>> return new CTORTest(10);
> >> > >> >>> }
> >> > >> >>> }
> >> > >> >>> }
> >> > >> >>> and using the compiled lib:
> >> > >> >>>
> >> > >> >>> <?xml version="1.0"?>
> >> > >> >>> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
> >> > >> >> xmlns:s="library://ns.adobe.com/flex/spark"
> >> > >> >> creationComplete="creationCompleteHandler(event)">
> >> > >> >>> <fx:Script><![CDATA[
> >> > >> >>> import mx.events.FlexEvent;
> >> > >> >>>
> >> > >> >>> import myLib.CTORTest;
> >> > >> >>>
> >> > >> >>> private function
> >> > >>creationCompleteHandler(event:FlexEvent):void {
> >> > >> >>> var a:CTORTest = new CTORTest(1);
> >> > >> >>> }
> >> > >> >>> ]]></fx:Script>
> >> > >> >>> </s:Application>
> >> > >> >>>
> >> > >> >>> gives:
> >> > >> >>> [Fault] exception, information=VerifyError: Error #1014: La
> >>classe
> >> > >> >> myLib:CTORTest::CTORTest est introuvable. (not found) with the
> >> > >>legacy
> >> > >> >> compiler
> >> > >> >>> and:
> >> > >> >>> F:\sources\falconTestDrive\shell\src\Main.mxml:9
> >> > >> >>> Erreur: Appel d'une méthode qui ne semble pas définie CTORTest.
> >> > >>(Call
> >> > >> >>> to
> >> > >> >> a undefined method)
> >> > >> >>> var a:CTORTest = new CTORTest(1);
> >> > >> >>>
> >> > >> >>> (I will customize the error message later)
> >> > >> >>>
> >> > >> >>> I still need to check it works in the 3 possible ways to
> >> > >>instantiate
> >> > >> >>> a
> >> > >> >> Class [1] (at the moment it works only with 1st one), check that
> >> > >>works
> >> > >> >> with is / instanceOf, revisit the cast function accordingly and
> >> > >>maybe
> >> > >> >> other things not yet in my mind and especially check FP won't
> >> > >>complain using it.
> >> > >> >>>
> >> > >> >>> /* expression = FunctionCallID(KeywordNewID(void),
> >>new_type_name,
> >> > >> >> ContainerID(expression*)) */
> >> > >> >>> /* expression = FunctionCallID(KeywordNewID(void), expression,
> >> > >> >> ContainerID(expression*)) */
> >> > >> >>> /* expression = FunctionCallID(KeywordNewID(void),
> >>vector_literal,
> >> > >> >> ContainerID(void)) */
> >> > >> >>>
> >> > >> >>> In case all this works and I'm far to know it at the moment, I
> >>will
> >> > >> >>> have
> >> > >> >> to think about implement "method overloading" otherwise I can't
> >>see
> >> > >> >> any usage of a protected constructor and therefore will probably
> >> > >> >> require some help for the best way to implement it.
> >> > >> >>
> >> > >> >> Exciting to see these kind of experiments. A really good
> >>usecase
> >> > >>for
> >> > >> >> private constructor would be to create a Singleton class, I.e a
> >> > >>class
> >> > >> >> that cannot be instantiated outside of itself. Would that be
> >> > >> >> something you can test for?
> >> > >> >>
> >> > >> >> Thanks,
> >> > >> >> Om
> >> > >> >>
> >> > >> >>>
> >> > >> >>> Thanks,
> >> > >> >>> Frédéric THOMAS
> >> > >> >>>
> >> > >> >>>> From: webdoubl...@hotmail.com
> >> > >> >>>> To: dev@flex.apache.org
> >> > >> >>>> Subject: RE: [Falcon] starting up
> >> > >> >>>> Date: Wed, 1 Oct 2014 16:57:28 +0100
> >> > >> >>>>
> >> > >> >>>> Ah ok, thanks Gordon, I was tearing my hair out :-)
> >> > >> >>>>
> >> > >> >>>> Frédéric THOMAS
> >> > >> >>>>
> >> > >> >>>>> Subject: Re: [Falcon] starting up
> >> > >> >>>>> From: gsmit...@hotmail.com
> >> > >> >>>>> Date: Wed, 1 Oct 2014 08:51:16 -0700
> >> > >> >>>>> To: dev@flex.apache.org
> >> > >> >>>>>
> >> > >> >>>>> That comment is out of date. Code Model was the part of
> >>pre-Falcon
> >> > >> >> Flash Builder that built an abstract syntax tree to support
> >> > >> >> intelligent editing. We used it as the beginning of Falcon's
> >>lexer
> >> > >>and
> >> > >> >> parser. The code is just looking at the AST to see if the
> >> > >>constructor
> >> > >> >> has a non-public namespace.
> >> > >> >>>>>
> >> > >> >>>>> - Gordon
> >> > >> >>>>>
> >> > >> >>>>>> On Oct 1, 2014, at 8:33 AM, "Frédéric THOMAS" <
> >> > >> >> webdoubl...@hotmail.com> wrote:
> >> > >> >>>>>>
> >> > >> >>>>>>
> >> > >> >>>>>>
> >> > >> >>>>>>
> >> > >> >>>>>>
> >> > >> >>>>>>
> >> > >> >>>>>>
> >> > >> >>>>>> I updated it to v17.0 and check in
> >> > >> >> falcon\compiler\generated\dist\sdk\lib\external, is there.
> >> > >> >>>>>>
> >> > >> >>>>>> oops, looking better, it has both, just removed the bad
> >>one, it
> >> > >> >> runs.
> >> > >> >>>>>>
> >> > >> >>>>>> Now, looking at
> >> > >>internal\as\codegen\ClassDirectiveProcessor.java,
> >> > >> >>>>>> I
> >> > >> >> see that:
> >> > >> >>>>>>
> >> > >> >>>>>> // If a constructor has a namespace as part of it's
> >>declaration,
> >> > >> >>>>>> it
> >> > >> >> must be declared public.
> >> > >> >>>>>> // It is ok to omit the namespace
> >> > >> >>>>>> // We must check the AST, as CM treats all ctors as public
> >>no
> >> > >> >> matter what the user typed in
> >> > >> >>>>>> // so the FunctionDefinition will always be in the public
> >> > >> >>>>>> namespace if( node.getActualNamespaceNode() != null &&
> >> > >> >>>>>> node.getActualNamespaceNode().getName() !=
> >> > >> >> IASKeywordConstants.PUBLIC)
> >> > >> >>>>>> problems.add(new
> >> > >> >> ConstructorMustBePublicProblem(node.getActualNamespaceNode()));
> >> > >> >>>>>>
> >> > >> >>>>>> What is the CM or Code Model ?
> >> > >> >>>>>>
> >> > >> >>>>>> Thanks,
> >> > >> >>>>>> Frédéric THOMAS
> >> > >> >>>>>>
> >> > >> >>>>>>> From: aha...@adobe.com
> >> > >> >>>>>>> To: dev@flex.apache.org
> >> > >> >>>>>>> Subject: Re: [Falcon] starting up
> >> > >> >>>>>>> Date: Wed, 1 Oct 2014 13:36:50 +0000
> >> > >> >>>>>>>
> >> > >> >>>>>>> Could you have an old guava.jar?
> >> > >> >>>>>>>
> >> > >> >>>>>>>> On 10/1/14 4:32 AM, "Frédéric THOMAS"
> >><webdoubl...@hotmail.com>
> >> > >> >> wrote:
> >> > >> >>>>>>>>
> >> > >> >>>>>>>> Hi,
> >> > >> >>>>>>>>
> >> > >> >>>>>>>> I built it with ANT an ran Falcon compc.bat from the
> >> > >> >> generated/dist/sdk,
> >> > >> >>>>>>>> does anyone knows why I get that ?
> >> > >> >>>>>>>>
> >> > >> >>>>>>>> Exception in thread "main" java.lang.NoClassDefFoundError:
> >> > >> >>>>>>>> com/google/common/cache/CacheLoader
> >> > >> >>>>>>>> at
> >> > >> >>>>>>>>
> >>org.apache.flex.compiler.clients.MXMLC.<init>(MXMLC.java:379)
> >> > >> >>>>>>>> at
> >>org.apache.flex.compiler.clients.COMPC.<init>(COMPC.java:54)
> >> > >> >>>>>>>> at
> >> > >> >>
> >> >
> >>>>org.apache.flex.compiler.clients.COMPC.staticMainNoExit(COMPC.java:75)
> >> > >> >>>>>>>> at
> >>org.apache.flex.compiler.clients.COMPC.main(COMPC.java:63)
> >> > >> >>>>>>>> Caused by: java.lang.ClassNotFoundException:
> >> > >> >>>>>>>> com.google.common.cache.CacheLoader
> >> > >> >>>>>>>> at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
> >> > >> >>>>>>>> at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
> >> > >> >>>>>>>> at java.security.AccessController.doPrivileged(Native
> >>Method)
> >> > >> >>>>>>>> at
> >>java.net.URLClassLoader.findClass(URLClassLoader.java:354)
> >> > >> >>>>>>>> at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
> >> > >> >>>>>>>> at
> >> > >> >>>>>>>>
> >>sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
> >> > >> >>>>>>>> at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
> >> > >> >>>>>>>> ... 4 more
> >> > >> >>>>>>>>
> >> > >> >>>>>>>> Thanks,
> >> > >> >>>>>>>> Frédéric THOMAS
> >> > >> >>>
> >> > >
> >> > >
> >> >
> >>
> >
>