document.remove(new Segment(source, attribute.getBegin() - 1, attribute.getEnd())); // 移除属性 if (oriattr != null) { String buf = String.format("#if(%s)%s=\"%s\"#end()", expression, oriattr.getName(), oriattr.getValue()); document.replace(new Segment(source, oriattr.getBegin(), oriattr.getEnd()), buf); document.remove(new Segment(source, attribute.getBegin(), attribute.getEnd())); // 移除ifattr控制属性 document.replace(new Segment(source, attribute.getBegin(), attribute.getEnd()), buf); document.remove(new Segment(source, attribute.getBegin(), attribute.getEnd())); // 移除setattr控制属性
document.remove(new Segment(source, attribute.getBegin() - 1, attribute.getEnd())); // 移除属性 if (oriattr != null) { String buf = String.format("#if(%s)%s=\"%s\"#end()", expression, oriattr.getName(), oriattr.getValue()); document.replace(new Segment(source, oriattr.getBegin(), oriattr.getEnd()), buf); document.remove(new Segment(source, attribute.getBegin(), attribute.getEnd())); // 移除ifattr控制属性 document.replace(new Segment(source, attribute.getBegin(), attribute.getEnd()), buf); document.remove(new Segment(source, attribute.getBegin(), attribute.getEnd())); // 移除setattr控制属性
int mainEndPos = attribute.getEnd() - tag.getBegin();
private TemplateNode parseDomElement(Element elem) { DOMElement templateElem = new DOMElement(elem.getName()); templateElem.setLocation(new Location(elem.getBegin(), elem.getEnd())); for (int i = 0; i < elem.getAttributes().size(); ++i) { Attribute attr = elem.getAttributes().get(i); if (attr.getName().indexOf(':') > 0) { AttributeComponentBinding component = parseAttributeComponent(attr); if (component != null) { templateElem.getAttributeComponents().add(component); } } else { templateElem.setAttribute(attr.getName(), attr.getValue(), new Location(attr.getBegin(), attr.getEnd())); } } Set<String> vars = new HashSet<>(); for (AttributeComponentBinding attrComponent : templateElem.getAttributeComponents()) { for (ComponentVariableBinding var : attrComponent.getVariables()) { vars.add(var.getName()); pushVar(var.getName(), var.getValueType()); } } parseSegment(elem.getEnd(), templateElem.getChildNodes(), child -> true); for (String var : vars) { popVar(var); } return templateElem; }
private TemplateNode parseDomElement(Element elem) { DOMElement templateElem = new DOMElement(elem.getName()); templateElem.setLocation(new Location(elem.getBegin(), elem.getEnd())); for (int i = 0; i < elem.getAttributes().size(); ++i) { Attribute attr = elem.getAttributes().get(i); if (attr.getName().indexOf(':') > 0) { AttributeComponentBinding component = parseAttributeComponent(attr); if (component != null) { templateElem.getAttributeComponents().add(component); } } else { templateElem.setAttribute(attr.getName(), attr.getValue(), new Location(attr.getBegin(), attr.getEnd())); } } Set<String> vars = new HashSet<>(); for (AttributeComponentBinding attrComponent : templateElem.getAttributeComponents()) { for (ComponentVariableBinding var : attrComponent.getVariables()) { vars.add(var.getName()); pushVar(var.getName(), var.getValueType()); } } parseSegment(elem.getEnd(), templateElem.getChildNodes(), child -> true); for (String var : vars) { popVar(var); } return templateElem; }
/** * Create a {@link PropertyTextUnitPlaceholder} given the supplied type, name and Jericho {@link Tag} and * {@link Attribute}. * * @param type * - {@link PlaceholderAccessType} is one of TRANSLATABLE, READ_ONLY_PROPERTY, WRITABLE_PROPERTY * @param name * - attribute name * @param value * - attribute value * @param tag * - Jericho {@link Tag} which contains the attribute * @param attribute * - attribute as a Jericho {@link Attribute} * @return a {@link PropertyTextUnitPlaceholder} representing the attribute */ protected PropertyTextUnitPlaceholder createPropertyTextUnitPlaceholder( PlaceholderAccessType type, String name, String value, Tag tag, Attribute attribute) { // offset of attribute int mainStartPos = attribute.getBegin() - tag.getBegin(); int mainEndPos = attribute.getEnd() - tag.getBegin(); // offset of value of the attribute int valueStartPos = attribute.getValueSegment().getBegin() - tag.getBegin(); int valueEndPos = attribute.getValueSegment().getEnd() - tag.getBegin(); return new PropertyTextUnitPlaceholder(type, normalizeAttributeName(name, value, tag), value, mainStartPos, mainEndPos, valueStartPos, valueEndPos); }
component.setLocation(new Location(attr.getBegin(), attr.getEnd())); if (componentMeta.nameSetter != null) { component.setElementNameMethodName(componentMeta.nameSetter.getName());
component.setLocation(new Location(attr.getBegin(), attr.getEnd())); if (componentMeta.nameSetter != null) { component.setElementNameMethodName(componentMeta.nameSetter.getName());