You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2021/04/26 18:23:24 UTC
[royale-compiler] branch develop updated: MXMLFileNode: validate
the the file name of the .mxml file is a valid ActionScript class name
(closes #173)
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
The following commit(s) were added to refs/heads/develop by this push:
new a9adcdc MXMLFileNode: validate the the file name of the .mxml file is a valid ActionScript class name (closes #173)
a9adcdc is described below
commit a9adcdcf69a89f4a071d004e2f1f18c6bcfd9008
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Mon Apr 26 11:22:45 2021 -0700
MXMLFileNode: validate the the file name of the .mxml file is a valid ActionScript class name (closes #173)
---
.../compiler/internal/tree/mxml/MXMLFileNode.java | 25 ++++++++++++++
.../problems/MXMLInvalidComponentNameProblem.java | 40 ++++++++++++++++++++++
2 files changed, 65 insertions(+)
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLFileNode.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLFileNode.java
index e9c5517..065dd85 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLFileNode.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLFileNode.java
@@ -56,6 +56,7 @@ import org.apache.royale.compiler.problems.MXMLConstructorHasParametersProblem;
import org.apache.royale.compiler.problems.MXMLContentAfterRootTagProblem;
import org.apache.royale.compiler.problems.MXMLContentBeforeRootTagProblem;
import org.apache.royale.compiler.problems.MXMLFinalClassProblem;
+import org.apache.royale.compiler.problems.MXMLInvalidComponentNameProblem;
import org.apache.royale.compiler.problems.MXMLMissingRootTagProblem;
import org.apache.royale.compiler.problems.MXMLMultipleRootTagsProblem;
import org.apache.royale.compiler.problems.MXMLNotAClassProblem;
@@ -224,11 +225,35 @@ public class MXMLFileNode extends MXMLNodeBase implements IMXMLFileNode, IScoped
}
}
+ private boolean isValidClassName(String className)
+ {
+ if (className == null || className.length() == 0 || !Character.isJavaIdentifierStart(className.charAt(0)))
+ {
+ return false;
+ }
+
+ for (int i=1; i < className.length(); i++)
+ {
+ if (!Character.isJavaIdentifierPart((className.charAt(i))))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
private void processRootTag(MXMLTreeBuilder builder, IMXMLTagData rootTag, IMXMLTextData asDoc)
{
ClassDefinition fileDef = fileScope.getMainClassDefinition();
assert fileDef != null;
+ if(!isValidClassName(fileDef.getBaseName())) {
+ ICompilerProblem problem = new MXMLInvalidComponentNameProblem(this, fileDef.getBaseName());
+ builder.addProblem(problem);
+ return;
+ }
+
IDefinition tagDef = builder.getFileScope().resolveTagToDefinition(rootTag);
// Report a problem if the root tag doesn't map to a definition.
diff --git a/compiler/src/main/java/org/apache/royale/compiler/problems/MXMLInvalidComponentNameProblem.java b/compiler/src/main/java/org/apache/royale/compiler/problems/MXMLInvalidComponentNameProblem.java
new file mode 100644
index 0000000..62d6733
--- /dev/null
+++ b/compiler/src/main/java/org/apache/royale/compiler/problems/MXMLInvalidComponentNameProblem.java
@@ -0,0 +1,40 @@
+/*
+ *
+ * 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.problems;
+
+import org.apache.royale.compiler.tree.mxml.IMXMLFileNode;
+
+/**
+ * Problem generated when the <code>id</code> attribute
+ * is an invalid ActionScript identifier.
+ */
+public final class MXMLInvalidComponentNameProblem extends MXMLSemanticProblem
+{
+ public static final String DESCRIPTION =
+ "The component name '${componentName}' is not a valid ActionScript identifier.";
+
+ public MXMLInvalidComponentNameProblem(IMXMLFileNode site, String componentName)
+ {
+ super(site);
+ this.componentName = componentName;
+ }
+
+ public String componentName;
+}