This is an automated email from the ASF dual-hosted git repository. joshtynjala pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
commit c3e54038313623d49f762d4aefa25ee91dbaea21 Author: Josh Tynjala <[email protected]> AuthorDate: Mon Nov 13 11:41:08 2023 -0800 remove obsolete AMD backend --- .../apache/royale/compiler/clients/ASDOCJSC.java | 4 - .../apache/royale/compiler/clients/MXMLJSC.java | 1 - .../compiler/codegen/js/amd/IJSAMDDocEmitter.java | 40 - .../compiler/codegen/js/amd/IJSAMDEmitter.java | 33 - .../internal/codegen/js/amd/ExportWriter.java | 230 ----- .../internal/codegen/js/amd/JSAMDDocEmitter.java | 37 - .../internal/codegen/js/amd/JSAMDEmitter.java | 971 --------------------- .../codegen/js/amd/JSAMDEmitterTokens.java | 38 - .../internal/codegen/js/amd/TempTools.java | 451 ---------- .../internal/driver/js/amd/AMDBackend.java | 53 -- .../internal/codegen/js/amd/TestAMDClassA.java | 181 ---- .../internal/codegen/js/amd/TestAMDClassB.java | 97 -- .../internal/codegen/js/amd/TestAMDEmitter.java | 144 --- .../internal/codegen/js/amd/TestAMDInterfaceI.java | 51 -- .../codegen/js/amd/TestAMDInterfaceIOther.java | 51 -- .../codegen/js/amd/TestAMDInterfaceISub.java | 52 -- .../internal/codegen/js/amd/TestAMDPackage.java | 127 --- .../royale/compiler/internal/test/AMDTestBase.java | 149 ---- 18 files changed, 2710 deletions(-) diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/ASDOCJSC.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/ASDOCJSC.java index e720cc3d2..43d4cf076 100644 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/ASDOCJSC.java +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/ASDOCJSC.java @@ -39,7 +39,6 @@ import org.apache.royale.compiler.exceptions.ConfigurationException; import org.apache.royale.compiler.exceptions.ConfigurationException.IOError; import org.apache.royale.compiler.exceptions.ConfigurationException.MustSpecifyTarget; import org.apache.royale.compiler.internal.driver.as.ASBackend; -import org.apache.royale.compiler.internal.driver.js.amd.AMDBackend; import org.apache.royale.compiler.internal.driver.js.goog.ASDocConfiguration; import org.apache.royale.compiler.internal.driver.js.goog.GoogBackend; import org.apache.royale.compiler.internal.driver.mxml.royale.MXMLRoyaleASDocBackend; @@ -132,9 +131,6 @@ public class ASDOCJSC extends MXMLJSCRoyale switch (jsOutputType) { - case AMD: - backend = new AMDBackend(); - break; case JSC: backend = new MXMLJSCJSSWCBackend(); diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java index f56a6f096..00fa05faa 100644 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java @@ -91,7 +91,6 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider, */ public enum JSOutputType { - AMD("amd"), ROYALE("royale"), GOOG("goog"), ROYALE_DUAL("royale_dual"), diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/js/amd/IJSAMDDocEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/js/amd/IJSAMDDocEmitter.java deleted file mode 100644 index 860991472..000000000 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/js/amd/IJSAMDDocEmitter.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * 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.royale.compiler.codegen.js.amd; - -import org.apache.royale.compiler.codegen.js.IJSDocEmitter; - -/** - * The {@link IJSAMDDocEmitter} interface allows the abstraction of JavaScript - * document comments to be emitted per tag. - * <p> - * The purpose of the API is to clamp emitted output to JavaScript doc tags. The - * output can be multiline but is specific to one tag. This allows a full - * comment to be created without worrying about how to assemble the tags. - * <p> - * TODO (mschmalle) Might make a comment API and tag API so comments are not - * dependent on tag creation IE IJSDocEmitter and IJSDocTagEmitter - * - * @author Michael Schmalle - */ -public interface IJSAMDDocEmitter extends IJSDocEmitter -{ - -} diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/js/amd/IJSAMDEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/js/amd/IJSAMDEmitter.java deleted file mode 100644 index b088e31cf..000000000 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/js/amd/IJSAMDEmitter.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * - * 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.royale.compiler.codegen.js.amd; - -import org.apache.royale.compiler.codegen.js.IJSEmitter; - -/** - * The {@link IJSAMDEmitter} interface allows abstraction between the base - * JavaScript and the AMD specific IJSAMDEmitter. - * - * @author Michael Schmalle - */ -public interface IJSAMDEmitter extends IJSEmitter -{ - -} diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/amd/ExportWriter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/amd/ExportWriter.java deleted file mode 100644 index c0f72aff4..000000000 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/amd/ExportWriter.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * - * 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.royale.compiler.internal.codegen.js.amd; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.apache.royale.compiler.definitions.ITypeDefinition; - -/** - * @author Michael Schmalle - */ -public class ExportWriter -{ - private static final String CLASSES_TYPES = "__CLASSES$TYPES__"; - - private static final String CLASSES_STRINGS = "__CLASSES$STRINGS__"; - - private static final String RUNTIME_TYPES = "__RUNTIME$TYPES__"; - - private static final String RUNTIME_STRINGS = "__RUNTIME$STRINGS__"; - - private final JSAMDEmitter emitter; - - private List<Dependency> runtime = new ArrayList<Dependency>(); - - private List<Dependency> types = new ArrayList<Dependency>(); - - public ExportWriter(JSAMDEmitter emitter) - { - this.emitter = emitter; - } - - public void queueExports(ITypeDefinition type, boolean outputString) - { - if (outputString) - { - emitter.write("["); - emitter.write("\"exports\""); - } - - emitter.write(", "); - - if (outputString) - emitter.write(RUNTIME_STRINGS); - else - emitter.write(RUNTIME_TYPES); - - //emitter.write(", "); - - if (outputString) - emitter.write(CLASSES_STRINGS); - else - emitter.write(CLASSES_TYPES); - - if (outputString) - { - emitter.write("]"); - } - } - - public void writeExports(ITypeDefinition type, boolean outputString) - { - StringBuilder sb = new StringBuilder(); - - int i = 0; - int len = runtime.size(); - - for (Dependency dependency : runtime) - { - sb.append(dependency.output(outputString, "runtime", outputString)); - - if (i < len - 1) - sb.append(", "); - i++; - } - - if (outputString) - { - int start = emitter.builder().indexOf(RUNTIME_STRINGS); - int end = start + RUNTIME_STRINGS.length(); - emitter.builder().replace(start, end, sb.toString()); - } - else - { - int start = emitter.builder().indexOf(RUNTIME_TYPES); - int end = start + RUNTIME_TYPES.length(); - emitter.builder().replace(start, end, sb.toString()); - } - - sb = new StringBuilder(); - - i = 0; - len = types.size(); - if (len > 0) - sb.append(", "); // trailing comma - - for (Dependency dependency : types) - { - sb.append(dependency.output(outputString, "classes", outputString)); - - if (i < len - 1) - sb.append(", "); - i++; - } - - if (outputString) - { - int start = emitter.builder().indexOf(CLASSES_STRINGS); - int end = start + CLASSES_STRINGS.length(); - emitter.builder().replace(start, end, sb.toString()); - } - else - { - int start = emitter.builder().indexOf(CLASSES_TYPES); - int end = start + CLASSES_TYPES.length(); - emitter.builder().replace(start, end, sb.toString()); - } - } - - void addImports(ITypeDefinition type) - { - Collection<String> imports = new ArrayList<String>(); - type.getContainedScope().getScopeNode().getAllImports(imports); - for (String imp : imports) - { - String name = toBaseName(imp); - if (!isExcludedImport(imp)) - addDependency(name, imp, false, false); - } - } - - void addFrameworkDependencies() - { - runtime.add(new Dependency("AS3", "AS3", false, false)); - } - - protected boolean isExcludedImport(String imp) - { - return imp.startsWith("__AS3__"); - } - - public void addDependency(String baseName, String qualifiedName, - boolean isNative, boolean isPlugin) - { - types.add(new Dependency(baseName, qualifiedName, isNative, isPlugin)); - } - - static String toBaseName(String name) - { - if (!name.contains(".")) - return name; - final String basename = name.substring(name.lastIndexOf(".") + 1); - return basename; - } - - static class Dependency - { - private final String baseName; - - private final String qualifiedName; - - public String getQualifiedName() - { - return qualifiedName; - } - - private final boolean isNative; - - public boolean isNative() - { - return isNative; - } - - @SuppressWarnings("unused") - private final boolean isPlugin; - - public Dependency(String baseName, String qualifiedName, - boolean isNative, boolean isPlugin) - { - this.baseName = baseName; - this.qualifiedName = qualifiedName; - this.isNative = isNative; - this.isPlugin = isPlugin; - } - - @Override - public String toString() - { - return qualifiedName; // TODO (mschmalle|AMD) native - } - - public String output(boolean outputString, String base, - boolean qualified) - { - StringBuilder sb = new StringBuilder(); - if (outputString) - { - sb.append("\"" + base + "/" - + qualifiedName.replaceAll("\\.", "/") + "\""); - } - else - { - if (qualified) - sb.append(qualifiedName); - else - sb.append(baseName); - } - return sb.toString(); - } - } -} diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/amd/JSAMDDocEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/amd/JSAMDDocEmitter.java deleted file mode 100644 index 70e390678..000000000 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/amd/JSAMDDocEmitter.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * - * 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.royale.compiler.internal.codegen.js.amd; - -import org.apache.royale.compiler.codegen.js.IJSEmitter; -import org.apache.royale.compiler.codegen.js.amd.IJSAMDDocEmitter; -import org.apache.royale.compiler.internal.codegen.js.JSDocEmitter; - -/** - * @author Michael Schmalle - */ -public class JSAMDDocEmitter extends JSDocEmitter implements IJSAMDDocEmitter -{ - - public JSAMDDocEmitter(IJSEmitter emitter) - { - super(emitter); - } - -} diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/amd/JSAMDEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/amd/JSAMDEmitter.java deleted file mode 100644 index e9413b4cb..000000000 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/amd/JSAMDEmitter.java +++ /dev/null @@ -1,971 +0,0 @@ -/* - * - * 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.royale.compiler.internal.codegen.js.amd; - -import java.io.FilterWriter; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.royale.compiler.codegen.js.amd.IJSAMDDocEmitter; -import org.apache.royale.compiler.codegen.js.amd.IJSAMDEmitter; -import org.apache.royale.compiler.definitions.IAccessorDefinition; -import org.apache.royale.compiler.definitions.IClassDefinition; -import org.apache.royale.compiler.definitions.IConstantDefinition; -import org.apache.royale.compiler.definitions.IDefinition; -import org.apache.royale.compiler.definitions.IFunctionDefinition; -import org.apache.royale.compiler.definitions.IInterfaceDefinition; -import org.apache.royale.compiler.definitions.IPackageDefinition; -import org.apache.royale.compiler.definitions.ITypeDefinition; -import org.apache.royale.compiler.definitions.IVariableDefinition; -import org.apache.royale.compiler.definitions.references.IReference; -import org.apache.royale.compiler.internal.codegen.as.ASEmitterTokens; -import org.apache.royale.compiler.internal.codegen.js.JSEmitter; -import org.apache.royale.compiler.internal.codegen.js.JSEmitterTokens; -import org.apache.royale.compiler.internal.codegen.js.utils.EmitterUtils; -import org.apache.royale.compiler.internal.definitions.ClassTraitsDefinition; -import org.apache.royale.compiler.internal.tree.as.FunctionCallNode; -import org.apache.royale.compiler.internal.tree.as.FunctionNode; -import org.apache.royale.compiler.internal.tree.as.IdentifierNode; -import org.apache.royale.compiler.problems.ICompilerProblem; -import org.apache.royale.compiler.projects.ICompilerProject; -import org.apache.royale.compiler.scopes.IASScope; -import org.apache.royale.compiler.tree.ASTNodeID; -import org.apache.royale.compiler.tree.as.IASNode; -import org.apache.royale.compiler.tree.as.IAccessorNode; -import org.apache.royale.compiler.tree.as.IBlockNode; -import org.apache.royale.compiler.tree.as.IClassNode; -import org.apache.royale.compiler.tree.as.IContainerNode; -import org.apache.royale.compiler.tree.as.IDefinitionNode; -import org.apache.royale.compiler.tree.as.IExpressionNode; -import org.apache.royale.compiler.tree.as.IFunctionCallNode; -import org.apache.royale.compiler.tree.as.IFunctionNode; -import org.apache.royale.compiler.tree.as.IGetterNode; -import org.apache.royale.compiler.tree.as.IIdentifierNode; -import org.apache.royale.compiler.tree.as.IInterfaceNode; -import org.apache.royale.compiler.tree.as.ILanguageIdentifierNode; -import org.apache.royale.compiler.tree.as.IMemberAccessExpressionNode; -import org.apache.royale.compiler.tree.as.IParameterNode; -import org.apache.royale.compiler.tree.as.ISetterNode; -import org.apache.royale.compiler.tree.as.ITypeNode; -import org.apache.royale.compiler.tree.as.IVariableNode; -import org.apache.royale.compiler.utils.NativeUtils; - -/** - * Concrete implementation of the 'AMD' JavaScript production. - * - * @author Michael Schmalle - */ -public class JSAMDEmitter extends JSEmitter implements IJSAMDEmitter -{ - - private Map<String, IDefinitionNode> foundAccessors = new HashMap<String, IDefinitionNode>(); - - private int inheritenceLevel = -1; - - private ExportWriter exportWriter; - - private boolean initializingFieldsInConstructor; - - private List<IDefinition> baseClassCalls = new ArrayList<IDefinition>(); - - StringBuilder builder() - { - return getBuilder(); - } - - IJSAMDDocEmitter getDoc() - { - return (IJSAMDDocEmitter) getDocEmitter(); - } - - public JSAMDEmitter(FilterWriter out) - { - super(out); - - exportWriter = new ExportWriter(this); - } - - @Override - public void emitPackageHeader(IPackageDefinition definition) - { - // TODO (mschmalle|AMD) this is a hack but I know no other way to do replacements in a Writer - setBufferWrite(true); - - write(JSAMDEmitterTokens.DEFINE); - write(ASEmitterTokens.PAREN_OPEN); - - IASScope containedScope = definition.getContainedScope(); - ITypeDefinition type = findType(containedScope.getAllLocalDefinitions()); - if (type == null) - return; - - exportWriter.addFrameworkDependencies(); - exportWriter.addImports(type); - - exportWriter.queueExports(type, true); - - writeToken(ASEmitterTokens.COMMA); - } - - @Override - public void emitPackageHeaderContents(IPackageDefinition definition) - { - // nothing - } - - @Override - public void emitPackageContents(IPackageDefinition definition) - { - IASScope containedScope = definition.getContainedScope(); - ITypeDefinition type = findType(containedScope.getAllLocalDefinitions()); - if (type == null) - return; - - write("function($exports"); - - exportWriter.queueExports(type, false); - - write(") {"); - indentPush(); - writeNewline(); - write("\"use strict\"; "); - writeNewline(); - - ITypeNode tnode = findTypeNode(definition.getNode()); - if (tnode != null) - { - getWalker().walk(tnode); // IClassNode | IInterfaceNode - } - - indentPop(); - writeNewline(); - write("}"); // end returned function - } - - @Override - public void emitPackageFooter(IPackageDefinition definition) - { - IASScope containedScope = definition.getContainedScope(); - ITypeDefinition type = findType(containedScope.getAllLocalDefinitions()); - if (type == null) - return; - - exportWriter.writeExports(type, true); - exportWriter.writeExports(type, false); - - write(");"); // end define() - - // flush the buffer, writes the builder to out - flushBuilder(); - } - - private void emitConstructor(IFunctionNode node) - { - FunctionNode fn = (FunctionNode) node; - fn.parseFunctionBody(getProblems()); - - //IFunctionDefinition definition = node.getDefinition(); - - write("function "); - write(node.getName()); - emitParameters(node.getParametersContainerNode()); - if (!isImplicit((IContainerNode) node.getScopedNode())) - { - emitMethodScope(node.getScopedNode()); - } - else - { - // we have a synthesized constructor, implict - } - } - - @Override - public void emitInterface(IInterfaceNode node) - { - final IInterfaceDefinition definition = node.getDefinition(); - final String interfaceName = definition.getBaseName(); - - write("AS3.interface_($exports, {"); - indentPush(); - writeNewline(); - - write("package_: \""); - write(definition.getPackageName()); - write("\","); - writeNewline(); - - write("interface_: \""); - write(interfaceName); - write("\""); - - IReference[] references = definition.getExtendedInterfaceReferences(); - final int len = references.length; - if (len > 0) - { - writeNewline(); - write("extends_: ["); - indentPush(); - writeNewline(); - int i = 0; - for (IReference reference : references) - { - write(reference.getName()); - if (i < len - 1) - { - write(","); - writeNewline(); - } - i++; - } - indentPop(); - writeNewline(); - write("]"); - } - - indentPop(); - writeNewline(); - write("});"); // end compilation unit - } - - @Override - public void emitClass(IClassNode node) - { - //ICompilerProject project = getWalker().getProject(); - - IClassDefinition definition = node.getDefinition(); - getModel().setCurrentClass(definition); - - final String className = definition.getBaseName(); - - write("AS3.compilationUnit($exports, function($primaryDeclaration){"); - indentPush(); - writeNewline(); - - // write constructor - emitConstructor((IFunctionNode) definition.getConstructor().getNode()); - writeNewline(); - - // base class - IReference baseClassReference = definition.getBaseClassReference(); - boolean hasSuper = baseClassReference != null - && !baseClassReference.getName().equals("Object"); - if (hasSuper) - { - String baseName = baseClassReference.getName(); - write("var Super = (" + baseName + "._ || " + baseName - + "._$get());"); - writeNewline(); - write("var super$ = Super.prototype;"); - writeNewline(); - } - - write("$primaryDeclaration(AS3.class_({"); - indentPush(); - writeNewline(); - - // write out package - write("package_: \"" + definition.getPackageName() + "\","); - writeNewline(); - // write class - write("class_: \"" + definition.getBaseName() + "\","); - writeNewline(); - if (hasSuper) - { - write("extends_: Super,"); - writeNewline(); - } - - IReference[] references = definition - .getImplementedInterfaceReferences(); - int len = references.length; - - // write implements - write("implements_:"); - write(" ["); - - if (len > 0) - { - indentPush(); - writeNewline(); - } - - int i = 0; - for (IReference reference : references) - { - write(reference.getName()); - exportWriter.addDependency(reference.getName(), - reference.getDisplayString(), false, false); - if (i < len - 1) - { - write(","); - writeNewline(); - } - i++; - } - - if (len > 0) - { - indentPop(); - writeNewline(); - } - - write("],"); - writeNewline(); - - // write members - final IDefinitionNode[] members = node.getAllMemberNodes(); - - write("members: {"); - - indentPush(); - writeNewline(); - - // constructor - write("constructor: " + className); - if (members.length > 0) - { - write(","); - writeNewline(); - } - - List<IDefinitionNode> instanceMembers = new ArrayList<IDefinitionNode>(); - List<IDefinitionNode> staticMembers = new ArrayList<IDefinitionNode>(); - List<IASNode> staticStatements = new ArrayList<IASNode>(); - - TempTools.fillInstanceMembers(members, instanceMembers); - TempTools.fillStaticMembers(members, staticMembers, true, false); - TempTools.fillStaticStatements(node, staticStatements, false); - - len = instanceMembers.size(); - i = 0; - for (IDefinitionNode mnode : instanceMembers) - { - if (mnode instanceof IAccessorNode) - { - if (foundAccessors.containsKey(mnode.getName())) - { - len--; - continue; - } - - getWalker().walk(mnode); - } - else if (mnode instanceof IFunctionNode) - { - getWalker().walk(mnode); - } - else if (mnode instanceof IVariableNode) - { - getWalker().walk(mnode); - } - else - { - write(mnode.getName()); - } - - if (i < len - 1) - { - write(","); - writeNewline(); - } - i++; - } - - // base class super calls - len = baseClassCalls.size(); - i = 0; - if (len > 0) - { - write(","); - writeNewline(); - } - - for (IDefinition baseCall : baseClassCalls) - { - write(baseCall.getBaseName() + "$" + inheritenceLevel + ": super$." - + baseCall.getBaseName()); - - if (i < len - 1) - { - write(","); - writeNewline(); - } - } - - // end members - indentPop(); - writeNewline(); - write("},"); - writeNewline(); - - len = staticMembers.size(); - - write("staticMembers: {"); - - indentPush(); - writeNewline(); - - i = 0; - for (IDefinitionNode mnode : staticMembers) - { - if (mnode instanceof IAccessorNode) - { - // TODO (mschmalle|AMD) havn't taken care of static accessors - if (foundAccessors.containsKey(mnode.getName())) - continue; - - foundAccessors.put(mnode.getName(), mnode); - - getWalker().walk(mnode); - } - else if (mnode instanceof IFunctionNode) - { - getWalker().walk(mnode); - } - else if (mnode instanceof IVariableNode) - { - getWalker().walk(mnode); - } - - if (i < len - 1) - { - write(","); - writeNewline(); - } - i++; - } - indentPop(); - if (len > 0) - writeNewline(); - write("}"); - - indentPop(); - writeNewline(); - write("}));"); - - // static statements - len = staticStatements.size(); - if (len > 0) - writeNewline(); - - i = 0; - for (IASNode statement : staticStatements) - { - getWalker().walk(statement); - if (!(statement instanceof IBlockNode)) - write(";"); - - if (i < len - 1) - writeNewline(); - - i++; - } - - indentPop(); - writeNewline(); - write("});"); // end compilation unit - - } - - //-------------------------------------------------------------------------- - // - //-------------------------------------------------------------------------- - - @Override - public void emitField(IVariableNode node) - { - IVariableDefinition definition = (IVariableDefinition) node - .getDefinition(); - - if (definition.isStatic()) - { - IClassDefinition parent = (IClassDefinition) definition.getParent(); - write(parent.getBaseName()); - write("."); - write(definition.getBaseName()); - write(" = "); - emitFieldInitialValue(node); - return; - } - - String name = toPrivateName(definition); - write(name); - write(": "); - write("{"); - indentPush(); - writeNewline(); - // field value - write("value:"); - emitFieldInitialValue(node); - write(","); - writeNewline(); - // writable - write("writable:"); - write(!(definition instanceof IConstantDefinition) ? "true" : "false"); - indentPop(); - writeNewline(); - write("}"); - } - - private void emitFieldInitialValue(IVariableNode node) - { - ICompilerProject project = getWalker().getProject(); - IVariableDefinition definition = (IVariableDefinition) node - .getDefinition(); - - IExpressionNode valueNode = node.getAssignedValueNode(); - if (valueNode != null) - getWalker().walk(valueNode); - else - write(TempTools.toInitialValue(definition, project)); - } - - @Override - public void emitGetAccessor(IGetterNode node) - { - if (foundAccessors.containsKey(node.getName())) - return; - - foundAccessors.put(node.getName(), node); - - ICompilerProject project = getWalker().getProject(); - IAccessorDefinition getter = (IAccessorDefinition) node.getDefinition(); - IAccessorDefinition setter = getter - .resolveCorrespondingAccessor(project); - - emitGetterSetterPair(getter, setter); - } - - @Override - public void emitSetAccessor(ISetterNode node) - { - if (foundAccessors.containsKey(node.getName())) - return; - - foundAccessors.put(node.getName(), node); - - ICompilerProject project = getWalker().getProject(); - IAccessorDefinition setter = (IAccessorDefinition) node.getDefinition(); - IAccessorDefinition getter = setter - .resolveCorrespondingAccessor(project); - - emitGetterSetterPair(getter, setter); - } - - private void emitGetterSetterPair(IAccessorDefinition getter, - IAccessorDefinition setter) - { - write(getter.getBaseName()); - write(": {"); - indentPush(); - writeNewline(); - - if (getter != null) - { - emitAccessor("get", getter); - } - if (setter != null) - { - write(","); - writeNewline(); - emitAccessor("set", setter); - } - - indentPop(); - writeNewline(); - write("}"); - - } - - protected void emitAccessor(String kind, IAccessorDefinition definition) - { - IFunctionNode fnode = definition.getFunctionNode(); - - FunctionNode fn = (FunctionNode) fnode; - fn.parseFunctionBody(new ArrayList<ICompilerProblem>()); - - write(kind + ": function "); - write(definition.getBaseName() + "$" + kind); - emitParameters(fnode.getParametersContainerNode()); - emitMethodScope(fnode.getScopedNode()); - } - - @Override - public void emitMethod(IFunctionNode node) - { - if (node.isConstructor()) - { - emitConstructor(node); - return; - } - - FunctionNode fn = (FunctionNode) node; - fn.parseFunctionBody(new ArrayList<ICompilerProblem>()); - IFunctionDefinition definition = node.getDefinition(); - - String name = toPrivateName(definition); - write(name); - write(":"); - write(" function "); - write(node.getName()); - emitParameters(node.getParametersContainerNode()); - emitMethodScope(node.getScopedNode()); - } - - @Override - public void emitFunctionBlockHeader(IFunctionNode node) - { - IFunctionDefinition definition = node.getDefinition(); - - if (node.isConstructor()) - { - initializingFieldsInConstructor = true; - IClassDefinition type = (IClassDefinition) definition - .getAncestorOfType(IClassDefinition.class); - // emit public fields init values - List<IVariableDefinition> fields = TempTools.getFields(type, true); - for (IVariableDefinition field : fields) - { - if (TempTools.isVariableAParameter(field, - definition.getParameters())) - continue; - write("this."); - write(field.getBaseName()); - write(" = "); - emitFieldInitialValue((IVariableNode) field.getNode()); - write(";"); - writeNewline(); - } - initializingFieldsInConstructor = false; - } - - emitDefaultParameterCodeBlock(node); - } - - private void emitDefaultParameterCodeBlock(IFunctionNode node) - { - // TODO (mschmalle|AMD) test for ... rest - // if default parameters exist, produce the init code - IParameterNode[] pnodes = node.getParameterNodes(); - Map<Integer, IParameterNode> defaults = TempTools.getDefaults(pnodes); - if (pnodes.length == 0) - return; - - if (defaults != null) - { - boolean hasBody = node.getScopedNode().getChildCount() > 0; - - if (!hasBody) - { - indentPush(); - write(ASEmitterTokens.INDENT); - } - - final StringBuilder code = new StringBuilder(); - - List<IParameterNode> parameters = new ArrayList<IParameterNode>( - defaults.values()); - Collections.reverse(parameters); - - int len = defaults.size(); - // make the header in reverse order - for (IParameterNode pnode : parameters) - { - if (pnode != null) - { - code.setLength(0); - - code.append(ASEmitterTokens.IF.getToken()); - code.append(ASEmitterTokens.SPACE.getToken()); - code.append(ASEmitterTokens.PAREN_OPEN.getToken()); - code.append(JSEmitterTokens.ARGUMENTS.getToken()); - code.append(ASEmitterTokens.MEMBER_ACCESS.getToken()); - code.append(JSAMDEmitterTokens.LENGTH.getToken()); - code.append(ASEmitterTokens.SPACE.getToken()); - code.append(ASEmitterTokens.LESS_THAN.getToken()); - code.append(ASEmitterTokens.SPACE.getToken()); - code.append(len); - code.append(ASEmitterTokens.PAREN_CLOSE.getToken()); - code.append(ASEmitterTokens.SPACE.getToken()); - code.append(ASEmitterTokens.BLOCK_OPEN.getToken()); - - write(code.toString()); - - indentPush(); - writeNewline(); - } - len--; - } - - Collections.reverse(parameters); - for (int i = 0, n = parameters.size(); i < n; i++) - { - IParameterNode pnode = parameters.get(i); - - if (pnode != null) - { - code.setLength(0); - - code.append(pnode.getName()); - code.append(ASEmitterTokens.SPACE.getToken()); - code.append(ASEmitterTokens.EQUAL.getToken()); - code.append(ASEmitterTokens.SPACE.getToken()); - code.append(pnode.getDefaultValue()); - code.append(ASEmitterTokens.SEMICOLON.getToken()); - write(code.toString()); - - indentPop(); - writeNewline(); - - write(ASEmitterTokens.BLOCK_CLOSE); - - if (i == n - 1 && !hasBody) - indentPop(); - - writeNewline(); - } - } - } - } - - @Override - public void emitParameter(IParameterNode node) - { - getWalker().walk(node.getNameExpressionNode()); - } - - @Override - public void emitMemberAccessExpression(IMemberAccessExpressionNode node) - { - getWalker().walk(node.getLeftOperandNode()); - if (!(node.getLeftOperandNode() instanceof ILanguageIdentifierNode)) - write(node.getOperator().getOperatorText()); - getWalker().walk(node.getRightOperandNode()); - } - - @Override - public void emitFunctionCall(IFunctionCallNode node) - { - if (node.isNewExpression()) - { - write(ASEmitterTokens.NEW); - write(ASEmitterTokens.SPACE); - } - // IDefinition resolve = node.resolveType(project); - // if (NativeUtils.isNative(resolve.getBaseName())) - // { - // - // } - - getWalker().walk(node.getNameNode()); - - emitArguments(node.getArgumentsNode()); - } - - @Override - public void emitArguments(IContainerNode node) - { - IContainerNode newNode = node; - FunctionCallNode fnode = (FunctionCallNode) node.getParent(); - if (TempTools.injectThisArgument(fnode, false)) - { - IdentifierNode thisNode = new IdentifierNode("this"); - newNode = EmitterUtils.insertArgumentsBefore(node, thisNode); - } - - int len = newNode.getChildCount(); - write(ASEmitterTokens.PAREN_OPEN); - for (int i = 0; i < len; i++) - { - IExpressionNode inode = (IExpressionNode) newNode.getChild(i); - if (inode.getNodeID() == ASTNodeID.IdentifierID) - { - emitArgumentIdentifier((IIdentifierNode) inode); - } - else - { - getWalker().walk(inode); - } - - if (i < len - 1) - { - writeToken(ASEmitterTokens.COMMA); - } - } - write(ASEmitterTokens.PAREN_CLOSE); - } - - private void emitArgumentIdentifier(IIdentifierNode node) - { - ITypeDefinition type = node.resolveType(getWalker().getProject()); - if (type instanceof ClassTraitsDefinition) - { - String qualifiedName = type.getQualifiedName(); - write(qualifiedName); - } - else - { - // XXX A problem? - getWalker().walk(node); - } - } - - @Override - public void emitIdentifier(IIdentifierNode node) - { - ICompilerProject project = getWalker().getProject(); - - IDefinition resolve = node.resolve(project); - if (TempTools.isBinding(node, project)) - { - // AS3.bind( this,"secret$1"); - // this will happen on the right side of the = sign to bind a methof/function - // to a variable - - write("AS3.bind(this, \"" + toPrivateName(resolve) + "\")"); - } - else - { - IExpressionNode leftBase = TempTools.getNode(node, false, project); - if (leftBase == node) - { - if (TempTools.isValidThis(node, project)) - write("this."); - // in constructor and a type - if (initializingFieldsInConstructor - && resolve instanceof IClassDefinition) - { - String name = resolve.getBaseName(); - write("(" + name + "._ || " + name + "._$get())"); - return; - } - } - - if (resolve != null) - { - // TODO (mschmalle|AMD) optimize - String name = toPrivateName(resolve); - if (NativeUtils.isNative(name)) - exportWriter.addDependency(name, name, true, false); - - if (node.getParent() instanceof IMemberAccessExpressionNode) - { - IMemberAccessExpressionNode mnode = (IMemberAccessExpressionNode) node - .getParent(); - if (mnode.getLeftOperandNode().getNodeID() == ASTNodeID.SuperID) - { - IIdentifierNode lnode = (IIdentifierNode) mnode - .getRightOperandNode(); - - IClassNode cnode = (IClassNode) node - .getAncestorOfType(IClassNode.class); - - initializeInheritenceLevel(cnode.getDefinition()); - - // super.foo(); - write("this."); - - write(lnode.getName() + "$" + inheritenceLevel); - - baseClassCalls.add(resolve); - - return; - } - } - write(name); - } - else - { - // no definition, just plain ole identifer - write(node.getName()); - } - } - } - - @Override - protected void emitType(IExpressionNode node) - { - } - - @Override - public void emitLanguageIdentifier(ILanguageIdentifierNode node) - { - if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.ANY_TYPE) - { - write(""); - } - else if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.REST) - { - write(""); - } - else if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.SUPER) - { - IIdentifierNode inode = (IIdentifierNode) node; - if (inode.getParent() instanceof IMemberAccessExpressionNode) - { - - } - else - { - write("Super.call"); - } - } - else if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.THIS) - { - write(""); - } - else if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.VOID) - { - write(""); - } - } - - private String toPrivateName(IDefinition definition) - { - if (definition instanceof ITypeDefinition) - return definition.getBaseName(); - if (!definition.isPrivate()) - return definition.getBaseName(); - - initializeInheritenceLevel(definition); - - return definition.getBaseName() + "$" + inheritenceLevel; - } - - void initializeInheritenceLevel(IDefinition definition) - { - if (inheritenceLevel != -1) - return; - - IClassDefinition cdefinition = null; - if (definition instanceof IClassDefinition) - cdefinition = (IClassDefinition) definition; - else - cdefinition = (IClassDefinition) definition - .getAncestorOfType(IClassDefinition.class); - - ICompilerProject project = getWalker().getProject(); - IClassDefinition[] ancestry = cdefinition.resolveAncestry(project); - inheritenceLevel = ancestry.length - 1; - } -} diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/amd/JSAMDEmitterTokens.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/amd/JSAMDEmitterTokens.java deleted file mode 100644 index 2795f4699..000000000 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/amd/JSAMDEmitterTokens.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * - * 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.royale.compiler.internal.codegen.js.amd; - -import org.apache.royale.compiler.codegen.IEmitterTokens; - -public enum JSAMDEmitterTokens implements IEmitterTokens -{ - DEFINE("define"), LENGTH("length"), ; - - private String token; - - private JSAMDEmitterTokens(String value) - { - token = value; - } - - public String getToken() - { - return token; - } -} diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/amd/TempTools.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/amd/TempTools.java deleted file mode 100644 index 59f07e560..000000000 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/amd/TempTools.java +++ /dev/null @@ -1,451 +0,0 @@ -/* - * - * 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.royale.compiler.internal.codegen.js.amd; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.royale.compiler.common.ASModifier; -import org.apache.royale.compiler.definitions.IClassDefinition; -import org.apache.royale.compiler.definitions.IDefinition; -import org.apache.royale.compiler.definitions.IFunctionDefinition; -import org.apache.royale.compiler.definitions.IParameterDefinition; -import org.apache.royale.compiler.definitions.ITypeDefinition; -import org.apache.royale.compiler.definitions.IVariableDefinition; -import org.apache.royale.compiler.definitions.references.IReference; -import org.apache.royale.compiler.internal.definitions.ClassTraitsDefinition; -import org.apache.royale.compiler.internal.tree.as.ExpressionNodeBase; -import org.apache.royale.compiler.internal.tree.as.FunctionCallNode; -import org.apache.royale.compiler.internal.tree.as.MemberAccessExpressionNode; -import org.apache.royale.compiler.projects.ICompilerProject; -import org.apache.royale.compiler.tree.ASTNodeID; -import org.apache.royale.compiler.tree.as.IASNode; -import org.apache.royale.compiler.tree.as.IBinaryOperatorNode; -import org.apache.royale.compiler.tree.as.IClassNode; -import org.apache.royale.compiler.tree.as.IDefinitionNode; -import org.apache.royale.compiler.tree.as.IDynamicAccessNode; -import org.apache.royale.compiler.tree.as.IExpressionNode; -import org.apache.royale.compiler.tree.as.IForLoopNode; -import org.apache.royale.compiler.tree.as.IFunctionCallNode; -import org.apache.royale.compiler.tree.as.IFunctionNode; -import org.apache.royale.compiler.tree.as.IIdentifierNode; -import org.apache.royale.compiler.tree.as.ILanguageIdentifierNode; -import org.apache.royale.compiler.tree.as.ILanguageIdentifierNode.LanguageIdentifierKind; -import org.apache.royale.compiler.tree.as.IMemberAccessExpressionNode; -import org.apache.royale.compiler.tree.as.IParameterNode; -import org.apache.royale.compiler.tree.as.IUnaryOperatorNode; -import org.apache.royale.compiler.tree.as.IVariableNode; - -/** - * These tools need to be refactored into utility classes. - * - * @author Michael Schmalle - */ -public class TempTools -{ - - public static void fillStaticStatements(IClassNode node, - List<IASNode> list, boolean excludeFields) - { - int len = node.getScopedNode().getChildCount(); - for (int i = 0; i < len; i++) - { - IASNode child = node.getScopedNode().getChild(i); - if (child instanceof IExpressionNode) - list.add(child); - else if (child instanceof IDefinitionNode) - { - if (!excludeFields - && ((IDefinitionNode) child) - .hasModifier(ASModifier.STATIC) - && child instanceof IVariableNode) - list.add(child); - } - } - } - - public static void fillInstanceMembers(IDefinitionNode[] members, - List<IDefinitionNode> list) - { - for (IDefinitionNode node : members) - { - if (node instanceof IFunctionNode - && ((IFunctionNode) node).isConstructor()) - continue; - - if (!node.hasModifier(ASModifier.STATIC)) - { - list.add(node); - } - } - } - - public static void fillStaticMembers(IDefinitionNode[] members, - List<IDefinitionNode> list, boolean excludeFields, - boolean excludeFunctions) - { - for (IDefinitionNode node : members) - { - if (node.hasModifier(ASModifier.STATIC)) - { - if (!excludeFields && node instanceof IVariableNode) - list.add(node); - else if (!excludeFunctions && node instanceof IFunctionNode) - list.add(node); - } - } - } - - public static List<IVariableDefinition> getFields( - IClassDefinition definition, boolean excludePrivate) - { - ArrayList<IVariableDefinition> result = new ArrayList<IVariableDefinition>(); - Collection<IDefinition> definitions = definition.getContainedScope() - .getAllLocalDefinitions(); - for (IDefinition member : definitions) - { - if (!member.isImplicit() && member instanceof IVariableDefinition) - { - IVariableDefinition vnode = (IVariableDefinition) member; - if (!member.isStatic() - && (member.isPublic() || member.isProtected())) - result.add(vnode); - // TODO FIX the logic here, this won't add twice though - if (!excludePrivate && member.isPrivate()) - result.add(vnode); - } - } - return result; - } - - public static boolean isVariableAParameter(IVariableDefinition node, - IParameterDefinition[] parameters) - { - for (IParameterDefinition parameter : parameters) - { - if (node.getBaseName().equals(parameter.getBaseName())) - return true; - } - return false; - } - - public static Map<Integer, IParameterNode> getDefaults( - IParameterNode[] nodes) - { - Map<Integer, IParameterNode> result = new HashMap<Integer, IParameterNode>(); - int i = 0; - boolean hasDefaults = false; - for (IParameterNode node : nodes) - { - if (node.hasDefaultValue()) - { - hasDefaults = true; - result.put(i, node); - } - else - { - result.put(i, null); - } - i++; - } - - if (!hasDefaults) - return null; - - return result; - } - - public static boolean injectThisArgument(FunctionCallNode node, - boolean allowMembers) - { - // if super isSuper checks the nameNode - if (node.isSuperExpression() && !node.isNewExpression()) - return true; - - ExpressionNodeBase base = node.getNameNode(); - if (base.getNodeID() == ASTNodeID.IdentifierID) - return false; - - if (allowMembers && base instanceof IMemberAccessExpressionNode) - { - // foo.super() - IMemberAccessExpressionNode mnode = (IMemberAccessExpressionNode) base; - if (mnode.getLeftOperandNode().getNodeID() == ASTNodeID.SuperID) - return true; - } - - return false; - } - - public static String toInitialValue(IVariableDefinition field, - ICompilerProject project) - { - Object value = field.resolveInitialValue(project); - if (value != null) - return value.toString(); - IReference reference = field.getTypeReference(); - if (reference == null) - return "undefined"; - if (reference.getName().equals("int") - || reference.getName().equals("uint") - || reference.getName().equals("Number")) - return "0"; - return "null"; - } - - public static boolean isBinding(IIdentifierNode node, - ICompilerProject project) - { - IDefinition resolve = node.resolve(project); - - if (resolve != null && resolve.isPrivate() && !isField(resolve)) - { - //if (resolve instanceof IFunctionDefinition) - IExpressionNode rightSide = getNode(node, true, project); - IBinaryOperatorNode parent = (IBinaryOperatorNode) node - .getAncestorOfType(IBinaryOperatorNode.class); - if (isThisLeftOf(node)) - parent = (IBinaryOperatorNode) parent - .getAncestorOfType(IBinaryOperatorNode.class); - - IVariableNode vparent = (IVariableNode) node - .getAncestorOfType(IVariableNode.class); - if (vparent != null) - { - IExpressionNode indentFromThis = getIndentFromThis(node); - if (vparent.getAssignedValueNode() == node - || ((IBinaryOperatorNode) vparent - .getAssignedValueNode()).getRightOperandNode() == indentFromThis) - return true; - } - - if (rightSide == node && parent != null/*|| isThisLeftOf(node)*/) - { - return true; - } - } - - return false; - } - - private static boolean isField(IDefinition node) - { - return !(node instanceof IFunctionDefinition); - } - - public static boolean isValidThis(IIdentifierNode node, - ICompilerProject project) - { - // added super.foo(), wanted to 'this' behind foo - if (node.getParent() instanceof IMemberAccessExpressionNode) - { - IMemberAccessExpressionNode mnode = (IMemberAccessExpressionNode) node - .getParent(); - if (mnode.getLeftOperandNode().getNodeID() == ASTNodeID.SuperID) - return false; - - IExpressionNode indentFromThis = getIndentFromThis(node); - if (node == indentFromThis) - return true; - - // test that this is the base expression - ExpressionNodeBase enode = (ExpressionNodeBase) node; - ExpressionNodeBase baseExpression = enode.getBaseExpression(); - if (indentFromThis == null && baseExpression != null - && baseExpression != node) - return false; - - // check to see if the left is a type - ITypeDefinition type = mnode.getLeftOperandNode().resolveType( - project); - - // A.{foo} : Left is a Type - // XXX going to have to test packgeName to com.acme.A - if (type instanceof ClassTraitsDefinition - && mnode.getLeftOperandNode() == node) - { - return false; - } - // this.{foo} : explicit 'this', in js we are ignoring explicit this identifiers - // because we are inserting all of them with the emitter - else if (indentFromThis == null) - { - //return false; - } - - } - - IDefinition definition = node.resolve(project); - if (definition == null) - return false; // Is this correct? - if (definition instanceof IParameterDefinition) - return false; - if (definition.getParent() instanceof IMemberAccessExpressionNode) - return false; - if (!(definition.getParent() instanceof IClassDefinition)) - return false; - - if (definition instanceof IVariableDefinition) - { - IVariableDefinition variable = (IVariableDefinition) definition; - if (variable.isStatic()) - return false; - } - if (definition instanceof IFunctionDefinition) - { - IFunctionDefinition function = (IFunctionDefinition) definition; - if (function.isStatic()) - return false; - } - - return true; - } - - private static boolean isThisLeftOf(IIdentifierNode node) - { - if (node.getParent() instanceof IMemberAccessExpressionNode) - { - IMemberAccessExpressionNode parent = (IMemberAccessExpressionNode) node - .getParent(); - if (parent.getLeftOperandNode() instanceof ILanguageIdentifierNode - && ((ILanguageIdentifierNode) parent.getLeftOperandNode()) - .getKind() == LanguageIdentifierKind.THIS) - return true; - } - return false; - } - - public static IExpressionNode getNode(IASNode iNode, Boolean toRight, - ICompilerProject project) - { - try - { - IASNode node = iNode; - while (node != null) - { - if (node instanceof IBinaryOperatorNode - && !(node instanceof MemberAccessExpressionNode)) - { - if (toRight) - node = ((IBinaryOperatorNode) node) - .getRightOperandNode(); - else - node = ((IBinaryOperatorNode) node) - .getLeftOperandNode(); - } - else if (node instanceof IFunctionCallNode) - node = ((IFunctionCallNode) node).getNameNode(); - else if (node instanceof IDynamicAccessNode) - node = ((IDynamicAccessNode) node).getLeftOperandNode(); - else if (node instanceof IUnaryOperatorNode) - node = ((IUnaryOperatorNode) node).getOperandNode(); - else if (node instanceof IForLoopNode) - node = ((IForLoopNode) node).getChild(0).getChild(0); - else if (node instanceof IVariableNode) - { - if (toRight) - node = ((IVariableNode) node).getAssignedValueNode(); - else - node = ((IVariableNode) node).getVariableTypeNode(); - } - else if (node instanceof IExpressionNode) - { - // IDefinition def = ((IExpressionNode) node).resolve(project); - // if (def instanceof VariableDefinition) - // { - // final VariableDefinition variable = (VariableDefinition) def; - // def = variable.resolveType(project); - // } - // else if (def instanceof FunctionDefinition) - // { - // final FunctionDefinition functionDef = (FunctionDefinition) def; - // final IReference typeRef = functionDef - // .getReturnTypeReference(); - // if (typeRef != null) - // def = typeRef.resolve(project, - // (ASScope) getScopeFromNode(iNode), - // DependencyType.INHERITANCE, false); - // } - // else if (def instanceof IGetterDefinition) - // { - // final ITypeDefinition returnType = ((IGetterDefinition) def) - // .resolveReturnType(project); - // // def = m_sharedData.getDefinition(returnType - // // .getQualifiedName()); - // def = returnType; // XXX figure out - // } - // - // if (def != null && def instanceof ClassDefinition) - // { - // return def; - // } - return (IExpressionNode) node; - } - else - { - node = null; - } - } - } - catch (Exception e) - { - // getDefinitionForNode(iNode,toRight); - - // getDefinition() sometimes crashes, e.g. when looking at a cast to an interface in some cases, - // FunctionDefinition.getParameters() returns null and ExpressionNodeBase.determineIfFunction() chokes on it - // printWarning(iNode, "getDefinitionForNode() failed for" + iNode); - } - return null; - } - - private static IExpressionNode getIndentFromThis(IIdentifierNode node) - { - if (node.getParent() instanceof IMemberAccessExpressionNode) - { - IMemberAccessExpressionNode parent = (IMemberAccessExpressionNode) node - .getParent(); - if (parent.getLeftOperandNode() instanceof ILanguageIdentifierNode - && ((ILanguageIdentifierNode) parent.getLeftOperandNode()) - .getKind() == LanguageIdentifierKind.THIS) - return parent.getRightOperandNode(); - } - return null; - } - - public static String toPackageName(String name) - { - if (!name.contains(".")) - return name; - final String stem = name.substring(0, name.lastIndexOf(".")); - return stem; - } - - public static String toBaseName(String name) - { - if (!name.contains(".")) - return name; - final String basename = name.substring(name.lastIndexOf(".") + 1); - return basename; - } - -} diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/amd/AMDBackend.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/amd/AMDBackend.java deleted file mode 100644 index ca3174dfc..000000000 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/amd/AMDBackend.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * 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.royale.compiler.internal.driver.js.amd; - -import java.io.FilterWriter; - -import org.apache.royale.compiler.codegen.IDocEmitter; -import org.apache.royale.compiler.codegen.as.IASEmitter; -import org.apache.royale.compiler.codegen.js.IJSEmitter; -import org.apache.royale.compiler.driver.IBackend; -import org.apache.royale.compiler.internal.codegen.js.amd.JSAMDDocEmitter; -import org.apache.royale.compiler.internal.codegen.js.amd.JSAMDEmitter; -import org.apache.royale.compiler.internal.driver.js.JSBackend; - -/** - * A concrete implementation of the {@link IBackend} API for 'AMD' code - * production. - * - * @author Michael Schmalle - */ -public class AMDBackend extends JSBackend -{ - @Override - public IDocEmitter createDocEmitter(IASEmitter emitter) - { - return new JSAMDDocEmitter((IJSEmitter) emitter); - } - - @Override - public IJSEmitter createEmitter(FilterWriter out) - { - IJSEmitter emitter = new JSAMDEmitter(out); - emitter.setDocEmitter(createDocEmitter(emitter)); - return emitter; - } -} diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDClassA.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDClassA.java deleted file mode 100644 index f025b5c92..000000000 --- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDClassA.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * - * 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.royale.compiler.internal.codegen.js.amd; - -import org.apache.royale.compiler.internal.test.AMDTestBase; -import org.apache.royale.compiler.tree.as.IFunctionNode; -import org.apache.royale.compiler.tree.as.IGetterNode; -import org.apache.royale.compiler.tree.as.ISetterNode; -import org.apache.royale.compiler.tree.as.IVariableNode; -import org.junit.Ignore; -import org.junit.Test; - -/** - * This class tests the production of AMD JavaScript for the test project, class - * A. - * - * @author Michael Schmalle - */ -@Ignore -public class TestAMDClassA extends AMDTestBase -{ - // !!! the errors have to do with how I change 'this' on member expressions - - //-------------------------------------------------------------------------- - // Class A - //-------------------------------------------------------------------------- - - @Test - public void test_field_msg() - { - IVariableNode vnode = findField("_msg", classNode); - asBlockWalker.visitVariable(vnode); - assertOut("_msg$1: {\n\tvalue:0,\n\twritable:true\n}"); - } - - @Test - public void test_constructor() - { - IFunctionNode vnode = findFunction("A", classNode); - asBlockWalker.visitFunction(vnode); - assertOut("function A(msg) {\n\tthis.msg = msg;\n}"); - } - - @Test - public void test_get_msg() - { - IGetterNode node = findGetter("msg", classNode); - asBlockWalker.visitGetter(node); - assertOut("msg: {\n\tget: function msg$get() {\n\t\treturn String(this._msg$1);\n\t}," - + "\n\tset: function msg$set(value) {\n\t\tthis._msg$1 = parseInt(value, 10);\n\t}\n}"); - } - - @Test - public void test_set_msg() - { - ISetterNode node = findSetter("msg", classNode); - asBlockWalker.visitSetter(node); - assertOut("msg: {\n\tget: function msg$get() {\n\t\treturn String(this._msg$1);\n\t}," - + "\n\tset: function msg$set(value) {\n\t\tthis._msg$1 = parseInt(value, 10);\n\t}\n}"); - } - - @Test - public void test_secret() - { - IFunctionNode vnode = findFunction("secret", classNode); - asBlockWalker.visitFunction(vnode); - assertOut("secret$1: function secret(n) {\n\treturn this.msg + n;\n}"); - } - - @Test - public void test_foo() - { - IFunctionNode vnode = findFunction("foo", classNode); - asBlockWalker.visitFunction(vnode); - assertOut("foo: function foo(x) {\n\treturn this.secret$1(A.bar(x));\n}"); - } - - @Test - public void test_baz() - { - IFunctionNode vnode = findFunction("baz", classNode); - asBlockWalker.visitFunction(vnode); - assertOut("baz: function baz() {\n\tvar tmp = AS3.bind(this, " - + "\"secret$1\");\n\treturn tmp(\"-bound\");\n}"); - } - - @Test - public void test_bar() - { - IFunctionNode vnode = findFunction("bar", classNode); - asBlockWalker.visitFunction(vnode); - assertOut("bar: function bar(x) {\n\treturn x + 1;\n}"); - } - - @Test - public void test_file() - { - // not going to put this test production in until everything is concrete and agreed upon - asBlockWalker.visitFile(fileNode); - //assertOut(""); - } - - @Override - protected String getTypeUnderTest() - { - return "com.acme.A"; - } -} - -/* - --------------------------------------------------------------------------------- -02-07-2013 -Current Production of visitFile() --------------------------------------------------------------------------------- - -define(["exports", "runtime/AS3", "classes/I", "classes/String", "classes/parseInt", "classes/trace"], function($exports, AS3, I, String, parseInt, trace) { - "use strict"; - AS3.compilationUnit($exports, function($primaryDeclaration){ - function A(msg) { - this.msg = msg; - } - $primaryDeclaration(AS3.class_({ - package_: "com.acme", - class_: "A", - implements_: [ - I - ], - members: { - constructor: A, - _msg$1: { - value:0, - writable:true - }, - msg: { - get: function msg$get() { - return String(this._msg$1); - }, - set: function msg$set(value) { - this._msg$1 = parseInt(value, 10); - } - }, - secret$1: function secret(n) { - return this.msg + n; - }, - foo: function foo(x) { - return this.secret$1(A.bar(x)); - }, - baz: function baz() { - var tmp = AS3.bind(this, "secret$1"); - return tmp("-bound"); - } - }, - staticMembers: { - bar: function bar(x) { - return x + 1; - } - } - })); - trace("Class A is initialized!"); - }); -}); - -*/ diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDClassB.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDClassB.java deleted file mode 100644 index ceeb852e8..000000000 --- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDClassB.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * - * 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.royale.compiler.internal.codegen.js.amd; - -import org.apache.royale.compiler.internal.test.AMDTestBase; -import org.apache.royale.compiler.tree.as.IFunctionNode; -import org.apache.royale.compiler.tree.as.IVariableNode; -import org.junit.Ignore; -import org.junit.Test; - -/** - * This class tests the production of AMD JavaScript for the test project, class - * B. - * - * @author Michael Schmalle - */ -@Ignore -public class TestAMDClassB extends AMDTestBase -{ - //-------------------------------------------------------------------------- - // Class B - //-------------------------------------------------------------------------- - - // XXX (mschmalle) () get back to this when more work is done - @Test - public void test_nowPlusOne() - { -// IFunctionNode vnode = findFunction("nowPlusOne", classNode); -// asBlockWalker.visitFunction(vnode); -// assertOut("nowPlusOne: function nowPlusOne() {\n\treturn new Date(B.now.getTime() + 60 * 60 * 1000);\n}"); - } - - @Test - public void test_constructor() - { - IFunctionNode vnode = findFunction("B", classNode); - asBlockWalker.visitFunction(vnode); - assertOut("function B(msg, count) {\n\tthis.barfoo = (A._ || A._$get()).bar(3);" - + "\n\tSuper.call(this, msg);\n\tthis.count = count;\n\ttrace(\"now: \" + B.now);\n}"); - } - - @Test - public void test_count() - { - IVariableNode node = findField("count", classNode); - asBlockWalker.visitVariable(node); - assertOut("count: {\n\tvalue:0,\n\twritable:true\n}"); - } - - @Test - public void test_override_foo() - { - IFunctionNode vnode = findFunction("foo", classNode); - asBlockWalker.visitFunction(vnode); - assertOut("foo: function foo(x) {\n\treturn this.foo$2(x + 2) + \"-sub\";\n}"); - } - - @Test - public void test_now() - { - IVariableNode node = findField("now", classNode); - asBlockWalker.visitVariable(node); - assertOut("B.now = new Date()"); - } - - @Test - public void test_file() - { - // not going to put this test production in until everything is concrete and agreed upon - asBlockWalker.visitFile(fileNode); - //assertOut(""); - } - - @Override - protected String getTypeUnderTest() - { - return "com.acme.B"; - } - -} diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDEmitter.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDEmitter.java deleted file mode 100644 index 057ec186a..000000000 --- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDEmitter.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * - * 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.royale.compiler.internal.codegen.js.amd; - -import org.apache.royale.compiler.driver.IBackend; -import org.apache.royale.compiler.internal.driver.js.amd.AMDBackend; -import org.apache.royale.compiler.internal.test.ASTestBase; -import org.junit.Test; - -/** - * This class tests the production of 'AMD' JavaScript output. - * <p> - * Note; this is a complete prototype more used in figuring out where - * abstraction and indirection is needed concerning the AS -> JS translations. - * - * @author Michael Schmalle - */ -public class TestAMDEmitter extends ASTestBase -{ - // TODO (mschmalle) these tests were all ignored... ? - - @Test - public void testSimple() - { -// String code = "package com.example.components {" -// + "import org.apache.royale.html.staticControls.TextButton;" -// + "public class MyTextButton extends TextButton {" -// + "public function MyTextButton() {if (foo() != 42) { bar(); } }" -// + "private var _privateVar:String = \"do \";" -// + "public var publicProperty:Number = 100;" -// + "public function myFunction(value: String): String{" -// + "return \"Don't \" + _privateVar + value; }"; -// IFileNode node = compileAS(code); -// asBlockWalker.visitFile(node); -// assertOut("package com.example.components {\n\tpublic class MyTextButton extends TextButton {\n\t\tcom.example.components.MyTextButton = function() {\n\t\t\tif (foo() != 42) {\n\t\t\t\tbar();\n\t\t\t}\n\t\t}\n\t\tprivate var _privateVar:String = \"do \";\n\t\tpublic var publicProperty:Number = 100;\n\t\tcom.example.components.MyTextButton.prototype.myFunction = function(value) {\n\t\t\treturn \"Don't \" + _privateVar + value;\n\t\t}\n\t}\n}"); - } - - @Test - public void testSimpleMethod() - { -// IFunctionNode node = getMethod("function method1():void{\n}"); -// asBlockWalker.visitFunction(node); -// assertOut("A.prototype.method1 = function() {\n}"); - } - - @Test - public void testSimpleParameterReturnType() - { -// IFunctionNode node = getMethod("function method1(bar:int):int{\n}"); -// asBlockWalker.visitFunction(node); -// assertOut("A.prototype.method1 = function(bar) {\n}"); - } - - @Test - public void testSimpleMultipleParameter() - { -// IFunctionNode node = getMethod("function method1(bar:int, baz:String, goo:A):void{\n}"); -// asBlockWalker.visitFunction(node); -// assertOut("A.prototype.method1 = function(bar, baz, goo) {\n}"); - } - - @Test - public void testDefaultParameter() - { -// /* -// foo.bar.A.method1 = function(p1, p2, p3, p4) { -// if (arguments.length < 4) { -// if (arguments.length < 3) { -// p3 = 3; -// } -// p4 = 4; -// } -// return p1 + p2 + p3 + p4; -// } -// */ -// IFunctionNode node = getMethod("function method1(p1:int, p2:int, p3:int = 3, p4:int = 4):int{return p1 + p2 + p3 + p4;}"); -// asBlockWalker.visitFunction(node); -// assertOut("A.prototype.method1 = function(p1, p2, p3, p4) {\n\tif (arguments.length < 4) " -// + "{\n\t\tif (arguments.length < 3) {\n\t\t\tp3 = 3;\n\t\t}\n\t\tp4 = 4;\n\t}" -// + "\n\treturn p1 + p2 + p3 + p4;\n}"); - } - - @Test - public void testDefaultParameter_Body() - { -// /* -// foo.bar.A.method1 = function(bar, bax) { -// if (arguments.length < 2) { -// if (arguments.length < 1) { -// bar = 42; -// } -// bax = 4; -// } -// } -// */ -// IFunctionNode node = getMethod("function method1(bar:int = 42, bax:int = 4):void{if (a) foo();}"); -// asBlockWalker.visitFunction(node); -// assertOut("A.prototype.method1 = function(bar, bax) {\n\tif (arguments.length < 2) {\n\t\t" -// + "if (arguments.length < 1) {\n\t\t\tbar = 42;\n\t\t}\n\t\tbax = 4;\n\t}\n\t" -// + "if (a)\n\t\tfoo();\n}"); - } - - @Test - public void testDefaultParameter_NoBody_Alternate() - { -// /* -// foo.bar.A.method1 = function(bar, bax) { -// if (arguments.length < 2) { -// if (arguments.length < 1) { -// bar = 42; -// } -// bax = 4; -// } -// } -// */ -// IFunctionNode node = getMethod("function method1(bar:int = 42, bax:int = 4):void{\n}"); -// asBlockWalker.visitFunction(node); -// assertOut("A.prototype.method1 = function(bar, bax) {\n\tif (arguments.length < 2) {\n\t\t" -// + "if (arguments.length < 1) {\n\t\t\tbar = 42;\n\t\t}\n\t\tbax = 4;\n\t}\n}"); - } - - @Override - protected IBackend createBackend() - { - return new AMDBackend(); - } -} diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDInterfaceI.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDInterfaceI.java deleted file mode 100644 index 2be1ba3d8..000000000 --- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDInterfaceI.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * 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.royale.compiler.internal.codegen.js.amd; - -import org.apache.royale.compiler.internal.test.AMDTestBase; -import org.junit.Test; - -/** - * This class tests the production of AMD JavaScript for the test project, - * interface I. - * - * @author Michael Schmalle - */ -public class TestAMDInterfaceI extends AMDTestBase -{ - //-------------------------------------------------------------------------- - // Interface I - //-------------------------------------------------------------------------- - - @Test - public void test_file() - { - asBlockWalker.visitFile(fileNode); - assertOut("define([\"exports\", \"runtime/AS3\"], function($exports, AS3) {" - + "\n\t\"use strict\"; \n\tAS3.interface_($exports, {\n\t\tpackage_: " - + "\"com.acme\",\n\t\tinterface_: \"I\"\n\t});\n});"); - } - - @Override - protected String getTypeUnderTest() - { - return "com.acme.I"; - } -} diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDInterfaceIOther.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDInterfaceIOther.java deleted file mode 100644 index 2eeda45f2..000000000 --- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDInterfaceIOther.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * 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.royale.compiler.internal.codegen.js.amd; - -import org.apache.royale.compiler.internal.test.AMDTestBase; -import org.junit.Test; - -/** - * This class tests the production of AMD JavaScript for the test project, - * interface com.acme.sub.IOther. - * - * @author Michael Schmalle - */ -public class TestAMDInterfaceIOther extends AMDTestBase -{ - //-------------------------------------------------------------------------- - // Interface IOther - //-------------------------------------------------------------------------- - - @Test - public void test_file() - { - asBlockWalker.visitFile(fileNode); - assertOut("define([\"exports\", \"runtime/AS3\"], function($exports, AS3) {" - + "\n\t\"use strict\"; \n\tAS3.interface_($exports, {\n\t\tpackage_: " - + "\"com.acme.sub\",\n\t\tinterface_: \"IOther\"\n\t});\n});"); - } - - @Override - protected String getTypeUnderTest() - { - return "com.acme.sub.IOther"; - } -} diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDInterfaceISub.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDInterfaceISub.java deleted file mode 100644 index f607bf27e..000000000 --- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDInterfaceISub.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * 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.royale.compiler.internal.codegen.js.amd; - -import org.apache.royale.compiler.internal.test.AMDTestBase; -import org.junit.Test; - -/** - * This class tests the production of AMD JavaScript for the test project, - * interface com.acme.sub.ISub. - * - * @author Michael Schmalle - */ -public class TestAMDInterfaceISub extends AMDTestBase -{ - //-------------------------------------------------------------------------- - // Interface ISub - //-------------------------------------------------------------------------- - - @Test - public void test_file() - { - asBlockWalker.visitFile(fileNode); - assertOut("define([\"exports\", \"runtime/AS3\", \"classes/com/acme/I\"], " - + "function($exports, AS3, I) {\n\t\"use strict\"; \n\tAS3.interface_($exports, {" - + "\n\t\tpackage_: \"com.acme.sub\",\n\t\tinterface_: \"ISub\"\n\t\textends_: " - + "[\n\t\t\tI\n\t\t]\n\t});\n});"); - } - - @Override - protected String getTypeUnderTest() - { - return "com.acme.sub.ISub"; - } -} diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDPackage.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDPackage.java deleted file mode 100644 index 9e3c4ab3a..000000000 --- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/amd/TestAMDPackage.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * - * 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.royale.compiler.internal.codegen.js.amd; - -import java.io.IOException; - -import org.apache.royale.compiler.driver.IBackend; -import org.apache.royale.compiler.internal.codegen.as.TestPackage; -import org.apache.royale.compiler.internal.driver.js.amd.AMDBackend; -import org.apache.royale.compiler.tree.as.IFileNode; -import org.apache.royale.compiler.tree.as.IFunctionNode; -import org.junit.Test; - -/** - * This class tests the production of AMD JavaScript for AS package. - * - * @author Michael Schmalle - */ -public class TestAMDPackage extends TestPackage -{ - - @Override - @Test - public void testPackage_Simple() - { - IFileNode node = compileAS("package{}"); - asBlockWalker.visitFile(node); - assertOut(""); - } - - @Override - @Test - public void testPackage_SimpleName() - { - IFileNode node = compileAS("package foo {}"); - asBlockWalker.visitFile(node); - assertOut(""); - } - - @Override - @Test - public void testPackage_Name() - { - IFileNode node = compileAS("package foo.bar.baz {}"); - asBlockWalker.visitFile(node); - assertOut(""); - } - - @Override - @Test - public void testPackageSimple_Class() - { - IFileNode node = compileAS("package {public class A{}}"); - asBlockWalker.visitFile(node); - //assertOut(""); - } - - // XXX (mschmalle) ? - @Test - public void testPackageSimple_TestA() throws IOException - { - } - - @Override - @Test - public void testPackageQualified_Class() - { - IFileNode node = compileAS("package foo.bar.baz {public class A{}}"); - asBlockWalker.visitFile(node); - //assertOut(""); - } - - @Override - @Test - public void testPackageQualified_ClassBody() - { - IFileNode node = compileAS("package foo.bar.baz {public class A{public function A(){}}}"); - asBlockWalker.visitFile(node); - //assertOut(""); - } - - @Override - @Test - public void testPackageQualified_ClassBodyMethodContents() - { - IFileNode node = compileAS("package foo.bar.baz {public class A{public function A(){if (a){for (var i:Object in obj){doit();}}}}}"); - asBlockWalker.visitFile(node); - //assertOut(""); - } - - //@Test - public void testMethod() - { - IFunctionNode node = getMethod("function foo(){}"); - asBlockWalker.visitFunction(node); - assertOut("A.prototype.foo = function() {\n}"); - } - - @Override - protected IBackend createBackend() - { - return new AMDBackend(); - } - - protected IFileNode getFile(String code) - { - IFileNode node = compileAS(code); - return node; - } -} diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/AMDTestBase.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/AMDTestBase.java deleted file mode 100644 index 0e64896f9..000000000 --- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/AMDTestBase.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * - * 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.royale.compiler.internal.test; - -import java.io.File; -import java.util.List; - -import org.apache.royale.compiler.driver.IBackend; -import org.apache.royale.compiler.internal.driver.js.amd.AMDBackend; -import org.apache.royale.compiler.tree.as.IClassNode; -import org.apache.royale.compiler.tree.as.IDefinitionNode; -import org.apache.royale.compiler.tree.as.IFileNode; -import org.apache.royale.compiler.tree.as.IFunctionNode; -import org.apache.royale.compiler.tree.as.IGetterNode; -import org.apache.royale.compiler.tree.as.IInterfaceNode; -import org.apache.royale.compiler.tree.as.ISetterNode; -import org.apache.royale.compiler.tree.as.ITypeNode; -import org.apache.royale.compiler.tree.as.IVariableNode; -import org.apache.royale.utils.FilenameNormalization; -import org.apache.royale.utils.TestAdapterFactory; - -/** - * This class tests the production of AMD JavaScript for AS package. - * - * @author Michael Schmalle - */ -public abstract class AMDTestBase extends TestBase -{ - protected IFileNode fileNode; - - protected IClassNode classNode; - - protected IInterfaceNode interfaceNode; - - private String projectPath; - - @Override - public void setUp() - { - super.setUp(); - - asEmitter = backend.createEmitter(writer); - asBlockWalker = backend.createWalker(project, errors, asEmitter); - - projectPath = new File(TestAdapterFactory.getTestAdapter().getUnitTestBaseDir(), - "amd/simple-project/src").getPath(); - - String target = getTypeUnderTest().replace(".", File.separator); - String targetDir = projectPath + File.separator - + target.substring(0, target.lastIndexOf(File.separator)); - String targetFile = target.substring( - target.lastIndexOf(File.separator) + 1, target.length()); - - fileNode = compileAS(targetFile, true, targetDir, false); - ITypeNode type = (ITypeNode) findFirstDescendantOfType(fileNode, - ITypeNode.class); - if (type instanceof IClassNode) - classNode = (IClassNode) type; - else if (type instanceof IInterfaceNode) - interfaceNode = (IInterfaceNode) type; - - } - - abstract protected String getTypeUnderTest(); - - @Override - protected void addLibraries(List<File> libraries) - { - libraries.add(new File(FilenameNormalization.normalize(env.FPSDK - + "/" + env.FPVER + "/playerglobal.swc"))); - - super.addLibraries(libraries); - } - - @Override - protected void addSourcePaths(List<File> sourcePaths) - { - sourcePaths.add(new File(FilenameNormalization.normalize(projectPath))); - - super.addSourcePaths(sourcePaths); - } - - @Override - protected IBackend createBackend() - { - return new AMDBackend(); - } - - protected IVariableNode findField(String name, IClassNode node) - { - IDefinitionNode[] nodes = node.getAllMemberNodes(); - for (IDefinitionNode inode : nodes) - { - if (inode.getName().equals(name)) - return (IVariableNode) inode; - } - return null; - } - - protected IFunctionNode findFunction(String name, IClassNode node) - { - IDefinitionNode[] nodes = node.getAllMemberNodes(); - for (IDefinitionNode inode : nodes) - { - if (inode.getName().equals(name)) - return (IFunctionNode) inode; - } - return null; - } - - protected IGetterNode findGetter(String name, IClassNode node) - { - IDefinitionNode[] nodes = node.getAllMemberNodes(); - for (IDefinitionNode inode : nodes) - { - if (inode.getName().equals(name) && inode instanceof IGetterNode) - return (IGetterNode) inode; - } - return null; - } - - protected ISetterNode findSetter(String name, IClassNode node) - { - IDefinitionNode[] nodes = node.getAllMemberNodes(); - for (IDefinitionNode inode : nodes) - { - if (inode.getName().equals(name) && inode instanceof ISetterNode) - return (ISetterNode) inode; - } - return null; - } -}
