* Method Signature.
*/
public interface MethodSignature extends TypeMember {
-
/**
* Returns <code>true</code> if the method signature is defined as abstract. <br>
- * By default in java all method declarations in interface are defined as
- * abstract, but the user don't need necessary to declare abstract keyword
- * in front of each method. <br>
- * The abstract methods are allowed in Class definitions but only when the
- * class is declared as abstract.
+ * By default in java all method declarations in interface are defined as abstract, but the user does not need
+ * necessarily to declare abstract keyword in front of each method. <br>
+ * The abstract methods are allowed in Class definitions but only when the class is declared as abstract.
*
* @return <code>true</code> if the method signature is defined as abstract.
*/
boolean isAbstract();
/**
- * Returns the List of parameters that method declare. If the method does
- * not contain any parameters, the method will return empty List.
+ * Returns {@code true} if this method is a {@code interface default} method.
+ *
+ * @return <code>true</code> if the method signature is defined as default.
+ */
+ // FIXME: 4.0.0: make this method non-default
+ default boolean isDefault() {
+ return false;
+ }
+
+ /**
+ * Returns the List of parameters that method declare. If the method does not contain any parameters, the method
+ * will return empty List.
*
* @return the List of parameters that method declare.
*/
*/
public interface MethodSignatureBuilder extends TypeMemberBuilder<MethodSignatureBuilder> {
/**
- * Sets the flag for declaration of method as abstract or non abstract. If
- * the flag <code>isAbstract == true</code> The instantiated Method
- * Signature MUST have return value for {@link MethodSignature#isAbstract()}
- * also equals to <code>true</code>.
+ * Sets the flag for declaration of method as abstract or non abstract. If the flag {@code isAbstract == true}
+ * the instantiated Method Signature MUST have return value for {@link MethodSignature#isAbstract()} also equals to
+ * <code>true</code>.
*
* @param isAbstract is abstract flag
*/
MethodSignatureBuilder setAbstract(boolean isAbstract);
/**
- * Adds Parameter into the List of method parameters. Neither the Name or
- * Type of parameter can be <code>null</code>.
+ * Sets the flag indicating whether this is a {@code default interface} method.
+ *
+ * @param isDefault true if this signature is to represent a default method.
+ * @return this builder
+ */
+ // FIXME: 4.0.0: make this method non-default
+ default MethodSignatureBuilder setDefault(final boolean isDefault) {
+ throw new UnsupportedOperationException(getClass() + " does not override setDefault");
+ }
+
+ /**
+ * Adds Parameter into the List of method parameters. Neither the Name or Type of parameter can be {@code null}.
*
* <br>
* In case that any of parameters are defined as <code>null</code> the
/**
* Returns <code>new</code> <i>immutable</i> instance of Method Signature. <br>
- * The <code>definingType</code> param cannot be <code>null</code>. The
- * every method in Java MUST be declared and defined inside the scope of
- * <code>class</code> or <code>interface</code> definition. In case that
- * defining Type will be passed as <code>null</code> reference the method
- * SHOULD thrown {@link IllegalArgumentException}.
+ * The <code>definingType</code> param cannot be <code>null</code>. Every method in Java MUST be declared and
+ * defined inside the scope of <code>class</code> or <code>interface</code> definition. In case that defining Type
+ * will be passed as <code>null</code> reference the method SHOULD thrown {@link IllegalArgumentException}.
*
* @param definingType Defining Type of Method Signature
* @return <code>new</code> <i>immutable</i> instance of Method Signature.
final ListSchemaNode node) {
final MethodSignatureBuilder getMethod = interfaceBuilder.addMethod(
BindingMapping.getNonnullMethodName(node.getQName().getLocalName()));
- getMethod.setReturnType(returnType);
+ getMethod.setReturnType(returnType).setDefault(true);
annotateDeprecatedIfNecessary(node.getStatus(), getMethod);
}
private List<MethodSignature.Parameter> parameters = Collections.emptyList();
private List<MethodSignature.Parameter> unmodifiableParams = Collections.emptyList();
private boolean isAbstract;
+ private boolean isDefault;
MethodSignatureBuilderImpl(final String name) {
super(name);
return this;
}
+ @Override
+ public MethodSignatureBuilder setDefault(final boolean newIsDefault) {
+ this.isDefault = newIsDefault;
+ return this;
+ }
+
@Override
public MethodSignatureBuilder addParameter(final Type type, final String name) {
this.parameters = LazyCollections.lazyAdd(this.parameters, new MethodParameterImpl(name, type));
public MethodSignature toInstance(final Type definingType) {
final List<AnnotationType> annotations = toAnnotationTypes();
return new MethodSignatureImpl(definingType, getName(), annotations, getComment(), getAccessModifier(),
- getReturnType(), this.unmodifiableParams, isFinal(), this.isAbstract, isStatic());
+ getReturnType(), this.unmodifiableParams, isFinal(), this.isAbstract, isStatic(), isDefault);
}
@Override
private final List<Parameter> params;
private final boolean isAbstract;
+ private final boolean isDefault;
+
+ MethodSignatureImpl(final Type definingType, final String name, final List<AnnotationType> annotations,
+ final String comment, final AccessModifier accessModifier, final Type returnType,
+ final List<Parameter> params, final boolean isFinal, final boolean isAbstract, final boolean isStatic) {
+ this(definingType, name, annotations, comment, accessModifier, returnType, params, isFinal, isAbstract,
+ isStatic, false);
+ }
MethodSignatureImpl(final Type definingType, final String name, final List<AnnotationType> annotations,
final String comment, final AccessModifier accessModifier, final Type returnType,
- final List<Parameter> params, final boolean isFinal, final boolean isAbstract, final boolean isStatic) {
+ final List<Parameter> params, final boolean isFinal, final boolean isAbstract, final boolean isStatic,
+ final boolean isDefault) {
super(definingType, name, annotations, comment, accessModifier, returnType, isFinal, isStatic);
this.params = params;
this.isAbstract = isAbstract;
+ this.isDefault = isDefault;
}
@Override
return this.isAbstract;
}
+ @Override
+ public boolean isDefault() {
+ return isDefault;
+ }
+
@Override
public List<Parameter> getParameters() {
return this.params;
checkArgument(method.getReturnType() != null);
checkArgument(method.getName() != null);
checkArgument(!method.getName().isEmpty());
+ if (method.isDefault()) {
+ return null;
+ }
final String prefix = BindingMapping.getGetterPrefix(Types.BOOLEAN.equals(method.getReturnType()));
if (!method.getName().startsWith(prefix)) {
return null;
*/
def private Object generateConstructorFromIfc(Type impl) '''
«IF (impl instanceof GeneratedType)»
- «IF !(impl.methodDefinitions.empty)»
+ «IF impl.hasNonDefaultMethods»
public «type.name»(«impl.fullyQualifiedName» arg) {
«printConstructorPropertySetter(impl)»
}
def private Object printConstructorPropertySetter(Type implementedIfc) '''
«IF (implementedIfc instanceof GeneratedType && !(implementedIfc instanceof GeneratedTransferObject))»
«val ifc = implementedIfc as GeneratedType»
- «FOR getter : ifc.methodDefinitions»
- this._«getter.propertyNameFromGetter» = arg.«getter.name»();
+ «FOR getter : ifc.nonDefaultMethods»
+ «IF BindingMapping.isGetterMethodName(getter.name)»
+ this._«getter.propertyNameFromGetter» = arg.«getter.name»();
+ «ENDIF»
«ENDFOR»
«FOR impl : ifc.implements»
«printConstructorPropertySetter(impl)»
def boolean hasImplementsFromUses(GeneratedType type) {
var i = 0
for (impl : type.getAllIfcs) {
- if ((impl instanceof GeneratedType) && !((impl as GeneratedType).methodDefinitions.empty)) {
+ if (impl instanceof GeneratedType && (impl as GeneratedType).hasNonDefaultMethods) {
i = i + 1
}
}
}
def private generateIfCheck(Type impl, List<Type> done) '''
- «IF (impl instanceof GeneratedType) && !((impl as GeneratedType).methodDefinitions.empty)»
+ «IF (impl instanceof GeneratedType && (impl as GeneratedType).hasNonDefaultMethods)»
«val implType = impl as GeneratedType»
if (arg instanceof «implType.fullyQualifiedName») {
«printPropertySetter(implType)»
def private printPropertySetter(Type implementedIfc) '''
«IF (implementedIfc instanceof GeneratedType && !(implementedIfc instanceof GeneratedTransferObject))»
«val ifc = implementedIfc as GeneratedType»
- «FOR getter : ifc.methodDefinitions»
- this._«getter.propertyNameFromGetter» = ((«implementedIfc.fullyQualifiedName»)arg).«getter.name»();
+ «FOR getter : ifc.nonDefaultMethods»
+ «IF BindingMapping.isGetterMethodName(getter.name)»
+ this._«getter.propertyNameFromGetter» = ((«implementedIfc.fullyQualifiedName»)arg).«getter.name»();
+ «ENDIF»
«ENDFOR»
«ENDIF»
'''
private def List<Type> getBaseIfcs(GeneratedType type) {
val List<Type> baseIfcs = new ArrayList();
for (ifc : type.implements) {
- if (ifc instanceof GeneratedType && !(ifc as GeneratedType).methodDefinitions.empty) {
+ if (ifc instanceof GeneratedType && (ifc as GeneratedType).hasNonDefaultMethods) {
baseIfcs.add(ifc)
}
}
if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
val ifc = type as GeneratedType
for (impl : ifc.implements) {
- if (impl instanceof GeneratedType && !(impl as GeneratedType).methodDefinitions.empty) {
+ if (impl instanceof GeneratedType && (impl as GeneratedType).hasNonDefaultMethods) {
baseIfcs.add(impl)
}
baseIfcs.addAll(impl.getAllIfcs)
}
'''
}
+
+ private static def hasNonDefaultMethods(GeneratedType type) {
+ !type.methodDefinitions.isEmpty && type.methodDefinitions.exists([def | !def.isDefault])
+ }
+
+ private static def nonDefaultMethods(GeneratedType type) {
+ type.methodDefinitions.filter([def | !def.isDefault])
+ }
}
def private generateMethods() '''
«IF !methods.empty»
«FOR m : methods SEPARATOR "\n"»
- «val noParams = m.parameters.empty»
- «IF noParams && m.name.isGetterMethodName»
+ «IF m.isDefault»
+ «generateDefaultMethod(m)»
+ «ELSEIF m.parameters.empty && m.name.isGetterMethodName»
«generateAccessorMethod(m)»
- «ELSEIF noParams && m.name.isNonnullMethodName»
- «generateNonnullMethod(m)»
«ELSE»
«generateMethod(m)»
«ENDIF»
«ENDIF»
'''
+ def private generateDefaultMethod(MethodSignature method) {
+ if (method.name.isNonnullMethodName) {
+ return generateNonnullMethod(method)
+ }
+ }
+
def private generateMethod(MethodSignature method) '''
«method.comment.asJavadoc»
«method.annotations.generateAnnotations»
--- /dev/null
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. 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 http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.test.model;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugment;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugmentBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.put.top.input.choice.list.choice.in.choice.list.ComplexViaUses;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.put.top.input.choice.list.choice.in.choice.list.ComplexViaUsesBuilder;
+
+public class TestCopyBuilders {
+
+ @Test
+ public void testBuilderListCopy() {
+ final TreeComplexUsesAugment source = new TreeComplexUsesAugmentBuilder().build();
+ final ComplexViaUses viaUses = new ComplexViaUsesBuilder().build();
+ final TreeComplexUsesAugment copied = new TreeComplexUsesAugmentBuilder(viaUses).build();
+ assertEquals(source, copied);
+ }
+}