8000 Second batch for migration from Digester3 to JAXB by ptziegler · Pull Request #685 · eclipse-windowbuilder/windowbuilder · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ The technology is effectively dead and the project no longer actively maintained
In prevent compilation errors inside the workspace, those components have been
removed from the project.

### Changes to wbp-component.xml schema

All special characters in the description need to be properly encoded.

Example:
<b>...</b>

## 1.14.0 (2023-12)

### Deprecation of SWTResourceManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<!-- order -->
<xs:element name="order" minOccurs="0" type="xs:string" />
<!-- description -->
<xs:element name="description" minOccurs="0"/>
<xs:element name="description" minOccurs="0" type="xs:string"/>
<!-- creation -->
<xs:element name="creation-default" type="Creation" minOccurs="0"/>
<xs:element name="creation" type="Creation" minOccurs="0" maxOccurs="unbounded"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import org.eclipse.wb.core.databinding.xsd.component.Component;
import org.eclipse.wb.core.databinding.xsd.component.ContextFactory;
import org.eclipse.wb.core.databinding.xsd.component.Creation;
import org.eclipse.wb.core.databinding.xsd.component.ExposingRuleType;
import org.eclipse.wb.core.databinding.xsd.component.ExposingRulesType;
import org.eclipse.wb.core.databinding.xsd.component.MethodsOrderType;
import org.eclipse.wb.core.databinding.xsd.component.MorphingType;
import org.eclipse.wb.core.databinding.xsd.component.TagType;
import org.eclipse.wb.core.databinding.xsd.component.TypeParameterType;
Expand Down Expand Up @@ -42,7 +45,6 @@
import org.eclipse.wb.internal.core.model.description.rules.MethodOrderDefaultRule;
import org.eclipse.wb.internal.core.model.description.rules.MethodOrderMethodRule;
import org.eclipse.wb.internal.core.model.description.rules.MethodOrderMethodsRule;
import org.eclipse.wb.internal.core.model.description.rules.MethodOrderMethodsSignatureRule;
import org.eclipse.wb.internal.core.model.description.rules.MethodPropertyRule;
import org.eclipse.wb.internal.core.model.description.rules.MethodRule;
import org.eclipse.wb.internal.core.model.description.rules.MethodSinglePropertyRule;
Expand Down Expand Up @@ -71,7 +73,6 @@
import org.eclipse.wb.internal.core.model.description.rules.StandardBeanPropertiesRule;
import org.eclipse.wb.internal.core.model.description.rules.StandardBeanPropertyTagRule;
import org.eclipse.wb.internal.core.model.description.rules.ToolkitRule;
import org.eclipse.wb.internal.core.utils.IOUtils2;
import org.eclipse.wb.internal.core.utils.ast.AstEditor;
import org.eclipse.wb.internal.core.utils.ast.AstNodeUtils;
import org.eclipse.wb.internal.core.utils.ast.AstParser;
Expand Down Expand Up @@ -111,6 +112,7 @@
import java.util.List;

import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBElement;
import jakarta.xml.bind.Unmarshaller;

/**
Expand Down Expand Up @@ -391,9 +393,7 @@ private static ComponentDescription getDescription0(AstEditor editor, ComponentD
process(componentDescription, component, editor);
}
// clear parts that can not be inherited
if (descriptionInfo.clazz == componentClass) {
setDescriptionWithInnerTags(componentDescription, resourceInfo);
} else {
if (descriptionInfo.clazz != componentClass) {
componentDescription.clearCreations();
componentDescription.setDescription(null);
}
Expand Down Expand Up @@ -440,22 +440,6 @@ && shouldCacheDescriptions_inPackage(descriptionInfos.getLast(), componentClass)
}
}

/**
* Usually XML parsers don't allow to get content of element with all inner
* tags, but we want these tags for description. So, we need special way to get
* description. Right now it is not very accurate, but may be will enough for
* practical purposes.
*/
private static void setDescriptionWithInnerTags(ComponentDescription componentDescription,
ResourceInfo resourceInfo) throws Exception {
InputStream stream = resourceInfo.getURL().openStream();
String string = IOUtils2.readString(stream);
String description = StringUtils.substringBetween(string, "<description>", "</description>");
if (description != null) {
componentDescription.setDescription(description);
}
}

/**
* Configures default {@link CreationDescription} with valid source.
*/
Expand Down Expand Up @@ -644,6 +628,53 @@ private static void process(ComponentDescription componentDescription, Component
}
}
}
// description text
{
acceptSafe(componentDescription, component.getDescription(), ComponentDescription::setDescription);
}
// method order
{
MethodsOrderType methodsOrder = component.getMethodOrder();
if (methodsOrder != null) {
acceptSafe(componentDescription, methodsOrder.getDefault(), new MethodOrderDefaultRule());
for (MethodsOrderType.Method method : methodsOrder.getMethod()) {
acceptSafe(componentDescription, method, new MethodOrderMethodRule());
}
for (MethodsOrderType.Methods methods : methodsOrder.getMethods()) {
acceptSafe(componentDescription, methods, new MethodOrderMethodsRule());
}
}
}
// exposed children
{
if (component.getExposingRules() != null) {
ExposingRulesType exposingRules = component.getExposingRules();
for (JAXBElement<ExposingRuleType> exposingRule : exposingRules.getExcludeOrInclude()) {
acceptSafe(componentDescription, exposingRule, new ExposingRulesRule());
}
}
}
// methods-exclude, methods-include
{
Component.Methods methods = component.getMethods();
if (methods != null) {
for (Component.Methods.MethodsInclude methodsInclude : methods.getMethodsInclude()) {
acceptSafe(componentDescription, methodsInclude.getSignature(), new MethodsOperationRule(true));
}
for (Component.Methods.MethodsExclude methodsExclude : methods.getMethodsExclude()) {
acceptSafe(componentDescription, methodsExclude.getSignature(), new MethodsOperationRule(false));
}
}
}
// untyped parameters
{
Component.Parameters parameters = component.getParameters();
if (parameters != null) {
for (Component.Parameters.Parameter parameter : parameters.getParameter()) {
componentDescription.addParameter(parameter.getName(), parameter.getValue());
}
}
}
}

/**
Expand Down Expand Up @@ -671,12 +702,6 @@ private static void addRules(Digester digester, AstEditor editor, Class<?> compo
{
digester.addRule("component/public-field-properties", new PublicFieldPropertiesRule());
}
// description text
{
String pattern = "component/description";
digester.addCallMethod(pattern, "setDescription", 1);
digester.addCallParam(pattern, 0);
}
// constructors
{
String pattern = "component/constructors/constructor";
Expand All @@ -693,32 +718,6 @@ private static void addRules(Digester digester, AstEditor editor, Class<?> compo
digester.addRule(pattern + "/tag", new MethodTagRule());
addParametersRules(digester, pattern + "/parameter", state);
}
// method order
{
String pattern = "component/method-order";
digester.addRule(pattern + "/default", new MethodOrderDefaultRule());
digester.addRule(pattern + "/method", new MethodOrderMethodRule());
digester.addRule(pattern + "/methods", new MethodOrderMethodsRule());
digester.addRule(pattern + "/methods/s", new MethodOrderMethodsSignatureRule());
}
// exposed children
{
String pattern = "component/exposing-rules";
digester.addRule(pattern + "/include", new ExposingRulesRule());
digester.addRule(pattern + "/exclude", new ExposingRulesRule());
}
// methods-exclude, methods-include
{
digester.addRule("component/methods/methods-include", new MethodsOperationRule(true));
digester.addRule("component/methods/methods-exclude", new MethodsOperationRule(false));
}
// untyped parameters
{
String pattern = "component/parameters/parameter";
digester.addCallMethod(pattern, "addParameter", 2);
digester.addCallParam(pattern, 0, "name");
digester.addCallParam(pattern, 1);
}
addPropertiesRules(digester, state);
addConfigurablePropertiesRules(digester, state);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* Copyright (c) 2011, 2024 Google, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -10,33 +10,36 @@
*******************************************************************************/
package org.eclipse.wb.internal.core.model.description.rules;

import org.eclipse.wb.core.databinding.xsd.component.ExposingRuleType;
import org.eclipse.wb.internal.core.model.description.ComponentDescription;
import org.eclipse.wb.internal.core.model.description.ExposingMethodRule;
import org.eclipse.wb.internal.core.model.description.ExposingPackageRule;
import org.eclipse.wb.internal.core.model.description.ExposingRule;
import org.eclipse.wb.internal.core.model.description.helpers.ComponentDescriptionHelper.FailableBiConsumer;

import org.apache.commons.digester3.Rule;
import org.xml.sax.Attributes;
import jakarta.xml.bind.JAXBElement;

/**
* The {@link Rule} that adds include/exclude rules for exposed children.
* The {@link FailableBiConsumer} that adds include/exclude rules for exposed
* children.
*
* @author scheglov_ke
* @coverage core.model.description
*/
public final class ExposingRulesRule extends AbstractDesignerRule {
public final class ExposingRulesRule
implements FailableBiConsumer<ComponentDescription, JAXBElement<ExposingRuleType>, Exception> {
////////////////////////////////////////////////////////////////////////////
//
// Rule
//
////////////////////////////////////////////////////////////////////////////
@Override
public void begin(String namespace, String name, Attributes attributes) throws Exception {
ComponentDescription componentDescription = (ComponentDescription) getDigester().peek();
public void accept(ComponentDescription componentDescription, JAXBElement<ExposingRuleType> jaxb) throws Exception {
// prepare attributes
boolean include = "include".equals(name);
String packageName = attributes.getValue("package");
String methodName = attributes.getValue("method");
ExposingRuleType exposingRule = jaxb.getValue();
boolean include = "include".equals(jaxb.getName().getLocalPart());
String packageName = exposingRule.getPackage();
String methodName = exposingRule.getMethod();
// add expose rules
if (packageName != null) {
ExposingRule rule = new ExposingPackageRule(include, packageName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* Copyright (c) 2011, 2024 Google, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -10,28 +10,31 @@
*******************************************************************************/
package org.eclipse.wb.internal.core.model.description.rules;

import org.eclipse.wb.core.databinding.xsd.component.DefaultMethodOrderType;
import org.eclipse.wb.core.databinding.xsd.component.MethodsOrderType;
import org.eclipse.wb.internal.core.model.description.ComponentDescription;
import org.eclipse.wb.internal.core.model.description.helpers.ComponentDescriptionHelper.FailableBiConsumer;
import org.eclipse.wb.internal.core.model.order.MethodOrder;

import org.apache.commons.digester3.Rule;
import org.xml.sax.Attributes;

/**
* The {@link Rule} that sets {@link ComponentDescription#setDefaultMethodOrder(MethodOrder)}.
* The {@link FailableBiConsumer} that sets
* {@link ComponentDescription#setDefaultMethodOrder(MethodOrder)}.
*
* @author scheglov_ke
* @coverage core.model.description
*/
public final class MethodOrderDefaultRule extends AbstractDesignerRule {
public final class MethodOrderDefaultRule
implements FailableBiConsumer<ComponentDescription, MethodsOrderType.Default, Exception> {
////////////////////////////////////////////////////////////////////////////
//
// Rule
//
////////////////////////////////////////////////////////////////////////////
@Override
public void begin(String namespace, String name, Attributes attributes) throws Exception {
ComponentDescription componentDescription = (ComponentDescription) getDigester().peek();
String specification = getRequiredAttribute(name, attributes, "order");
public void accept(ComponentDescription componentDescription, MethodsOrderType.Default defaultMethod)
throws Exception {
DefaultMethodOrderType order = defaultMethod.getOrder();
String specification = order.value();
componentDescription.setDefaultMethodOrder(MethodOrder.parse(specification));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* Copyright (c) 2011, 2024 Google, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -10,39 +10,39 @@
*******************************************************************************/
package org.eclipse.wb.internal.core.model.description.rules;

import org.eclipse.wb.core.databinding.xsd.component.MethodsOrderType;
import org.eclipse.wb.internal.core.model.description.ComponentDescription;
import org.eclipse.wb.internal.core.model.description.MethodDescription;
import org.eclipse.wb.internal.core.model.description.helpers.ComponentDescriptionHelper.FailableBiConsumer;
import org.eclipse.wb.internal.core.model.order.MethodOrder;
import org.eclipse.wb.internal.core.utils.check.Assert;

import org.apache.commons.digester3.Rule;
import org.xml.sax.Attributes;

/**
* The {@link Rule} that {@link MethodOrder} for single {@link MethodDescription}.
* The {@link FailableBiConsumer} that {@link MethodOrder} for single
* {@link MethodDescription}.
*
* @author scheglov_ke
* @coverage core.model.description
*/
public final class MethodOrderMethodRule extends AbstractDesignerRule {
public final class MethodOrderMethodRule
implements FailableBiConsumer<ComponentDescription, MethodsOrderType.Method, Exception> {
////////////////////////////////////////////////////////////////////////////
//
// Rule
//
////////////////////////////////////////////////////////////////////////////
@Override
public void begin(String namespace, String name, Attributes attributes) throws Exception {
public void accept(ComponentDescription componentDescription, MethodsOrderType.Method method) throws Exception {
// prepare order
MethodOrder order;
{
String specification = getRequiredAttribute(name, attributes, "order");
String specification = method.getOrder();
order = MethodOrder.parse(specification);
}
// prepare method
MethodDescription methodDescription;
{
String signature = getRequiredAttribute(name, attributes, "signature");
ComponentDescription componentDescription = (ComponentDescription) getDigester().peek();
String signature = method.getSignature();
methodDescription = componentDescription.getMethod(signature);
Assert.isNotNull(
methodDescription,
Expand Down
Loading
0