Skip to content

Commit

Permalink
Fixed #84
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed May 25, 2020
1 parent 5c617a9 commit 78aa846
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/helger/jcodemodel/JAnonymousClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public String fullName ()
@Override
public void generate (final IJFormatter f)
{
f.type (m_aBaseClass);
if (true)
m_aBaseClass.generate (f);
else
f.type (m_aBaseClass);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
* Portions Copyright 2013-2020 Philip Helger + contributors
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.helger.jcodemodel.supplementary.issues;

import java.util.List;

import org.junit.Test;

import com.helger.jcodemodel.JAnonymousClass;
import com.helger.jcodemodel.JCodeModel;
import com.helger.jcodemodel.JDefinedClass;
import com.helger.jcodemodel.JExpr;
import com.helger.jcodemodel.util.CodeModelTestsHelper;

/**
* Test for https://github.com/phax/jcodemodel/issues/84
*
* @author Philip Helger
*/
public final class Issue84FuncTest
{
@Test
public void testIssue () throws Exception
{
final JCodeModel cm = new JCodeModel ();

final JDefinedClass outerClass = cm._class ("test.Outer");
final JDefinedClass innerClass = outerClass._class ("Inner");

final JDefinedClass testClass = cm._class ("test.Test");
final JAnonymousClass anonymousClass = cm.anonymousClass (cm.ref (List.class).narrow (innerClass));
testClass.field (0, cm.ref (List.class).narrow (innerClass), "field", JExpr._new (anonymousClass));

CodeModelTestsHelper.parseCodeModel (cm);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ public final class CodeModelTestsHelper
@Nonnull
private static IJFormatter _createFormatter (@Nonnull final StringWriter aWriter)
{
return new JFormatter (new SourcePrintWriter (aWriter, JCMWriter.getDefaultNewLine ()),
JCMWriter.DEFAULT_INDENT_STRING);
return new JFormatter (new SourcePrintWriter (aWriter, JCMWriter.getDefaultNewLine ()), JCMWriter.DEFAULT_INDENT_STRING);
}

/** Hidden constructor. */
Expand Down Expand Up @@ -234,6 +233,7 @@ private static CompilationUnit _parseWithJavaParser (final byte [] aBytes,

System.out.println ("Parsing " +
JCStringHelper.replaceAll (sDirName, '/', '.') +
(sDirName.length () > 0 ? "." : "") +
(sFilename.endsWith (".java") ? sFilename.substring (0, sFilename.length () - 5) : sFilename));

try (final ByteArrayInputStream bis = new ByteArrayInputStream (aBytes))
Expand Down

0 comments on commit 78aa846

Please sign in to comment.