diff -Nru jboss-jdeparser2-2.0.0/debian/changelog jboss-jdeparser2-2.0.2/debian/changelog --- jboss-jdeparser2-2.0.0/debian/changelog 2015-10-19 18:39:05.000000000 +0000 +++ jboss-jdeparser2-2.0.2/debian/changelog 2016-04-20 06:10:32.000000000 +0000 @@ -1,3 +1,19 @@ +jboss-jdeparser2 (2.0.2-1) unstable; urgency=medium + + * Imported Upstream version 2.0.2. + * Declare compliance with Debian Policy 3.9.8. + + -- Markus Koschany Wed, 20 Apr 2016 08:08:55 +0200 + +jboss-jdeparser2 (2.0.1-1) unstable; urgency=medium + + * Imported Upstream version 2.0.1. + * Update my e-mail address. + * Declare compliance with Debian Policy 3.9.7. + * Vcs-Git: Use https. + + -- Markus Koschany Sun, 20 Mar 2016 18:30:23 +0100 + jboss-jdeparser2 (2.0.0-1) unstable; urgency=medium * Initial release. (Closes: #799112) diff -Nru jboss-jdeparser2-2.0.0/debian/control jboss-jdeparser2-2.0.2/debian/control --- jboss-jdeparser2-2.0.0/debian/control 2015-10-19 17:43:44.000000000 +0000 +++ jboss-jdeparser2-2.0.2/debian/control 2016-04-20 06:10:32.000000000 +0000 @@ -3,7 +3,7 @@ Priority: optional Maintainer: Debian Java Maintainers Uploaders: - Markus Koschany + Markus Koschany Build-Depends: debhelper (>= 9), default-jdk, @@ -11,8 +11,8 @@ junit4, libmaven-javadoc-plugin-java, maven-debian-helper (>= 1.5) -Standards-Version: 3.9.6 -Vcs-Git: git://anonscm.debian.org/pkg-java/jboss-jdeparser2.git +Standards-Version: 3.9.8 +Vcs-Git: https://anonscm.debian.org/git/pkg-java/jboss-jdeparser2.git Vcs-Browser: https://anonscm.debian.org/cgit/pkg-java/jboss-jdeparser2.git Homepage: https://github.com/jdeparser/jdeparser2 diff -Nru jboss-jdeparser2-2.0.0/debian/copyright jboss-jdeparser2-2.0.2/debian/copyright --- jboss-jdeparser2-2.0.0/debian/copyright 2015-10-19 17:43:44.000000000 +0000 +++ jboss-jdeparser2-2.0.2/debian/copyright 2016-04-20 06:10:32.000000000 +0000 @@ -6,11 +6,11 @@ jdeparser2 is licensed under Apache-2.0. Files: * -Copyright: 2015, Red Hat, Inc. +Copyright: 2015-2016, Red Hat, Inc. License: Apache-2.0 Files: debian/* -Copyright: 2015, Markus Koschany +Copyright: 2015-2016, Markus Koschany License: Apache-2.0 License: Apache-2.0 diff -Nru jboss-jdeparser2-2.0.0/debian/patches/disable-apiviz-plugin.patch jboss-jdeparser2-2.0.2/debian/patches/disable-apiviz-plugin.patch --- jboss-jdeparser2-2.0.0/debian/patches/disable-apiviz-plugin.patch 2015-10-19 17:43:44.000000000 +0000 +++ jboss-jdeparser2-2.0.2/debian/patches/disable-apiviz-plugin.patch 2016-04-20 06:10:32.000000000 +0000 @@ -1,4 +1,4 @@ -From: Markus Koschany +From: Markus Koschany Date: Thu, 28 May 2015 15:08:20 +0200 Subject: disable apiviz plugin diff -Nru jboss-jdeparser2-2.0.0/debian/rules jboss-jdeparser2-2.0.2/debian/rules --- jboss-jdeparser2-2.0.0/debian/rules 2015-10-19 17:43:44.000000000 +0000 +++ jboss-jdeparser2-2.0.2/debian/rules 2016-04-20 06:10:32.000000000 +0000 @@ -1,5 +1,4 @@ #!/usr/bin/make -f -export JAVA_HOME=/usr/lib/jvm/default-java %: dh $@ --parallel --buildsystem=maven diff -Nru jboss-jdeparser2-2.0.0/pom.xml jboss-jdeparser2-2.0.2/pom.xml --- jboss-jdeparser2-2.0.0/pom.xml 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/pom.xml 2016-04-18 17:39:15.000000000 +0000 @@ -28,7 +28,7 @@ org.jboss.jdeparser jdeparser - 2.0.0.Final + 2.0.2.Final org.jboss diff -Nru jboss-jdeparser2-2.0.0/README.md jboss-jdeparser2-2.0.2/README.md --- jboss-jdeparser2-2.0.0/README.md 1970-01-01 00:00:00.000000000 +0000 +++ jboss-jdeparser2-2.0.2/README.md 2016-04-18 17:39:15.000000000 +0000 @@ -0,0 +1,16 @@ +# jdeparser2 +Version 2.x of JDeparser, a Java source code generating library. + +## Usage and documentionation + +The online JavaDoc is located at https://jdeparser.github.io/jdeparser2. + +See org.jboss.jdeparser.SimpleExampleTestCase for an example to get you off the ground quick. + +## Source + +The source code is found at https://github.com/jdeparser/jdeparser2 - feel free to clone and contribute. + +## Bug Tracker + +The bug tracker can be found at https://issues.jboss.org/browse/JDP. diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/AbstractJCall.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/AbstractJCall.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/AbstractJCall.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/AbstractJCall.java 2016-04-18 17:39:15.000000000 +0000 @@ -104,7 +104,7 @@ } public void write(final SourceFileWriter writer) throws IOException { - writer.write(FormatPreferences.Space.BEFORE_PAREN); + writer.write(FormatPreferences.Space.BEFORE_PAREN_METHOD_CALL); writer.write($PUNCT.PAREN.OPEN); writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_DECLARATION); if (args != null) { diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/AbstractJClassDef.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/AbstractJClassDef.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/AbstractJClassDef.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/AbstractJClassDef.java 2016-04-18 17:39:15.000000000 +0000 @@ -89,6 +89,14 @@ return item; } + public JComment lineComment() { + return add(new LineJComment()); + } + + public JComment blockComment() { + return add(new BlockJComment()); + } + public JClassDefSection section() { return add(new JClassDefSectionImpl(this)); } @@ -372,7 +380,9 @@ sourceFileWriter.write(ifExt ? $KW.EXTENDS : $KW.IMPLEMENTS); sourceFileWriter.write(iterator.next()); while (iterator.hasNext()) { + sourceFileWriter.write(FormatPreferences.Space.BEFORE_COMMA); sourceFileWriter.write($PUNCT.COMMA); + sourceFileWriter.write(FormatPreferences.Space.AFTER_COMMA); sourceFileWriter.write(iterator.next()); } } diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/AbstractJType.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/AbstractJType.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/AbstractJType.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/AbstractJType.java 2016-04-18 17:39:15.000000000 +0000 @@ -40,10 +40,18 @@ throw new IllegalArgumentException("Using a JType from a different implementation"); } - String qualifiedName(SourceFileWriter writer) { + String qualifiedName() { return simpleName(); } + public abstract int hashCode(); + + public final boolean equals(Object other) { + return other instanceof AbstractJType && equals((AbstractJType) other); + } + + abstract boolean equals(AbstractJType other); + public abstract String simpleName(); public abstract String toString(); diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/ArrayJType.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/ArrayJType.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/ArrayJType.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/ArrayJType.java 2016-04-18 17:39:15.000000000 +0000 @@ -44,8 +44,16 @@ sourceFileWriter.write($PUNCT.BRACKET.CLOSE); } - String qualifiedName(final SourceFileWriter writer) { - return elementType.qualifiedName(writer); + String qualifiedName() { + return elementType.qualifiedName(); + } + + public int hashCode() { + return elementType.hashCode() ^ 0xee55ee55 + 7; + } + + boolean equals(final AbstractJType other) { + return other instanceof ArrayJType && elementType.equals(((ArrayJType) other).elementType); } public JExpr _new(final JExpr dim) { diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/ArrayLookupJExpr.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/ArrayLookupJExpr.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/ArrayLookupJExpr.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/ArrayLookupJExpr.java 2016-04-18 17:39:15.000000000 +0000 @@ -32,7 +32,7 @@ ArrayLookupJExpr(final AbstractJExpr expr, final AbstractJExpr idx) { super(Prec.ARRAY_ACCESS); - this.expr = expr.prec() < Prec.ARRAY_ACCESS ? new ParenJExpr(expr) : expr; + this.expr = expr.prec() > Prec.ARRAY_ACCESS ? new ParenJExpr(expr) : expr; this.idx = idx; } diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/BasicJBlock.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/BasicJBlock.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/BasicJBlock.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/BasicJBlock.java 2016-04-18 17:39:15.000000000 +0000 @@ -200,7 +200,7 @@ } public JCall call(final JExpr obj, final String name) { - return add(new InstanceJCall(obj, name)); + return add(new InstanceJCall(AbstractJExpr.of(obj), name)); } public JCall callStatic(final ExecutableElement element) { @@ -218,7 +218,7 @@ } public JCall callStatic(final JType type, final String name) { - return add(new StaticJCall(type, name)); + return add(new StaticJCall(AbstractJType.of(type), name)); } public JCall callStatic(final Class type, final String name) { diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/CastJExpr.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/CastJExpr.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/CastJExpr.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/CastJExpr.java 2016-04-18 17:39:15.000000000 +0000 @@ -32,7 +32,7 @@ CastJExpr(final AbstractJExpr expr, final JType type) { super(Prec.CAST); - this.expr = expr.prec() < Prec.CAST ? new ParenJExpr(expr) : expr; + this.expr = expr.prec() > Prec.CAST ? new ParenJExpr(expr) : expr; this.type = type; } diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/CondJExpr.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/CondJExpr.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/CondJExpr.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/CondJExpr.java 2016-04-18 17:39:15.000000000 +0000 @@ -33,9 +33,9 @@ CondJExpr(final AbstractJExpr cond, final AbstractJExpr ifTrue, final AbstractJExpr ifFalse) { super(Prec.COND); - this.cond = cond.prec() < Prec.COND ? new ParenJExpr(cond) : cond; - this.ifTrue = ifTrue.prec() < Prec.COND ? new ParenJExpr(ifTrue) : ifTrue; - this.ifFalse = ifFalse.prec() < Prec.COND ? new ParenJExpr(ifFalse) : ifFalse; + this.cond = cond.prec() > Prec.COND ? new ParenJExpr(cond) : cond; + this.ifTrue = ifTrue.prec() > Prec.COND ? new ParenJExpr(ifTrue) : ifTrue; + this.ifFalse = ifFalse.prec() > Prec.COND ? new ParenJExpr(ifFalse) : ifFalse; } public void write(final SourceFileWriter writer) throws IOException { diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/FieldRefJExpr.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/FieldRefJExpr.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/FieldRefJExpr.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/FieldRefJExpr.java 2016-04-18 17:39:15.000000000 +0000 @@ -32,7 +32,7 @@ FieldRefJExpr(final AbstractJExpr expr, final String refName) { super(Prec.MEMBER_ACCESS); - this.expr = expr; + this.expr = expr.prec() > prec() ? new ParenJExpr(expr) : expr; this.refName = refName; } diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/ForEachJBlock.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/ForEachJBlock.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/ForEachJBlock.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/ForEachJBlock.java 2016-04-18 17:39:15.000000000 +0000 @@ -48,6 +48,7 @@ writer.write(FormatPreferences.Space.WITHIN_PAREN_FOR); JMod.write(writer, mods); writer.write(type); + writer.sp(); writer.writeEscaped(name); writer.write(FormatPreferences.Space.BEFORE_COLON); writer.write($PUNCT.COLON); diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/FormatPreferences.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/FormatPreferences.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/FormatPreferences.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/FormatPreferences.java 2016-04-18 17:39:15.000000000 +0000 @@ -531,6 +531,7 @@ */ public enum Space { // default for all parens + @Deprecated BEFORE_PAREN, // single-line statements @@ -550,6 +551,7 @@ BEFORE_PAREN_CAST, // default for all binary operators + @Deprecated AROUND_OPERATORS, // specific operator categories diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/ImplJSourceFile.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/ImplJSourceFile.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/ImplJSourceFile.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/ImplJSourceFile.java 2016-04-18 17:39:15.000000000 +0000 @@ -31,7 +31,7 @@ */ class ImplJSourceFile extends BasicJCommentable implements JSourceFile { private final ImplJSources sources; - private final Map imports = new HashMap<>(); + private final Map imports = new HashMap<>(); private final Map staticImports = new HashMap<>(); private final ArrayList content = new ArrayList<>(); private final String packageName; @@ -58,36 +58,32 @@ writer.writeEscaped(packageName); writer.write($PUNCT.SEMI); writer.nl(); - final Map imports = ImplJSourceFile.this.imports; - if (imports != null) { - final Iterator iterator = imports.values().iterator(); - if (iterator.hasNext()) { + final Map imports = ImplJSourceFile.this.imports; + final Iterator iterator = imports.values().iterator(); + if (iterator.hasNext()) { + writer.nl(); + do { + final AbstractJType _import = iterator.next(); + writer.write($KW.IMPORT); + writer.writeClass(_import.qualifiedName()); + writer.write($PUNCT.SEMI); writer.nl(); - do { - final ReferenceJType _import = iterator.next(); - writer.write($KW.IMPORT); - writer.writeClass(_import.qualifiedName(writer)); - writer.write($PUNCT.SEMI); - writer.nl(); - } while (iterator.hasNext()); - writer.nl(); - } + } while (iterator.hasNext()); + writer.nl(); } final Map staticImports = ImplJSourceFile.this.staticImports; - if (staticImports != null) { - final Iterator iterator = staticImports.values().iterator(); - if (iterator.hasNext()) { - writer.nl(); - do { - final StaticRefJExpr staticImport = iterator.next(); - writer.write($KW.IMPORT); - writer.write($KW.STATIC); - writer.write(staticImport); - writer.write($PUNCT.SEMI); - writer.nl(); - } while (iterator.hasNext()); + final Iterator staticIterator = staticImports.values().iterator(); + if (staticIterator.hasNext()) { + writer.nl(); + do { + final StaticRefJExpr staticImport = staticIterator.next(); + writer.write($KW.IMPORT); + writer.write($KW.STATIC); + staticImport.writeForImport(writer); + writer.write($PUNCT.SEMI); writer.nl(); - } + } while (staticIterator.hasNext()); + writer.nl(); } } }); @@ -99,26 +95,17 @@ return imports.containsKey(name); } - boolean hasImport(final JType type, final SourceFileWriter writer) { - if (type instanceof ReferenceJType) { - ReferenceJType referenceJType = (ReferenceJType) type; - final String name = referenceJType.simpleName(); - if (imports.containsKey(name) && imports.get(name).qualifiedName(writer).equals(referenceJType.qualifiedName(writer))) { - return true; - } - } - return false; + boolean hasImport(final AbstractJType type) { + return type.equals(imports.get(type.simpleName())); } boolean hasStaticImport(final String name) { return staticImports.containsKey(name); } - boolean hasStaticImport(final JExpr expr, final SourceFileWriter writer) { - if (! (expr instanceof StaticRefJExpr)) return false; - final StaticRefJExpr staticRefJExpr = (StaticRefJExpr) expr; - final String refName = staticRefJExpr.getRefName(); - return staticImports.containsKey(refName) && staticImports.get(refName).getType().qualifiedName(writer).equals(staticRefJExpr.getType().qualifiedName(writer)); + boolean hasStaticImport(final String name, final AbstractJType enclosingType) { + final StaticRefJExpr expr = staticImports.get(name); + return expr != null && enclosingType.equals(expr.getType()); } public JSourceFile _import(final String type) { @@ -126,14 +113,16 @@ } public JSourceFile _import(final JType type) { - checkPackage(); - if (! (type instanceof ReferenceJType)) { + if (! (type instanceof ReferenceJType) && ! (type instanceof NestedJType)) { + // can't import this type return this; } if (imports.containsKey(type.simpleName())) { + // already imported return this; } - imports.put(type.simpleName(), (ReferenceJType) type); + checkPackage(); + imports.put(type.simpleName(), (AbstractJType) type); return this; } @@ -146,6 +135,14 @@ } public JSourceFile importStatic(final JType type, final String member) { + if (! (type instanceof ReferenceJType) && ! (type instanceof NestedJType)) { + // no static members + return this; + } + if (staticImports.containsKey(member)) { + // already imported + return this; + } checkPackage(); staticImports.put(member, new StaticRefJExpr(AbstractJType.of(type), member)); return this; diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/InnerJAnonymousClassDef.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/InnerJAnonymousClassDef.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/InnerJAnonymousClassDef.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/InnerJAnonymousClassDef.java 2016-04-18 17:39:15.000000000 +0000 @@ -28,7 +28,7 @@ InnerJAnonymousClassDef(final AbstractJExpr expr, final JType type) { super(type); - this.expr = expr; + this.expr = expr.prec() > prec() ? new ParenJExpr(expr) : expr; } public void write(final SourceFileWriter writer) throws IOException { diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/InnerNewJCall.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/InnerNewJCall.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/InnerNewJCall.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/InnerNewJCall.java 2016-04-18 17:39:15.000000000 +0000 @@ -31,7 +31,7 @@ InnerNewJCall(final AbstractJExpr target, final JType type) { super(AbstractJType.of(type)); - this.target = target; + this.target = target.prec() > prec() ? new ParenJExpr(target) : target; } public void write(final SourceFileWriter writer) throws IOException { diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/InstanceJCall.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/InstanceJCall.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/InstanceJCall.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/InstanceJCall.java 2016-04-18 17:39:15.000000000 +0000 @@ -29,9 +29,9 @@ private final JExpr target; - InstanceJCall(final JExpr target, final String name) { + InstanceJCall(final AbstractJExpr target, final String name) { super(name); - this.target = target; + this.target = target.prec() > prec() ? new ParenJExpr(target) : target; } JExpr getTarget() { diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/JClassItem.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/JClassItem.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/JClassItem.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/JClassItem.java 2016-04-18 17:39:15.000000000 +0000 @@ -28,6 +28,7 @@ * * @author David M. Lloyd */ +@Deprecated public interface JClassItem { /** @@ -35,6 +36,7 @@ * * @return the item kind */ + @Deprecated Kind getItemKind(); /** @@ -43,6 +45,7 @@ * @return the modifiers * @see JMod */ + @Deprecated int getModifiers(); /** @@ -51,6 +54,7 @@ * @param mods the modifier(s) * @return {@code true} if all of the modifiers are present, {@code false} otherwise */ + @Deprecated boolean hasAllModifiers(int mods); /** @@ -59,6 +63,7 @@ * @param mods the modifier(s) * @return {@code true} if any if the modifiers are present, {@code false} otherwise */ + @Deprecated boolean hasAnyModifier(int mods); /** @@ -66,8 +71,10 @@ * * @return the name, or {@code null} if there is none */ + @Deprecated String getName(); + @Deprecated Comparator SMART_NAME_SORT = new Comparator() { private int rankOf(JClassItem item) { return item.getItemKind().ordinal(); @@ -138,6 +145,7 @@ /** * The kind of class item. */ + @Deprecated enum Kind { /** * A line comment. The item will implement {@link JComment}. diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/JExprs.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/JExprs.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/JExprs.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/JExprs.java 2016-04-18 17:39:15.000000000 +0000 @@ -193,7 +193,7 @@ * @return the method call */ public static JCall callStatic(final JType type, final String name) { - return new StaticJCall(type, name); + return new StaticJCall(AbstractJType.of(type), name); } /** diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/JLambdaImpl.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/JLambdaImpl.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/JLambdaImpl.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/JLambdaImpl.java 2016-04-18 17:39:15.000000000 +0000 @@ -75,11 +75,16 @@ } public void write(final SourceFileWriter writer) throws IOException { - writer.write(Tokens.$PUNCT.PAREN.OPEN); if (params == null) { + writer.write(Tokens.$PUNCT.PAREN.OPEN); writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_CALL_EMPTY); + writer.write(Tokens.$PUNCT.PAREN.CLOSE); } else { - writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_CALL); + final boolean singleParam = params.size() == 1 && hasInferred; + if (! singleParam) { + writer.write(Tokens.$PUNCT.PAREN.OPEN); + writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_CALL); + } final Iterator iterator = params.iterator(); while (iterator.hasNext()) { final Param param = iterator.next(); @@ -93,9 +98,11 @@ writer.write(FormatPreferences.Space.AFTER_COMMA); } } - writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_CALL); + if (! singleParam) { + writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_CALL); + writer.write(Tokens.$PUNCT.PAREN.CLOSE); + } } - writer.write(Tokens.$PUNCT.PAREN.CLOSE); writer.write(FormatPreferences.Space.AROUND_ARROW); writer.write(Tokens.$PUNCT.BINOP.ARROW); writer.write(FormatPreferences.Space.AROUND_ARROW); diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/NarrowedJType.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/NarrowedJType.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/NarrowedJType.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/NarrowedJType.java 2016-04-18 17:39:15.000000000 +0000 @@ -36,6 +36,18 @@ this.args = args; } + boolean equals(final AbstractJType other) { + return other instanceof NarrowedJType && equals((NarrowedJType) other); + } + + private boolean equals(final NarrowedJType other) { + return erased.equals(other.erased) && Arrays.equals(args, other.args); + } + + public int hashCode() { + return erased.hashCode() * 17 + Arrays.hashCode(args); + } + public String simpleName() { return erased.simpleName(); } diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/NestedJType.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/NestedJType.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/NestedJType.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/NestedJType.java 2016-04-18 17:39:15.000000000 +0000 @@ -39,6 +39,10 @@ this.name = name; } + String qualifiedName() { + return enclosingType.qualifiedName() + "." + name; + } + public JExpr _class() { StaticRefJExpr expr = classExpr; if (expr == null) { @@ -71,6 +75,18 @@ return new ImplJAnonymousClassDef(this); } + boolean equals(final AbstractJType other) { + return other instanceof NestedJType && equals((NestedJType) other); + } + + private boolean equals(final NestedJType other) { + return enclosingType.equals(other.enclosingType) && name.equals(other.name); + } + + public int hashCode() { + return enclosingType.hashCode() * 17 + name.hashCode(); + } + public String simpleName() { return name; } @@ -96,8 +112,10 @@ } void writeDirect(final SourceFileWriter writer) throws IOException { - enclosingType.writeDirect(writer); - writer.write($PUNCT.DOT); + if (! writer.getClassFile().hasStaticImport(name, enclosingType) && ! writer.getClassFile().hasImport(this)) { + enclosingType.writeDirect(writer); + writer.write($PUNCT.DOT); + } writer.writeClass(name); } } diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/PrimitiveJType.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/PrimitiveJType.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/PrimitiveJType.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/PrimitiveJType.java 2016-04-18 17:39:15.000000000 +0000 @@ -62,6 +62,14 @@ return expr; } + boolean equals(final AbstractJType other) { + return other instanceof PrimitiveJType && simpleName.equals(((PrimitiveJType) other).simpleName); + } + + public int hashCode() { + return simpleName.hashCode(); + } + public String simpleName() { return simpleName; } diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/ReferenceJType.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/ReferenceJType.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/ReferenceJType.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/ReferenceJType.java 2016-04-18 17:39:15.000000000 +0000 @@ -54,7 +54,7 @@ } @Override - String qualifiedName(final SourceFileWriter writer) { + String qualifiedName() { if (packageName.isEmpty()) { return simpleName; } @@ -107,15 +107,15 @@ final boolean packageMatches = currentPackageName.equals(packageName); if (packageMatches && cf.hasImport(simpleName())) { // an explicit import masks the implicit import - sourceFileWriter.writeClass(qualifiedName(sourceFileWriter)); + sourceFileWriter.writeClass(qualifiedName()); } else if (packageName.equals("java.lang") && ! sourceFileWriter.getClassFile().getSources().hasClass(currentPackageName + "." + simpleName()) || packageMatches) { // implicit import sourceFileWriter.writeClass(simpleName()); - } else if (cf.hasImport(simpleName())) { + } else if (cf.hasImport(this)) { // explicit import sourceFileWriter.writeClass(simpleName()); } else { - sourceFileWriter.writeClass(qualifiedName(sourceFileWriter)); + sourceFileWriter.writeClass(qualifiedName()); } } @@ -136,6 +136,18 @@ return nestedType; } + boolean equals(final AbstractJType other) { + return other instanceof ReferenceJType && equals((ReferenceJType) other); + } + + private boolean equals(final ReferenceJType other) { + return packageName.equals(other.packageName) && simpleName.equals(other.simpleName); + } + + public int hashCode() { + return packageName.hashCode() * 17 + simpleName.hashCode(); + } + public String toString() { return "Reference of type " + simpleName(); } diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/SourceFileWriter.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/SourceFileWriter.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/SourceFileWriter.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/SourceFileWriter.java 2016-04-18 17:39:15.000000000 +0000 @@ -83,7 +83,8 @@ private static final int SS_NONE = 0; private static final int SS_NEEDED = 1; private static final int SS_ADDED = 2; - private static final int SS_NEEDS_INDENT = 3; + private static final int SS_NEW_LINE = 3; + private static final int SS_2_NEW_LINE = 4; SourceFileWriter(final FormatPreferences format, final Writer writer) { this.format = format; @@ -96,7 +97,7 @@ countingWriter.write(lineBuffer); countingWriter.write(lineSep); lineBuffer.setLength(0); - spaceState = SS_NEEDS_INDENT; + spaceState = spaceState == SS_NEW_LINE ? SS_2_NEW_LINE : SS_NEW_LINE; } /** @@ -105,7 +106,7 @@ * @throws IOException etc. */ void sp() throws IOException { - if (spaceState == SS_NEEDS_INDENT) { + if (spaceState == SS_NEW_LINE || spaceState == SS_2_NEW_LINE) { addIndent(); } else if (spaceState != SS_ADDED) { spaceState = SS_ADDED; @@ -130,7 +131,8 @@ void processSpacing() throws IOException { switch (spaceState) { - case SS_NEEDS_INDENT: { + case SS_2_NEW_LINE: + case SS_NEW_LINE: { nextIndent.addIndent(nextIndent, format, lineBuffer); spaceState = SS_ADDED; break; @@ -143,7 +145,7 @@ } void addIndent() throws IOException { - assert spaceState == SS_NEEDS_INDENT; // it was a new line + assert spaceState == SS_NEW_LINE || spaceState == SS_2_NEW_LINE; // it was a new line nextIndent.addIndent(nextIndent, format, lineBuffer); spaceState = SS_ADDED; } @@ -185,8 +187,8 @@ return; } if (format.getSpaceType(rule) == FormatPreferences.SpaceType.NEWLINE) { - if (spaceState != SS_NEEDS_INDENT) { - // must not be directly after a newline + if (spaceState != SS_2_NEW_LINE) { + // must not be directly after a 2-newline nl(); } } else { diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/SourceWriter.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/SourceWriter.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/SourceWriter.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/SourceWriter.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,29 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2014 Red Hat, Inc., and individual contributors - * as indicated by the @author tags. - * - * 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 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jboss.jdeparser; - -import java.io.IOException; - -/** - * @author David M. Lloyd - */ -abstract class SourceWriter { - - abstract void writeRaw(int ch) throws IOException; -} diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/StaticJCall.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/StaticJCall.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/StaticJCall.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/StaticJCall.java 2016-04-18 17:39:15.000000000 +0000 @@ -27,20 +27,22 @@ */ class StaticJCall extends AbstractMethodJCall { - private final JType type; + private final AbstractJType type; - StaticJCall(final JType type, final String name) { + StaticJCall(final AbstractJType type, final String name) { super(name); this.type = type; } - JType getType() { + AbstractJType getType() { return type; } public void write(final SourceFileWriter writer) throws IOException { - writer.write(AbstractJType.of(type)); - writer.write($PUNCT.DOT); + if (! writer.getClassFile().hasStaticImport(getName(), type)) { + type.writeDirect(writer); + writer.write($PUNCT.DOT); + } super.write(writer); } } diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/StaticRefJExpr.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/StaticRefJExpr.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/StaticRefJExpr.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/StaticRefJExpr.java 2016-04-18 17:39:15.000000000 +0000 @@ -51,7 +51,16 @@ } public void write(final SourceFileWriter writer) throws IOException { - writer.write(type); + if (! writer.getClassFile().hasStaticImport(refName, type)) { + type.writeDirect(writer); + writer.write($PUNCT.DOT); + } + writer.writeEscaped(refName); + } + + void writeForImport(final SourceFileWriter writer) throws IOException { + writer.processSpacing(); + writer.writeClass(type.qualifiedName()); writer.write($PUNCT.DOT); writer.writeEscaped(refName); } diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/ThisJType.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/ThisJType.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/ThisJType.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/ThisJType.java 2016-04-18 17:39:15.000000000 +0000 @@ -28,6 +28,14 @@ ThisJType() { } + boolean equals(final AbstractJType other) { + return other instanceof ThisJType; + } + + public int hashCode() { + return 23; + } + public String simpleName() { return "<>"; } diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/Tokens.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/Tokens.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/Tokens.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/Tokens.java 2016-04-18 17:39:15.000000000 +0000 @@ -143,7 +143,7 @@ ASSIGN_LSHR(">>>=", Space.AROUND_ASSIGN), ASSIGN_SHL("<<=", Space.AROUND_ASSIGN), - DBL_COLON("::", null), + DBL_COLON("::", Space.AROUND_METHOD_REF), ARROW("->", Space.AROUND_ARROW), ; diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/UnaryJExpr.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/UnaryJExpr.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/UnaryJExpr.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/UnaryJExpr.java 2016-04-18 17:39:15.000000000 +0000 @@ -57,9 +57,11 @@ public void write(final SourceFileWriter writer) throws IOException { if (isPostfix()) { writer.write(expr); + writer.write(FormatPreferences.Space.AT_UNARY); writer.write(op); } else { writer.write(op); + writer.write(FormatPreferences.Space.AT_UNARY); writer.write(expr); } } diff -Nru jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/WildcardJType.java jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/WildcardJType.java --- jboss-jdeparser2-2.0.0/src/main/java/org/jboss/jdeparser/WildcardJType.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/main/java/org/jboss/jdeparser/WildcardJType.java 2016-04-18 17:39:15.000000000 +0000 @@ -35,6 +35,18 @@ this.extendsNotSuper = extendsNotSuper; } + boolean equals(final AbstractJType other) { + return other instanceof WildcardJType && equals((WildcardJType) other); + } + + private boolean equals(final WildcardJType other) { + return extendsNotSuper == other.extendsNotSuper && targetType.equals(other.targetType); + } + + public int hashCode() { + return targetType.hashCode() ^ (extendsNotSuper ? 0 : 1); + } + public String simpleName() { return targetType.simpleName(); } @@ -55,13 +67,20 @@ void writeDirect(final SourceFileWriter sourceFileWriter) throws IOException { sourceFileWriter.write($PUNCT.Q); - sourceFileWriter.sp(); - sourceFileWriter.write(extendsNotSuper ? $KW.EXTENDS : $KW.SUPER); - sourceFileWriter.write(getTargetType()); + final AbstractJType targetType = getTargetType(); + if (! targetType.equals(JType.OBJECT)) { + sourceFileWriter.sp(); + sourceFileWriter.write(extendsNotSuper ? $KW.EXTENDS : $KW.SUPER); + sourceFileWriter.write(targetType); + } } public String toString() { - return "? " + (extendsNotSuper ? "extends " : "super ") + targetType; + if (extendsNotSuper && targetType.equals(JType.OBJECT)) { + return "?"; + } else { + return "? " + (extendsNotSuper ? "extends " : "super ") + targetType; + } } AbstractJType getTargetType() { diff -Nru jboss-jdeparser2-2.0.0/src/test/java/org/jboss/jdeparser/SimpleExampleTestCase.java jboss-jdeparser2-2.0.2/src/test/java/org/jboss/jdeparser/SimpleExampleTestCase.java --- jboss-jdeparser2-2.0.0/src/test/java/org/jboss/jdeparser/SimpleExampleTestCase.java 2015-03-11 15:46:42.000000000 +0000 +++ jboss-jdeparser2-2.0.2/src/test/java/org/jboss/jdeparser/SimpleExampleTestCase.java 2016-04-18 17:39:15.000000000 +0000 @@ -63,6 +63,10 @@ jIf.assign(JExprs.$v(t), str("new Value")); jIf._else().assign(JExprs.$v(t), str("other value")); + // static import and reference + body.call(JTypes.$t(Thread.State.class).$v("NEW"), "toString"); + bazFile.importStatic(Thread.State.class, "NEW"); + // Reference an enclosing class body.var(0, JTypes.$t(Map.Entry.class).typeArg(String.class, Object.class), "mapEntry", JExpr.NULL); bazFile._import(Map.class);