Skip to content

Commit

Permalink
fixes following the rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
wigbam committed Mar 17, 2023
1 parent d175416 commit 6615997
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.Map;
import java.util.Set;

import com.sun.codemodel.*;
import org.jsonschema2pojo.AnnotationStyle;
import org.jsonschema2pojo.Annotator;
import org.jsonschema2pojo.Schema;
Expand All @@ -39,6 +38,22 @@
import org.jsonschema2pojo.util.SerializableHelper;

import com.fasterxml.jackson.databind.JsonNode;
import com.sun.codemodel.ClassType;
import com.sun.codemodel.JBlock;
import com.sun.codemodel.JClass;
import com.sun.codemodel.JClassAlreadyExistsException;
import com.sun.codemodel.JClassContainer;
import com.sun.codemodel.JConditional;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JExpr;
import com.sun.codemodel.JExpression;
import com.sun.codemodel.JFieldRef;
import com.sun.codemodel.JFieldVar;
import com.sun.codemodel.JMethod;
import com.sun.codemodel.JMod;
import com.sun.codemodel.JOp;
import com.sun.codemodel.JType;
import com.sun.codemodel.JVar;

/**
* Applies the generation steps required for schemas of type "object".
Expand Down Expand Up @@ -185,7 +200,6 @@ private JDefinedClass createClass(String nodeName, JsonNode node, JClassContaine

Annotator annotator = ruleFactory.getAnnotator();


try {
if (node.has("existingJavaType")) {
String fqn = substringBefore(node.get("existingJavaType").asText(), "<");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static String makeUnique(String className) {

if (m.matches()) {
// get the current number
final Integer number = Integer.parseInt(m.group(2));
final int number = Integer.parseInt(m.group(2));
// replace the current number in the string with the number +1
return m.group(1) + (number + 1);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package org.jsonschema2pojo.util;

import java.util.Iterator;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.stream.StreamSupport;

import static java.lang.Character.*;
import static javax.lang.model.SourceVersion.*;
Expand All @@ -28,7 +30,6 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.sun.codemodel.JClass;
import com.sun.codemodel.JClassAlreadyExistsException;
import com.sun.codemodel.JClassContainer;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JType;
Expand Down Expand Up @@ -289,17 +290,11 @@ private String createFullFieldName(String nodeName, String prefix, String suffix
}

private String makeUnique(String className, JClassContainer container) {
try {
JDefinedClass _class = container._class(className);
Iterator<JDefinedClass> iter = container.classes();
while (iter.hasNext()) {
if (iter.next().equals(_class)) {
iter.remove();
}
}
return className;
} catch (JClassAlreadyExistsException e) {
if (StreamSupport.stream(Spliterators.spliteratorUnknownSize(container.classes(), Spliterator.DISTINCT), false)
.anyMatch(x -> x.name().equals(className))) {
return makeUnique(MakeUniqueClassName.makeUnique(className), container);
}

return className;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.sun.codemodel.JType;
import org.jsonschema2pojo.Annotator;
import org.jsonschema2pojo.GenerationConfig;
import org.jsonschema2pojo.RuleLogger;
import org.jsonschema2pojo.Schema;
import org.jsonschema2pojo.util.NameHelper;
import org.jsonschema2pojo.util.ParcelableHelper;
Expand All @@ -42,6 +43,7 @@ public class ObjectRuleTest {
protected final RuleFactory ruleFactory = mock(RuleFactory.class);
protected final Annotator annotator = mock(Annotator.class);
protected final NameHelper nameHelper = mock(NameHelper.class);
protected final RuleLogger ruleLogger = mock(RuleLogger.class);
protected final ParcelableHelper parcelableHelper = mock(ParcelableHelper.class);
protected final ReflectionHelper reflectionHelper = mock(ReflectionHelper.class);
protected final AdditionalPropertiesRule additionalPropertiesRule = mock(AdditionalPropertiesRule.class);
Expand All @@ -63,6 +65,7 @@ public void setUp() {
lenient().when(ruleFactory.getReflectionHelper()).thenReturn(reflectionHelper);
lenient().when(ruleFactory.getPropertiesRule()).thenReturn(propertiesRule);
lenient().when(ruleFactory.getGenerationConfig()).thenReturn(generationConfig);
lenient().when(ruleFactory.getLogger()).thenReturn(ruleLogger);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void testClassNameCorrectly() {
}

@Test
public void testGetUniqueClassNamePackageNewClass() throws Exception {
public void testGetUniqueClassNamePackageNewClass() {
JCodeModel codeModel = new JCodeModel();
JPackage _package = codeModel._package("pkg");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* Copyright © 2010-2020 Nokia
* <p>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down

0 comments on commit 6615997

Please sign in to comment.