[BUGFIX] Fix for FLEX-35273
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/c1417e13 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/c1417e13 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/c1417e13 Branch: refs/heads/master Commit: c1417e134de1fe703dfb88e29369893a3038a7bf Parents: 9cb1399 Author: greg-dove <[email protected]> Authored: Mon Mar 6 21:25:15 2017 +1300 Committer: greg-dove <[email protected]> Committed: Mon Mar 6 21:32:40 2017 +1300 ---------------------------------------------------------------------- .../tree/mxml/MXMLPropertySpecifierNode.java | 47 ++++++++++++++++++-- ...XMLBadChildTagPropertyAssignmentProblem.java | 47 ++++++++++++++++++++ .../MXMLMultipleInitializersProblem.java | 46 +++++++++++++++++++ 3 files changed, 136 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c1417e13/compiler/src/main/java/org/apache/flex/compiler/internal/tree/mxml/MXMLPropertySpecifierNode.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/tree/mxml/MXMLPropertySpecifierNode.java b/compiler/src/main/java/org/apache/flex/compiler/internal/tree/mxml/MXMLPropertySpecifierNode.java index f4a43f1..5e812d4 100644 --- a/compiler/src/main/java/org/apache/flex/compiler/internal/tree/mxml/MXMLPropertySpecifierNode.java +++ b/compiler/src/main/java/org/apache/flex/compiler/internal/tree/mxml/MXMLPropertySpecifierNode.java @@ -47,8 +47,7 @@ import org.apache.flex.compiler.mxml.IMXMLTagData; import org.apache.flex.compiler.mxml.IMXMLTextData; import org.apache.flex.compiler.mxml.IMXMLUnitData; import org.apache.flex.compiler.parsing.MXMLTokenTypes; -import org.apache.flex.compiler.problems.ICompilerProblem; -import org.apache.flex.compiler.problems.MXMLUnresolvedTagProblem; +import org.apache.flex.compiler.problems.*; import org.apache.flex.compiler.tree.ASTNodeID; import org.apache.flex.compiler.tree.as.IASNode; import org.apache.flex.compiler.tree.mxml.IMXMLInstanceNode; @@ -124,6 +123,10 @@ class MXMLPropertySpecifierNode extends MXMLSpecifierNodeBase implements IMXMLPr * The sole child node, which is the value of the property. */ private MXMLInstanceNode instanceNode; + /* + * Flag to track whether an instance problem has already been logged (multiple children) + */ + private Boolean firstInstanceProblemAdded = false; @Override public ASTNodeID getNodeID() @@ -436,6 +439,8 @@ class MXMLPropertySpecifierNode extends MXMLSpecifierNodeBase implements IMXMLPr MXMLNodeInfo info) { MXMLFileScope fileScope = builder.getFileScope(); + //use a local variable until we are sure that this is a valid instance node + MXMLInstanceNode instanceNode = null; // Check whether the tag is an <fx:Component> tag. if (fileScope.isComponentTag(childTag)) @@ -484,11 +489,45 @@ class MXMLPropertySpecifierNode extends MXMLSpecifierNodeBase implements IMXMLPr } } } - } - // Report problem for second instance tag or for any other kind of tag. + ITypeDefinition assignToType = getPropertyType(builder); + // if the assignToType is Array it is special-cased, and handled in initializationComplete method + if (assignToType != project.getBuiltinType(IASLanguageConstants.BuiltinType.ARRAY)) { + //otherwise if the type of the instance node is incompatible with the type of the property node, + //or if there are multiple child tags + //that's a problem + if (instanceNode!=null && this.instanceNode==null && + !(instanceNode.getClassReference(project).isInstanceOf(assignToType,project) || + assignToType == project.getBuiltinType(IASLanguageConstants.BuiltinType.ANY_TYPE))) { + //we have a single value of incompatible type + ICompilerProblem problem = new MXMLBadChildTagPropertyAssignmentProblem(childTag,instanceNode.getClassReference(project).getQualifiedName(),propertyTypeName); + builder.addProblem(problem); + instanceNode=null; + + } else { + if (this.instanceNode!=null && instanceNode!=null) { + //we have a multiple values when we should only have one + if (!firstInstanceProblemAdded) { + //if we have multiple children problem scenario, we only encounter that on the 2nd childTag + //so start with a MXMLMultipleInitializersProblem instance for the first tag + ICompilerProblem problem = new MXMLMultipleInitializersProblem( tag.getFirstChild(false),getPropertyTypeName(builder)); + builder.addProblem(problem); + firstInstanceProblemAdded=true; + } + + ICompilerProblem problem = new MXMLMultipleInitializersProblem(childTag,getPropertyTypeName(builder)); + builder.addProblem(problem); + instanceNode=null; + } + } + } + } + if (instanceNode!=null) + this.instanceNode = instanceNode; } + + /** * This override is called on each non-whitespace unit of text inside a * property tag, such as <label>O<!-- comment -->K</label> which must http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c1417e13/compiler/src/main/java/org/apache/flex/compiler/problems/MXMLBadChildTagPropertyAssignmentProblem.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/compiler/problems/MXMLBadChildTagPropertyAssignmentProblem.java b/compiler/src/main/java/org/apache/flex/compiler/problems/MXMLBadChildTagPropertyAssignmentProblem.java new file mode 100644 index 0000000..a08ce92 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/compiler/problems/MXMLBadChildTagPropertyAssignmentProblem.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.compiler.problems; + +import org.apache.flex.compiler.mxml.IMXMLTagData; + +/** + * Problem generated for property value child tag on an property MXML tag. + */ +public final class MXMLBadChildTagPropertyAssignmentProblem extends MXMLSemanticProblem +{ + public static final String DESCRIPTION = + "In initializer for '${element}', type ${type} is not assignable to target type '${assignToType}'."; + public static final int errorCode = 1999; + public MXMLBadChildTagPropertyAssignmentProblem(IMXMLTagData tag ,String incompatibleType,String expectedType) + { + super(tag); + childTag = tag.getName(); + childNamespace = tag.getURI() != null ? tag.getURI() : ""; + element = tag.getParentTag().getName(); + type=incompatibleType; + assignToType = expectedType; + } + + public String childTag; + public final String childNamespace; + public String element; + public String assignToType; + public String type; +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c1417e13/compiler/src/main/java/org/apache/flex/compiler/problems/MXMLMultipleInitializersProblem.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/compiler/problems/MXMLMultipleInitializersProblem.java b/compiler/src/main/java/org/apache/flex/compiler/problems/MXMLMultipleInitializersProblem.java new file mode 100644 index 0000000..55bb226 --- /dev/null +++ b/compiler/src/main/java/org/apache/flex/compiler/problems/MXMLMultipleInitializersProblem.java @@ -0,0 +1,46 @@ +/* + * + * 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.problems; + +import org.apache.flex.compiler.mxml.IMXMLTagData; + +/** + * Problem generated for multiple initializers as child tags on an MXML property tag. + */ +public final class MXMLMultipleInitializersProblem extends MXMLSemanticProblem +{ + public static final String DESCRIPTION = + "In initializer for '${element}' multiple initializer values are not permitted for target type '${targetType}'."; + + public static final int errorCode = 1998; + public MXMLMultipleInitializersProblem(IMXMLTagData tag, String targetType) + { + super(tag); + childTag = tag.getShortName(); + childNamespace = tag.getURI() != null ? tag.getURI() : ""; + element = tag.getParentTag().getName(); + this.targetType = targetType; + } + + public String childTag; + public final String childNamespace; + public String element; + public String targetType; +}
