import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject
import java.util.Collection
import java.util.Arrays
+import java.util.HashMap
abstract class BaseTemplate {
throw new IllegalArgumentException("Generated type reference cannot be NULL!")
}
this.type = _type;
- this.importMap = GeneratorUtil.createImports(type)
+ this.importMap = new HashMap<String,String>()
}
def packageDefinition() '''package «type.packageName»;'''
def protected generateToString(Collection<GeneratedProperty> properties) '''
«IF !properties.empty»
@Override
- public String toString() {
- StringBuilder builder = new StringBuilder("«type.name» [");
+ public «String.importedName» toString() {
+ «StringBuilder.importedName» builder = new «StringBuilder.importedName»("«type.name» [");
boolean first = true;
«FOR property : properties»
def private generateAugmentField(boolean init) '''
«IF augmentField != null»
- private final «Map.importedName»<Class<? extends «augmentField.returnType.importedName»>, «augmentField.returnType.importedName»> «augmentField.name»«IF init» = new «HashMap.importedName»<>()«ENDIF»;
+ private «Map.importedName»<«Class.importedName»<? extends «augmentField.returnType.importedName»>, «augmentField.returnType.importedName»> «augmentField.name» = new «HashMap.importedName»<>();
«ENDIF»
'''
«ENDFOR»
«IF augmentField != null»
- public «type.name»«BUILDER» add«augmentField.name.toFirstUpper»(Class<? extends «augmentField.returnType.importedName»> augmentationType, «augmentField.returnType.importedName» augmentation) {
+ public «type.name»«BUILDER» add«augmentField.name.toFirstUpper»(«Class.importedName»<? extends «augmentField.returnType.importedName»> augmentationType, «augmentField.returnType.importedName» augmentation) {
this.«augmentField.name».put(augmentationType, augmentation);
return this;
}
this.«augmentField.name» = «Collections.importedName».emptyMap();
break;
case 1:
- final «Map.importedName».Entry<Class<? extends «augmentField.returnType.importedName»>, «augmentField.returnType.importedName»> e = builder.«augmentField.name».entrySet().iterator().next();
- this.«augmentField.name» = «Collections.importedName».<Class<? extends «augmentField.returnType.importedName»>, «augmentField.returnType.importedName»>singletonMap(e.getKey(), e.getValue());
+ final «Map.importedName».Entry<«Class.importedName»<? extends «augmentField.returnType.importedName»>, «augmentField.returnType.importedName»> e = builder.«augmentField.name».entrySet().iterator().next();
+ this.«augmentField.name» = «Collections.importedName».<«Class.importedName»<? extends «augmentField.returnType.importedName»>, «augmentField.returnType.importedName»>singletonMap(e.getKey(), e.getValue());
break;
default :
this.«augmentField.name» = new «HashMap.importedName»<>(builder.«augmentField.name»);
@SuppressWarnings("unchecked")
«IF addOverride»@Override«ENDIF»
- public <E extends «augmentField.returnType.importedName»> E get«augmentField.name.toFirstUpper»(Class<E> augmentationType) {
+ public <E extends «augmentField.returnType.importedName»> E get«augmentField.name.toFirstUpper»(«Class.importedName»<E> augmentationType) {
if (augmentationType == null) {
throw new IllegalArgumentException("Augmentation Type reference cannot be NULL!");
}
def protected generateEquals() '''
«IF !properties.empty || augmentField != null»
@Override
- public boolean equals(java.lang.Object obj) {
+ public boolean equals(«Object.importedName» obj) {
if (this == obj) {
return true;
}
def override generateToString(Collection<GeneratedProperty> properties) '''
«IF !(properties === null)»
@Override
- public String toString() {
- StringBuilder builder = new StringBuilder("«type.name» [");
+ public «String.importedName» toString() {
+ «StringBuilder.importedName» builder = new «StringBuilder.importedName» ("«type.name» [");
boolean first = true;
«FOR property : properties»
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-
import org.opendaylight.yangtools.binding.generator.util.TypeConstants;
import org.opendaylight.yangtools.binding.generator.util.Types;
import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType;
}
} else {
builder = new StringBuilder();
- if (typePackageName.startsWith("java.lang")) {
- builder.append(type.getName());
- } else {
if (!typePackageName.isEmpty()) {
builder.append(typePackageName + Constants.DOT + type.getName());
} else {
builder.append(type.getName());
}
- }
if (type.equals(Types.voidType())) {
return "void";
}
def private generateAnnotations(List<AnnotationType> annotations) '''
«IF annotations != null && !annotations.empty»
«FOR annotation : annotations»
- @«annotation.name»
+ @«annotation.importedName»
«IF annotation.parameters != null && !annotation.parameters.empty»
(
«FOR param : annotation.parameters SEPARATOR ","»
*/
package org.opendaylight.yangtools.sal.java.api.generator.test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.io.File;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
final String outputStr = clsGen.generate(genTO);
assertNotNull(outputStr);
- assertTrue(outputStr.contains("public CompositeKeyListKey(Byte _key1, String _key2)"));
+ assertTrue(outputStr.contains("public CompositeKeyListKey(java.lang.Byte _key1, java.lang.String _key2)"));
assertEquals(2, propertyCount);
genTOsCount++;
cleanUp(sourcesOutputDir, compiledOutputDir);
}
+ @Test
+ public void classNamesColisionTest() throws Exception {
+ final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "class-name-collision");
+ assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
+ final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "class-name-collision");
+ assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
+
+ generateTestSources("/compilation/class-name-collision", sourcesOutputDir);
+ testCompilation(sourcesOutputDir, compiledOutputDir);
+ cleanUp(sourcesOutputDir, compiledOutputDir);
+ }
+
private void generateTestSources(String resourceDirPath, File sourcesOutputDir) throws Exception {
final List<File> sourceFiles = getSourceFiles(resourceDirPath);
final Set<Module> modulesToBuild = parser.parseYangModels(sourceFiles);
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. 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
+ */
+module class-name-collision {
+ yang-version 1;
+ namespace "urn:class:name:collision";
+ prefix "bar";
+
+ revision "2014-04-28" {
+
+ }
+
+ list string {
+ }
+
+ list string-builder {
+ }
+
+ list class {
+ }
+
+ list set {
+ }
+
+ list map {
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. 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
+ */
+module configuration {
+ yang-version 1;
+ namespace "urn:configuration";
+ prefix "bar";
+
+ revision "2014-04-30" {
+ }
+
+ container configuration {
+ list class {
+ key "name";
+ leaf name {
+ type string;
+ }
+ leaf value {
+ type string;
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. 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
+ */
+module other-module {
+ yang-version 1;
+ namespace "urn:other-module";
+ prefix "bar";
+
+ revision "2014-04-29" {
+ }
+
+ list foo {
+ }
+
+ list boo {
+ }
+}