Return-Path: X-Original-To: apmail-flex-commits-archive@www.apache.org Delivered-To: apmail-flex-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BD753113D9 for ; Tue, 22 Jul 2014 13:35:43 +0000 (UTC) Received: (qmail 47213 invoked by uid 500); 22 Jul 2014 13:35:29 -0000 Delivered-To: apmail-flex-commits-archive@flex.apache.org Received: (qmail 47155 invoked by uid 500); 22 Jul 2014 13:35:29 -0000 Mailing-List: contact commits-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list commits@flex.apache.org Received: (qmail 46301 invoked by uid 99); 22 Jul 2014 13:35:28 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Jul 2014 13:35:28 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5DB2C9AF231; Tue, 22 Jul 2014 13:35:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: cdutz@apache.org To: commits@flex.apache.org Date: Tue, 22 Jul 2014 13:36:02 -0000 Message-Id: <97c55f9e6e2643e9bc80b08bd2fba321@git.apache.org> In-Reply-To: <9b4488ac636245f08eb096463c80c652@git.apache.org> References: <9b4488ac636245f08eb096463c80c652@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [36/51] [partial] - Migrated the directory structure to a more Maven style structure. - Started migrating the Parser from Antlr2+3 and JFlex to Antlr4. http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingABCVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingABCVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingABCVisitor.java new file mode 100644 index 0000000..f82f1d1 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingABCVisitor.java @@ -0,0 +1,125 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.semantics.*; + +/** + * A DelegatingABCVisitor wraps another IABCVisitor and delegates actions to it. + * The DelegatingABCVisitor can be used as a base class for an application that + * needs to supplement the basic IABCVisitor's behavior, often by returning a + * visitor that, in turn, implements application-specific behavior. + */ +public class DelegatingABCVisitor implements IABCVisitor +{ + /** + * Construct a DelegatingABCVisitor. + * + * @param delegate - the IABCVisitor this visitor delegates to. + */ + public DelegatingABCVisitor(IABCVisitor delegate) + { + this.delegate = delegate; + } + + /** + * The backing (delegate) IABCVisitor. + */ + private IABCVisitor delegate; + + @Override + public void visit(int majorVersion, int minorVersion) + { + delegate.visit(majorVersion, minorVersion); + } + + @Override + public void visitEnd() + { + delegate.visitEnd(); + } + + @Override + public IScriptVisitor visitScript() + { + return delegate.visitScript(); + } + + @Override + public IClassVisitor visitClass(InstanceInfo iinfo, ClassInfo cinfo) + { + return delegate.visitClass(iinfo, cinfo); + } + + @Override + public IMethodVisitor visitMethod(MethodInfo minfo) + { + return delegate.visitMethod(minfo); + } + + @Override + public void visitPooledInt(Integer i) + { + delegate.visitPooledInt(i); + } + + @Override + public void visitPooledUInt(Long l) + { + delegate.visitPooledUInt(l); + } + + @Override + public void visitPooledDouble(Double d) + { + delegate.visitPooledDouble(d); + } + + @Override + public void visitPooledString(String s) + { + delegate.visitPooledString(s); + } + + @Override + public void visitPooledNamespace(Namespace ns) + { + delegate.visitPooledNamespace(ns); + } + + @Override + public void visitPooledNsSet(Nsset nss) + { + delegate.visitPooledNsSet(nss); + } + + @Override + public void visitPooledName(Name n) + { + delegate.visitPooledName(n); + } + + @Override + public void visitPooledMetadata(Metadata md) + { + delegate.visitPooledMetadata(md); + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingClassVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingClassVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingClassVisitor.java new file mode 100644 index 0000000..2d95ef8 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingClassVisitor.java @@ -0,0 +1,60 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + + +/** + * this class just passes all calls through to the delegate - used as a base + * class when you want to modify the behavior of some of the methods. + */ +public class DelegatingClassVisitor implements IClassVisitor +{ + public DelegatingClassVisitor(IClassVisitor delegate) + { + this.delegate = delegate; + } + + private IClassVisitor delegate; + + @Override + public void visit() + { + delegate.visit(); + } + + @Override + public void visitEnd() + { + delegate.visitEnd(); + } + + @Override + public ITraitsVisitor visitClassTraits() + { + return delegate.visitClassTraits(); + } + + @Override + public ITraitsVisitor visitInstanceTraits() + { + return delegate.visitInstanceTraits(); + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingMetadataVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingMetadataVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingMetadataVisitor.java new file mode 100644 index 0000000..3527914 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingMetadataVisitor.java @@ -0,0 +1,42 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.semantics.Metadata; + +/** + * this class just passes all calls through to the delegate - used as a base + * class when you want to modify the behavior of some of the methods. + */ +public class DelegatingMetadataVisitor implements IMetadataVisitor +{ + public DelegatingMetadataVisitor(IMetadataVisitor delegate) + { + this.delegate = delegate; + } + + private IMetadataVisitor delegate; + + @Override + public void visit(Metadata md) + { + delegate.visit(md); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingMethodBodyVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingMethodBodyVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingMethodBodyVisitor.java new file mode 100644 index 0000000..b67817e --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingMethodBodyVisitor.java @@ -0,0 +1,110 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.instructionlist.InstructionList; +import org.apache.flex.abc.semantics.Instruction; +import org.apache.flex.abc.semantics.Label; +import org.apache.flex.abc.semantics.Name; + +/** + * Base class for various method body visitors that wish to modify the method + * body this class just passes all calls through to the delegate + */ +public class DelegatingMethodBodyVisitor implements IMethodBodyVisitor +{ + public DelegatingMethodBodyVisitor(IMethodBodyVisitor delegate) + { + this.delegate = delegate; + } + + private final IMethodBodyVisitor delegate; + + @Override + public void visit() + { + delegate.visit(); + } + + @Override + public void visitEnd() + { + delegate.visitEnd(); + } + + @Override + public ITraitsVisitor visitTraits() + { + return delegate.visitTraits(); + } + + @Override + public void visitInstructionList(InstructionList new_list) + { + delegate.visitInstructionList(new_list); + } + + @Override + public void visitInstruction(int opcode) + { + delegate.visitInstruction(opcode); + } + + @Override + public void visitInstruction(int opcode, int immediate_operand) + { + delegate.visitInstruction(opcode, immediate_operand); + } + + @Override + public void visitInstruction(int opcode, Object[] operands) + { + delegate.visitInstruction(opcode, operands); + } + + @Override + public void visitInstruction(int opcode, Object single_operand) + { + delegate.visitInstruction(opcode, single_operand); + } + + public void visitInstruction(Instruction instruction) + { + delegate.visitInstruction(instruction); + } + + @Override + public int visitException(Label from, Label to, Label target, Name exception_type, Name catch_var) + { + return delegate.visitException(from, to, target, exception_type, catch_var); + } + + @Override + public void labelCurrent(Label l) + { + delegate.labelCurrent(l); + } + + @Override + public void labelNext(Label l) + { + delegate.labelNext(l); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingMethodVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingMethodVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingMethodVisitor.java new file mode 100644 index 0000000..b134ae9 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingMethodVisitor.java @@ -0,0 +1,54 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.semantics.MethodBodyInfo; + +/** + * this class just passes all calls through to the delegate - used as a base + * class when you want to modify the behavior of some of the methods. + */ +public class DelegatingMethodVisitor implements IMethodVisitor +{ + public DelegatingMethodVisitor(IMethodVisitor delegate) + { + this.delegate = delegate; + } + + private final IMethodVisitor delegate; + + @Override + public void visit() + { + delegate.visit(); + } + + @Override + public void visitEnd() + { + delegate.visitEnd(); + } + + @Override + public IMethodBodyVisitor visitBody(MethodBodyInfo mbi) + { + return delegate.visitBody(mbi); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingScriptVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingScriptVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingScriptVisitor.java new file mode 100644 index 0000000..01ea99c --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingScriptVisitor.java @@ -0,0 +1,60 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.semantics.MethodInfo; + +/** + * this class just passes all calls through to the delegate - used as a base + * class when you want to modify the behavior of some of the methods. + */ +public class DelegatingScriptVisitor implements IScriptVisitor +{ + public DelegatingScriptVisitor(IScriptVisitor delegate) + { + this.delegate = delegate; + } + + private IScriptVisitor delegate; + + @Override + public void visit() + { + delegate.visit(); + } + + @Override + public void visitEnd() + { + delegate.visitEnd(); + } + + @Override + public ITraitsVisitor visitTraits() + { + return delegate.visitTraits(); + } + + @Override + public void visitInit(MethodInfo methodInfo) + { + delegate.visitInit(methodInfo); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingTraitVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingTraitVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingTraitVisitor.java new file mode 100644 index 0000000..fc685cf --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingTraitVisitor.java @@ -0,0 +1,59 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + + +/** + * this class just passes all calls through to the delegate - used as a base + * class when you want to modify the behavior of some of the methods. + */ +public class DelegatingTraitVisitor implements ITraitVisitor +{ + public DelegatingTraitVisitor(ITraitVisitor delegate) + { + this.delegate = delegate; + } + + private ITraitVisitor delegate; + + @Override + public void visitStart() + { + delegate.visitStart(); + } + + @Override + public void visitEnd() + { + delegate.visitEnd(); + } + + @Override + public IMetadataVisitor visitMetadata(int count) + { + return delegate.visitMetadata(count); + } + + @Override + public void visitAttribute(String attrName, Object attrValue) + { + delegate.visitAttribute(attrName, attrValue); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingTraitsVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingTraitsVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingTraitsVisitor.java new file mode 100644 index 0000000..c033291 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/DelegatingTraitsVisitor.java @@ -0,0 +1,75 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.semantics.ClassInfo; +import org.apache.flex.abc.semantics.MethodInfo; +import org.apache.flex.abc.semantics.Name; +import org.apache.flex.abc.semantics.Traits; + +/** + * this class just passes all calls through to the delegate - used as a base + * class when you want to modify the behavior of some of the methods. + */ +public class DelegatingTraitsVisitor implements ITraitsVisitor +{ + public DelegatingTraitsVisitor(ITraitsVisitor delegate) + { + this.delegate = delegate; + } + + private ITraitsVisitor delegate; + + @Override + public void visit() + { + delegate.visit(); + } + + @Override + public void visitEnd() + { + delegate.visitEnd(); + } + + @Override + public Traits getTraits() + { + return delegate.getTraits(); + } + + @Override + public ITraitVisitor visitSlotTrait(int kind, Name name, int slotID, Name slotType, Object slotValue) + { + return delegate.visitSlotTrait(kind, name, slotID, slotType, slotValue); + } + + @Override + public ITraitVisitor visitClassTrait(int kind, Name name, int slotID, ClassInfo clazz) + { + return delegate.visitClassTrait(kind, name, slotID, clazz); + } + + @Override + public ITraitVisitor visitMethodTrait(int kind, Name name, int dispID, MethodInfo method) + { + return delegate.visitMethodTrait(kind, name, dispID, method); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/IABCVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/IABCVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/IABCVisitor.java new file mode 100644 index 0000000..d83730b --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/IABCVisitor.java @@ -0,0 +1,132 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.semantics.ClassInfo; +import org.apache.flex.abc.semantics.InstanceInfo; +import org.apache.flex.abc.semantics.Metadata; +import org.apache.flex.abc.semantics.MethodInfo; +import org.apache.flex.abc.semantics.Name; +import org.apache.flex.abc.semantics.Namespace; +import org.apache.flex.abc.semantics.Nsset; + +/** + * The IABCVisitor is the ABC program-level data sink and visitor generator. A + * program using the AET to construct an ABC program first instantiates an + * IABCVisitor implementation instance, usually + * org.apache.flex.abc.util.ABCEmitter, and get visitors for the classes, + * scripts, and other data elements in the ABC by calling the factory methods + * declared here. + */ +public interface IABCVisitor extends IVisitor +{ + void visit(int majorVersion, int minorVersion); + + /** + * Visit a script. + * + * @return the script's visitor. May be null if the script is not to be + * processed. + */ + IScriptVisitor visitScript(); + + /** + * Visit a class. + * + * @param iinfo - the class' instance info. + * @param cinfo - the class' class info. + * @return the class' visitor. May be null if the class is not to be + * processed. + */ + IClassVisitor visitClass(InstanceInfo iinfo, ClassInfo cinfo); + + /** + * Visit a method. + * + * @param minfo - the Method's method info. + * @return the method body visitor. May be null if the method is not to be + * processed. + */ + IMethodVisitor visitMethod(MethodInfo minfo); + + /** + * Visit a pooled integer value. + * + * @note values introduced as operands of instructions need not use this + * method. + */ + void visitPooledInt(Integer i); + + /** + * Visit a pooled unsigned integer value. + * + * @note values introduced as operands of instructions need not use this + * method. + */ + void visitPooledUInt(Long l); + + /** + * Visit a pooled double value. + * + * @note values introduced as operands of instructions need not use this + * method. + */ + void visitPooledDouble(Double d); + + /** + * Visit a pooled string value. + * + * @note values introduced as operands of instructions need not use this + * method. + */ + void visitPooledString(String s); + + /** + * Visit a pooled namespace value. + * + * @note values introduced as operands of instructions need not use this + * method. + */ + void visitPooledNamespace(Namespace ns); + + /** + * Visit a pooled namespace set value. + * + * @note values introduced as operands of instructions need not use this + * method. + */ + void visitPooledNsSet(Nsset nss); + + /** + * Visit a pooled name value. + * + * @note values introduced as operands of instructions need not use this + * method. + */ + void visitPooledName(Name n); + + /** + * Visit a pooled metadata value. + * + * @note values introduced as operands of instructions need not use this + * method. + */ + void visitPooledMetadata(Metadata md); +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/IClassVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/IClassVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/IClassVisitor.java new file mode 100644 index 0000000..e71db93 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/IClassVisitor.java @@ -0,0 +1,49 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +/** + * The IClassVisitor generates traits visitors for an ABC class' static and + * instance traits. + * + * @see org.apache.flex.abc.semantics.ClassInfo which holds the rest of the + * class' information. + */ +public interface IClassVisitor extends IVisitor +{ + /** + * Begin visiting a class. + */ + void visit(); + + /** + * Visit the class' static (class) traits. + * + * @return a ITraitsVisitor used to define the class' static traits. + */ + ITraitsVisitor visitClassTraits(); + + /** + * Visit the class' instance traits. + * + * @return a ITraitsVisitor used to define the class' instance traits. + */ + ITraitsVisitor visitInstanceTraits(); +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/IDiagnosticsVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/IDiagnosticsVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/IDiagnosticsVisitor.java new file mode 100644 index 0000000..b35f536 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/IDiagnosticsVisitor.java @@ -0,0 +1,118 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.ABCEmitter; +import org.apache.flex.abc.diagnostics.AbstractDiagnosticVisitor; +import org.apache.flex.abc.graph.IBasicBlock; +import org.apache.flex.abc.graph.IFlowgraph; +import org.apache.flex.abc.semantics.MethodBodyInfo; +import org.apache.flex.abc.semantics.MethodInfo; +import org.apache.flex.abc.semantics.ScriptInfo; + +/** + * IVisitor that is called by the {@link ABCEmitter} to notify clients of issues + * it encountered that will most likely cause the abc created by the + * {@link ABCEmitter} to fail verification in the VM. + *

+ * Clients should not directly implement this method unless absolutely + * necessary, instead the should sub-class {@link AbstractDiagnosticVisitor}. + * Methods may be added to this interface in future versions of the AET. + */ +public interface IDiagnosticsVisitor +{ + /** + * An underflow of operand stack was detected in a basic block in a method. + * + * @param methodBodyInfo {@link MethodBodyInfo} for the method body with the + * stack underflow. + * @param cfg {@link IFlowgraph} for the method body with the stack + * underflow. + * @param block {@link IBasicBlock} in the {@link IFlowgraph} that contains + * the stack underflow. + * @param instructionIndex The index of the instruction in the {@link IBasicBlock} + * that contains the stack underflow. + */ + void operandStackUnderflow(MethodBodyInfo methodBodyInfo, IFlowgraph cfg, IBasicBlock block, int instructionIndex); + + /** + * An underflow of scope stack was detected in a basic block in a method. + * + * @param methodBodyInfo {@link MethodBodyInfo} for the method body with the + * stack underflow. + * @param cfg {@link IFlowgraph} for the method body with the stack + * underflow. + * @param block {@link IBasicBlock} in the {@link IFlowgraph} that contains + * the stack underflow. + * @param instructionIndex The index of the instruction in the {@link IBasicBlock} + * that contains the stack underflow. + */ + void scopeStackUnderflow(MethodBodyInfo methodBodyInfo, IFlowgraph cfg, IBasicBlock block, int instructionIndex); + + /** + * A basic block in a method has been found to be unreachable. + * @param methodBodyInfo {@link MethodBodyInfo} for the method body + * with the unreachable block. + * @param cfg {@link IFlowgraph} for the method body with the + * unreachable block. + * @param block {@link IBasicBlock} in the {@link IFlowgraph} + * that contains the unreachable block. + */ + void unreachableBlock(MethodBodyInfo methodBodyInfo, IFlowgraph cfg, IBasicBlock block); + + /** + * A {@link MethodInfo} has too many default parameters. + * + * @param methodInfo The {@link MethodInfo} that has too many default + * parameters. + */ + void tooManyDefaultParameters(MethodInfo methodInfo); + + /** + * A {@link MethodInfo} has a different number of parameter names than + * parameter types. + * + * @param methodInfo The {@link MethodInfo} that has the incorrect number of + * parameter names. + */ + void incorrectNumberOfParameterNames(MethodInfo methodInfo); + + /** + * A {@link MethodInfo} for a native method also has an associated + * {@link MethodBodyInfo}. + * + * @param methodInfo The {@link MethodInfo} that is marked as a native + * method. + * @param methodBodyInfo The {@link MethodBodyInfo} associated with the + * native method. + */ + void nativeMethodWithMethodBody(MethodInfo methodInfo, MethodBodyInfo methodBodyInfo); + + /** + * A {@link MethodInfo} for the init method of a {@link ScriptInfo} has + * required arguments. + * + * @param scriptInfo The {@link ScriptInfo} whose init method has required + * arguments. + * @param methodInfo The {@link MethodInfo} for the init method of the + * specified {@link ScriptInfo}. + */ + void scriptInitWithRequiredArguments(ScriptInfo scriptInfo, MethodInfo methodInfo); +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/IFlowGraphVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/IFlowGraphVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/IFlowGraphVisitor.java new file mode 100644 index 0000000..3adca67 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/IFlowGraphVisitor.java @@ -0,0 +1,53 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.graph.IBasicBlock; +import org.apache.flex.abc.semantics.Instruction; + +/** + * A IFlowGraphVisitor defines the behavior of a visitor over a control flow + * graph. + */ +public interface IFlowGraphVisitor +{ + /** + * Visit a new Block. + * + * @param b - the Block to visit. + * @return true if the walker should continue visiting the block. + */ + boolean visitBlock(IBasicBlock b); + + /** + * Finish visiting a Block. + * + * @param b - the Block. It must be the same block last visited by + * visitBlock() where that call returned true. + */ + void visitEnd(IBasicBlock b); + + /** + * Visit an Instruction within the most recently-visited Block. + * + * @param insn - the Instruction. + */ + void visitInstruction(Instruction insn); +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/IMetadataVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/IMetadataVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/IMetadataVisitor.java new file mode 100644 index 0000000..9e13e98 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/IMetadataVisitor.java @@ -0,0 +1,37 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.semantics.Metadata; + +/** + * An IMetdataVisitor defines a trait's metadata. + * + * @see ITraitVisitor#visitMetadata + */ +public interface IMetadataVisitor +{ + /** + * Visit a metadata entry. + * + * @param md - the metadata. + */ + void visit(Metadata md); +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/IMethodBodyVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/IMethodBodyVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/IMethodBodyVisitor.java new file mode 100644 index 0000000..f3dcdf4 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/IMethodBodyVisitor.java @@ -0,0 +1,118 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.instructionlist.InstructionList; +import org.apache.flex.abc.semantics.Instruction; +import org.apache.flex.abc.semantics.Label; +import org.apache.flex.abc.semantics.Name; + +/** + * An IMethodBodyVisitor defines a method's local variables and ABC instructions. + */ +public interface IMethodBodyVisitor extends IVisitor +{ + /** + * Begin processing a method body. + */ + void visit(); + + /** + * Visit the method body's traits (local variables). + * + * @return a traits visitor, or null if the traits aren't of interest. + */ + ITraitsVisitor visitTraits(); + + /** + * Reset the method body's instruction list en bloc. + */ + void visitInstructionList(InstructionList newList); + + /** + * Visit an instruction with no operands. + * + * @param opcode - the instruction's opcode. + */ + void visitInstruction(int opcode); + + /** + * Visit an instruction with an immediate operand. + * + * @param opcode - the instruction's opcode. + * @param immediateOperand - the operand. + */ + void visitInstruction(int opcode, int immediateOperand); + + /** + * Visit an instruction. + * + * @param opcode - the instruction's opcode. + * @param operands - the instruction's operands. + */ + void visitInstruction(int opcode, Object[] operands); + + /** + * Visit an instruction with a single operand (convenience method). + * + * @param opcode - the instruction's opcode. + * @param singleOperand - the instruction's operand. + */ + void visitInstruction(int opcode, Object singleOperand); + + /** + * Vist an instruction + * + * @param instruction the Instruction to visit + */ + void visitInstruction(Instruction instruction); + + /** + * Visit an exception handler. + * + * @param from - the label that starts the "try" region. + * @param to - the label that ends the "try" region. + * @param target - the "catch" target. + * @param exceptionType - the type of exception to be handled. "*" is valid + * and handles any exception. + * @param catchVar - the name of the exception variable. May be null if no + * exception variable is desired. + * @return the exception's exception number. + */ + int visitException(Label from, Label to, Label target, Name exceptionType, Name catchVar); + + /** + * Bind a Label object (not to be confused with the AVM OP_label + * instruction) to the last-visited ABC instruction in this method. + * + * @pre visitInstruction() must have been called at least once, i.e., there + * must be a last-visited ABC instruction. + */ + void labelCurrent(Label l); + + /** + * Bind a Label object (not to be confused with the AVM OP_label + * instruction) to the next ABC instruction that gets visited in this method + * + * @pre visitInstruction() must be called at least once after labelNext, + * i.e., there must be a next instruction. + */ + void labelNext(Label l); +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/IMethodVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/IMethodVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/IMethodVisitor.java new file mode 100644 index 0000000..1e8d9be --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/IMethodVisitor.java @@ -0,0 +1,42 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.semantics.MethodBodyInfo; + +/** + * An IMethodVisitor begins definition of a method, and generates the + * corresponding IMethodBodyVisitor. + */ +public interface IMethodVisitor extends IVisitor +{ + /** + * Begin defining a method. + */ + void visit(); + + /** + * Generate a IMethodBodyVisitor. + * + * @param mbi - the method's MethodBodyInfo. + * @return the defining IMethodBodyVisitor. + */ + IMethodBodyVisitor visitBody(MethodBodyInfo mbi); +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/IScriptVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/IScriptVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/IScriptVisitor.java new file mode 100644 index 0000000..5fe14cd --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/IScriptVisitor.java @@ -0,0 +1,48 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.semantics.MethodInfo; + +/** + * An IScriptVisitor generates a visitor for the script's traits, and records the + * script's init method. + */ +public interface IScriptVisitor extends IVisitor +{ + /** + * Begin visiting the script. + */ + void visit(); + + /** + * Define the script's traits. + * + * @return the ITraitsVisitor that actually defines the traits. + */ + ITraitsVisitor visitTraits(); + + /** + * Declare the script's init routine. + * + * @param methodInfo - the MethodInfo of the init routine. + */ + void visitInit(MethodInfo methodInfo); +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/ITraitVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/ITraitVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/ITraitVisitor.java new file mode 100644 index 0000000..1a2e80f --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/ITraitVisitor.java @@ -0,0 +1,51 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +/** + * An ITraitVisitor generates a IMetadataVisitor to define a trait's metadata, and + * records name=value trait attributes. + */ +public interface ITraitVisitor extends IVisitor +{ + /** + * Start visiting trait. + */ + void visitStart(); + + /** + * Visit the trait's metadata. + * + * @param count number of metadata objects + * @return the IMetadataVisitor that will define the metadata. + */ + IMetadataVisitor visitMetadata(int count); + + /** + * Record a name=value trait attribute, e.g., + *

trait_visitor.visitAttribute(Trait.TRAIT_FINAL, Boolean.TRUE); + * + * @param attrName - the attribute's name. + * @param attrValue - the attribute's value. + * @note many attributes are enabled by their presence, value may not be + * checked. Refer to the AVM spec for information on a particular attribute. + */ + void visitAttribute(String attrName, Object attrValue); +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/ITraitsVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/ITraitsVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/ITraitsVisitor.java new file mode 100644 index 0000000..02bf6ae --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/ITraitsVisitor.java @@ -0,0 +1,73 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.semantics.ClassInfo; +import org.apache.flex.abc.semantics.MethodInfo; +import org.apache.flex.abc.semantics.Name; +import org.apache.flex.abc.semantics.Traits; + +/** + * An ITraitsVisitor defines the individual trait entries of a traits collection. + */ +public interface ITraitsVisitor extends IVisitor +{ + /** + * Slot ID 0 means "let the AVM pick a slot ID." + */ + static final int RUNTIME_SLOT = 0; + + /** + * disp_id ID 0 means "let the AVM pick a disp_id." + */ + static final int RUNTIME_DISP_ID = 0; + + /** + * Begin visiting traits. Calling the visitXTrait methods is undefined + * before visit() is called. + */ + void visit(); + + /** + * @return the visitor's traits (optional), or null. + */ + Traits getTraits(); + + /** + * Define a slot trait. + * + * @return a ITraitsVisitor, used to visit the trait's metadata. + */ + ITraitVisitor visitSlotTrait(int kind, Name name, int slotID, Name slotType, Object slotValue); + + /** + * Define a class trait. + * + * @return a ITraitsVisitor, used to visit the trait's metadata. + */ + ITraitVisitor visitClassTrait(int kind, Name name, int slotID, ClassInfo clazz); + + /** + * Define a method trait. + * + * @return a ITraitsVisitor, used to visit the trait's metadata. + */ + ITraitVisitor visitMethodTrait(int kind, Name name, int dispID, MethodInfo method); +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/IVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/IVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/IVisitor.java new file mode 100644 index 0000000..cebb1f0 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/IVisitor.java @@ -0,0 +1,37 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +/** + * Base interface for all visitors reachable from an {@link IABCVisitor}. + *

+ * Currently this interface exists so that clients can keep a collection of + * visitor's whose {@link #visitEnd()} methods need to be called at some point + * in the future. + */ +public interface IVisitor +{ + /** + * Indicates that no further method calls will be made on this visitor + * instance. Interfaces that derive from this interface add more specific + * meaning to this method. + */ + void visitEnd(); +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/NilABCVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/NilABCVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/NilABCVisitor.java new file mode 100644 index 0000000..70499d6 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/NilABCVisitor.java @@ -0,0 +1,102 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.semantics.ClassInfo; +import org.apache.flex.abc.semantics.InstanceInfo; +import org.apache.flex.abc.semantics.Metadata; +import org.apache.flex.abc.semantics.MethodInfo; +import org.apache.flex.abc.semantics.Name; +import org.apache.flex.abc.semantics.Namespace; +import org.apache.flex.abc.semantics.Nsset; + +/** + * An IABCVisitor that ignores its input as far as possible. + */ +public class NilABCVisitor implements IABCVisitor +{ + @Override + public void visit(int majorVersion, int minorVersion) + { + } + + @Override + public void visitEnd() + { + } + + @Override + public IScriptVisitor visitScript() + { + return NilVisitors.NIL_SCRIPT_VISITOR; + } + + @Override + public IClassVisitor visitClass(InstanceInfo iinfo, ClassInfo cinfo) + { + return NilVisitors.NIL_CLASS_VISITOR; + } + + @Override + public IMethodVisitor visitMethod(MethodInfo minfo) + { + return NilVisitors.NIL_METHOD_VISITOR; + } + + @Override + public void visitPooledInt(Integer i) + { + } + + @Override + public void visitPooledUInt(Long l) + { + } + + @Override + public void visitPooledDouble(Double d) + { + } + + @Override + public void visitPooledString(String s) + { + } + + @Override + public void visitPooledNamespace(Namespace ns) + { + } + + @Override + public void visitPooledNsSet(Nsset nss) + { + } + + @Override + public void visitPooledName(Name n) + { + } + + @Override + public void visitPooledMetadata(Metadata md) + { + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/NilClassVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/NilClassVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/NilClassVisitor.java new file mode 100644 index 0000000..26ab3b1 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/NilClassVisitor.java @@ -0,0 +1,48 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +/** + * An IClassVisitor that ignores its input as far as possible. + */ +public class NilClassVisitor implements IClassVisitor +{ + @Override + public void visit() + { + } + + @Override + public void visitEnd() + { + } + + @Override + public ITraitsVisitor visitClassTraits() + { + return NilVisitors.NIL_TRAITS_VISITOR; + } + + @Override + public ITraitsVisitor visitInstanceTraits() + { + return NilVisitors.NIL_TRAITS_VISITOR; + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/NilDiagnosticsVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/NilDiagnosticsVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/NilDiagnosticsVisitor.java new file mode 100644 index 0000000..e9ac1fa --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/NilDiagnosticsVisitor.java @@ -0,0 +1,32 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.diagnostics.AbstractDiagnosticVisitor; + +/** + * Nil implementation of {@link IDiagnosticsVisitor}. + */ +public final class NilDiagnosticsVisitor extends AbstractDiagnosticVisitor +{ + public NilDiagnosticsVisitor() + { + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/NilMetadataVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/NilMetadataVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/NilMetadataVisitor.java new file mode 100644 index 0000000..3b4f881 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/NilMetadataVisitor.java @@ -0,0 +1,33 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.semantics.Metadata; + +/** + * An IMetadataVisitor that ignores its input as far as possible. + */ +public class NilMetadataVisitor implements IMetadataVisitor +{ + @Override + public void visit(Metadata md) + { + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/NilMethodBodyVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/NilMethodBodyVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/NilMethodBodyVisitor.java new file mode 100644 index 0000000..57572b0 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/NilMethodBodyVisitor.java @@ -0,0 +1,97 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.instructionlist.InstructionList; +import org.apache.flex.abc.semantics.Instruction; +import org.apache.flex.abc.semantics.Label; +import org.apache.flex.abc.semantics.Name; + +/** + * An IMethodBodyVisitor that ignores its input as far as possible. + */ +public class NilMethodBodyVisitor implements IMethodBodyVisitor +{ + @Override + public ITraitsVisitor visitTraits() + { + return NilVisitors.NIL_TRAITS_VISITOR; + } + + @Override + public void visitInstructionList(InstructionList new_list) + { + } + + @Override + public void visitInstruction(int opcode, Object single_operand) + { + + } + + public void visitInstruction(Instruction instruction) + { + + } + + @Override + public void visitInstruction(int opcode, Object[] operands) + { + + } + + @Override + public void visitInstruction(int opcode, int immediate_operand) + { + + } + + @Override + public void visitInstruction(int opcode) + { + + } + + @Override + public int visitException(Label from, Label to, Label target, Name exception_type, Name catch_var) + { + throw new IllegalStateException("Must implement this method and return a valid exception number."); + } + + @Override + public void visitEnd() + { + } + + @Override + public void visit() + { + } + + @Override + public void labelCurrent(Label l) + { + } + + @Override + public void labelNext(Label l) + { + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/NilMethodVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/NilMethodVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/NilMethodVisitor.java new file mode 100644 index 0000000..8adea94 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/NilMethodVisitor.java @@ -0,0 +1,44 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.semantics.MethodBodyInfo; + +/** + * An IMethodVisitor that ignores its input as far as possible. + */ +public class NilMethodVisitor implements IMethodVisitor +{ + @Override + public void visit() + { + } + + @Override + public void visitEnd() + { + } + + @Override + public IMethodBodyVisitor visitBody(MethodBodyInfo mbi) + { + return NilVisitors.NIL_METHOD_BODY_VISITOR; + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/NilScriptVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/NilScriptVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/NilScriptVisitor.java new file mode 100644 index 0000000..838144b --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/NilScriptVisitor.java @@ -0,0 +1,49 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.semantics.MethodInfo; + +/** + * An IScriptVisitor that ignores its input as far as possible. + */ +public class NilScriptVisitor implements IScriptVisitor +{ + @Override + public void visit() + { + } + + @Override + public void visitEnd() + { + } + + @Override + public ITraitsVisitor visitTraits() + { + return NilVisitors.NIL_TRAITS_VISITOR; + } + + @Override + public void visitInit(MethodInfo methodInfo) + { + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/NilTraitVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/NilTraitVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/NilTraitVisitor.java new file mode 100644 index 0000000..2501343 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/NilTraitVisitor.java @@ -0,0 +1,47 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +/** + * An ITraitVisitor that ignores its input as far as possible. + */ +public class NilTraitVisitor implements ITraitVisitor +{ + @Override + public void visitStart() + { + } + + @Override + public void visitEnd() + { + } + + @Override + public IMetadataVisitor visitMetadata(int count) + { + return NilVisitors.NIL_METADATA_VISITOR; + } + + @Override + public void visitAttribute(String attrName, Object attrValue) + { + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/NilTraitsVisitor.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/NilTraitsVisitor.java b/compiler/src/main/java/org/apache/flex/abc/visitors/NilTraitsVisitor.java new file mode 100644 index 0000000..02b431b --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/NilTraitsVisitor.java @@ -0,0 +1,65 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + +import org.apache.flex.abc.semantics.ClassInfo; +import org.apache.flex.abc.semantics.MethodInfo; +import org.apache.flex.abc.semantics.Name; +import org.apache.flex.abc.semantics.Traits; + +/** + * An ITraitsVisitor that ignores its input as far as possible. + */ +public class NilTraitsVisitor implements ITraitsVisitor +{ + @Override + public void visit() + { + } + + @Override + public void visitEnd() + { + } + + @Override + public Traits getTraits() + { + return null; + } + + @Override + public ITraitVisitor visitClassTrait(int kind, Name name, int slotId, ClassInfo clazz) + { + return NilVisitors.NIL_TRAIT_VISITOR; + } + + @Override + public ITraitVisitor visitMethodTrait(int kind, Name name, int dispId, MethodInfo method) + { + return NilVisitors.NIL_TRAIT_VISITOR; + } + + @Override + public ITraitVisitor visitSlotTrait(int kind, Name name, int slotId, Name slotType, Object slotValue) + { + return NilVisitors.NIL_TRAIT_VISITOR; + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/NilVisitors.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/NilVisitors.java b/compiler/src/main/java/org/apache/flex/abc/visitors/NilVisitors.java new file mode 100644 index 0000000..0f0fd88 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/NilVisitors.java @@ -0,0 +1,74 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.abc.visitors; + + +/** + * A set of singleton visitors that ignore their input + * as far as possible. + */ +public class NilVisitors +{ + /** + * Nil {@code IScriptVisitor}. + */ + public static final IScriptVisitor NIL_SCRIPT_VISITOR = new NilScriptVisitor(); + + /** + * Nil {@code IClassVisitor}. + */ + public static final IClassVisitor NIL_CLASS_VISITOR = new NilClassVisitor(); + + /** + * Nil {@code IMethodBodyVisitor}. + */ + public static final IMethodBodyVisitor NIL_METHOD_BODY_VISITOR = new NilMethodBodyVisitor(); + + /** + * Nil {@code IMethodVisitor}. + */ + public static final IMethodVisitor NIL_METHOD_VISITOR = new NilMethodVisitor(); + + /** + * Nil {@code IABCVisitor}. + */ + public static final IABCVisitor NIL_ABC_VISITOR = new NilABCVisitor(); + + /** + * Nil {@code ITraitsVisitor}; + */ + public static final ITraitsVisitor NIL_TRAITS_VISITOR = new NilTraitsVisitor(); + + /** + * Nil {@code ITraitVisitor}; + */ + public static final ITraitVisitor NIL_TRAIT_VISITOR = new NilTraitVisitor(); + + /** + * Nil {@code IMetadataVisitor}; + */ + public static final IMetadataVisitor NIL_METADATA_VISITOR = new NilMetadataVisitor(); + + /** + * Nil {@code IDiagnosticsVisitor} + */ + public static final IDiagnosticsVisitor NIL_DIAGNOSTICS_VISITOR = new NilDiagnosticsVisitor(); + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/abc/visitors/package.html ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/abc/visitors/package.html b/compiler/src/main/java/org/apache/flex/abc/visitors/package.html new file mode 100644 index 0000000..5eed182 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/abc/visitors/package.html @@ -0,0 +1,33 @@ + + + + + +This package contains the most basic model of ABC, which uses visitors. + +

It consists of a set of visitors that accept data from a source, +usually a client compiler or an ABCParser, +and transmit the data to a sink, +usually a static analysis program or an ABCEmitter. +

+ + + + http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/compiler/Messages.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/compiler/Messages.java b/compiler/src/main/java/org/apache/flex/compiler/Messages.java new file mode 100644 index 0000000..4479871 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/compiler/Messages.java @@ -0,0 +1,104 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.flex.compiler; + +import java.util.Locale; +import java.util.Map; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +import org.apache.flex.compiler.clients.problems.ProblemFormatter; + +/** + * Class to look up messages for the compiler client classes. This class looks + * up strings from a well known bundle. The locale can be modified by the client + * to display messages in a non-default locale. See the -tools-locale option. + */ +public final class Messages +{ + private static final String BUNDLE_NAME = "org.apache.flex.compiler.messages"; + + private static ResourceBundle resourceBundle; + private static Locale locale; + + + /** + * Get a localized string for the message id. + * + * @param id the id of the message. + * @return localized string. + */ + public static String getString(String id) + { + String message = null; + + try + { + message = getBundle().getString(id); + } + catch (MissingResourceException e) + { + // ignore exception + } + + return message; + } + + /** + * Get a localized string for a parameterized message. + * + * @param id the id of the message. + * @param parameters map that contains key/value pairs used to resolve the + * tokens in the specified message. + * @return resolved, token-free message + */ + public static String getString(String id, Map parameters) + { + return ProblemFormatter.substitute(getString(id), parameters); + } + + public static void setLocale(Locale locale) + { + Messages.locale = locale; + } + + protected static ResourceBundle getBundle() + { + try + { + if (resourceBundle == null) + { + Locale locale = Messages.locale; + if (locale == null) + locale = Locale.getDefault(); + + resourceBundle = ResourceBundle.getBundle(BUNDLE_NAME, locale); + } + } + catch (MissingResourceException e) + { + // fallback to english. + resourceBundle = ResourceBundle.getBundle(BUNDLE_NAME, Locale.ENGLISH); + } + + return resourceBundle; + } + +}