/** * Resolve the specifier name in the class definition to a member definition, and create a * specifier node based on the member type. * * @param builder MXML tree builder. * @param specifierName Specifier name. * @return A MXML specifier node. */ protected MXMLSpecifierNodeBase createSpecifierNode( MXMLTreeBuilder builder, String specifierName) { MXMLSpecifierNodeBase specifierNode = null; // Check if the attribute is a declared property, style, or event. FlexProject project = builder.getProject(); IDefinition specifierDefinition = project.resolveSpecifier(classReference, specifierName); if (specifierDefinition instanceof ISetterDefinition || specifierDefinition instanceof IVariableDefinition) { specifierNode = new MXMLPropertySpecifierNode(this); } else if (specifierDefinition instanceof IEventDefinition) { specifierNode = new MXMLEventSpecifierNode(this); } else if (specifierDefinition instanceof IStyleDefinition) { specifierNode = new MXMLStyleSpecifierNode(this); } else if (specifierDefinition instanceof IEffectDefinition) { specifierNode = new MXMLEffectSpecifierNode(this); } if (specifierNode != null) { specifierNode.setDefinition(specifierDefinition); // TODO Move this logic } // If not, dynamic classes allow new properties to be set via attributes. else if (classReference.isDynamic()) { specifierNode = new MXMLPropertySpecifierNode(this); ((MXMLPropertySpecifierNode) specifierNode) .setDynamicName(specifierName); // TODO Move this logic } return specifierNode; }
@Override protected void processTagSpecificAttribute( MXMLTreeBuilder builder, MXMLTagData tag, MXMLTagAttributeData attribute, MXMLNodeInfo info) { MXMLSpecifierNodeBase childNode = createSpecifierNode(builder, attribute.getName()); if (childNode != null) { childNode.setLocation(attribute); childNode.setSuffix(builder, attribute.getStateName()); childNode.initializeFromAttribute(builder, attribute, info); info.addChildNode(childNode); } else { super.processTagSpecificAttribute(builder, tag, attribute, info); } }
@Override protected void processChildNonWhitespaceUnit( MXMLTreeBuilder builder, MXMLTagData tag, MXMLTextData text, MXMLNodeInfo info) { // Non-whitespace may be the value of a default property. IVariableDefinition defaultPropertyDefinition = getDefaultPropertyDefinition(builder); if (defaultPropertyDefinition != null) { MXMLSpecifierNodeBase childNode = createSpecifierNode(builder, defaultPropertyDefinition.getBaseName()); if (childNode != null) { childNode.initializeFromText(builder, text, info); info.addChildNode(childNode); } } else { super.processChildNonWhitespaceUnit(builder, tag, text, info); } }
@Override protected void processChildTag( MXMLTreeBuilder builder, MXMLTagData tag, MXMLTagData childTag, MXMLNodeInfo info) { if (info.hasSpecifierWithName(childTag.getShortName(), childTag.getStateName())) { ICompilerProblem problem = new MXMLDuplicateChildTagProblem(childTag); builder.addProblem(problem); return; } FlexProject project = builder.getProject(); // Handle child tags that are property/style/event specifiers. MXMLSpecifierNodeBase childNode = createSpecifierNode(builder, childTag.getShortName()); if (childNode != null) { // This tag is not part of the default property value. processNonDefaultPropertyContentUnit(builder, info); childNode.setSuffix(builder, childTag.getStateName()); childNode.initializeFromTag(builder, childTag); info.addChildNode(childNode); } else if (builder.getFileScope().isScriptTag(childTag) && (builder.getMXMLDialect().isEqualToOrBefore(MXMLDialect.MXML_2009))) { // In MXML 2006 and 2009, allow a <Script> tag // inside any class reference tag if (!processingDefaultProperty) { // Not processing the default property, just make a script // node and put it in the tree. MXMLScriptNode scriptNode = new MXMLScriptNode(this); scriptNode.initializeFromTag(builder, childTag); info.addChildNode(scriptNode); } else { // We are processing a default property. Script nodes need // to be a child of that default specifier nodes so that // finding a node by offset works properly. // See: http://bugs.adobe.com/jira/browse/CMP-955 processDefaultPropertyContentUnit(builder, childTag, info); } } else if (builder.getFileScope().isReparentTag(childTag)) { MXMLReparentNode reparentNode = new MXMLReparentNode(this); reparentNode.initializeFromTag(builder, childTag); info.addChildNode(reparentNode); } else { IDefinition definition = builder.getFileScope().resolveTagToDefinition(childTag); if (definition instanceof ClassDefinition) { // Handle child tags that are instance tags. IVariableDefinition defaultPropertyDefinition = getDefaultPropertyDefinition(builder); if (defaultPropertyDefinition != null && !processedDefaultProperty) { // Since there is a default property and we haven't already processed it, // assume this child instance tag is part of its value. processDefaultPropertyContentUnit(builder, childTag, info); } else { // This tag is not part of the default property value. processNonDefaultPropertyContentUnit(builder, info); MXMLInstanceNode instanceNode = MXMLInstanceNode.createInstanceNode(builder, definition.getQualifiedName(), this); instanceNode.setClassReference( project, (IClassDefinition) definition); // TODO Move this logic to initializeFromTag(). instanceNode.initializeFromTag(builder, childTag); info.addChildNode(instanceNode); } } else { // Handle child tags that are something other than property/style/event tags // or instance tags. // This tag is not part of the default property value. processNonDefaultPropertyContentUnit(builder, info); super.processChildTag(builder, tag, childTag, info); } } }