001 /* Copyright (c) 2015, Jesper Öqvist <jesper.oqvist@cs.lth.se> 002 * All rights reserved. 003 * 004 * Redistribution and use in source and binary forms, with or without 005 * modification, are permitted provided that the following conditions are met: 006 * 007 * 1. Redistributions of source code must retain the above copyright notice, 008 * this list of conditions and the following disclaimer. 009 * 010 * 2. Redistributions in binary form must reproduce the above copyright notice, 011 * this list of conditions and the following disclaimer in the documentation 012 * and/or other materials provided with the distribution. 013 * 014 * 3. Neither the name of the copyright holder nor the names of its 015 * contributors may be used to endorse or promote products derived from this 016 * software without specific prior written permission. 017 * 018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 021 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 022 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 028 * POSSIBILITY OF SUCH DAMAGE. 029 */ 030 031 /** 032 * This is a generated aspect for pretty-printing Java programs. 033 */ 034 aspect Java8PrettyPrint { 035 public void InferredParameterDeclaration.prettyPrint(PrettyPrinter out) { 036 out.print(name()); 037 } 038 public void ExprLambdaBody.prettyPrint(PrettyPrinter out) { 039 out.print(getExpr()); 040 } 041 public void DeclaredLambdaParameters.prettyPrint(PrettyPrinter out) { 042 out.print("("); 043 out.join(getParameters(), new PrettyPrinter.Joiner() { 044 @Override 045 public void printSeparator(PrettyPrinter out) { 046 out.print(", "); 047 } 048 }); 049 out.print(")"); 050 } 051 public void BlockLambdaBody.prettyPrint(PrettyPrinter out) { 052 out.print(getBlock()); 053 } 054 public void InferredLambdaParameters.prettyPrint(PrettyPrinter out) { 055 out.print("("); 056 out.join(getParameters(), new PrettyPrinter.Joiner() { 057 @Override 058 public void printSeparator(PrettyPrinter out) { 059 out.print(", "); 060 } 061 }); 062 out.print(")"); 063 } 064 public void LambdaExpr.prettyPrint(PrettyPrinter out) { 065 out.print(getLambdaParameters()); 066 out.print(" -> "); 067 out.print(getLambdaBody()); 068 } 069 public void ClassReference.prettyPrint(PrettyPrinter out) { 070 out.print(getTypeAccess()); 071 out.print("::"); 072 if (hasTypeArgument()) { 073 out.print("<"); 074 out.join(getTypeArguments(), new PrettyPrinter.Joiner() { 075 @Override 076 public void printSeparator(PrettyPrinter out) { 077 out.print(", "); 078 } 079 }); 080 out.print(">"); 081 } 082 out.print("new"); 083 } 084 public void ArrayReference.prettyPrint(PrettyPrinter out) { 085 out.print(getTypeAccess()); 086 out.print("::new"); 087 } 088 public void ExprMethodReference.prettyPrint(PrettyPrinter out) { 089 out.print(getExpr()); 090 out.print("::"); 091 if (hasTypeArgument()) { 092 out.print("<"); 093 out.join(getTypeArguments(), new PrettyPrinter.Joiner() { 094 @Override 095 public void printSeparator(PrettyPrinter out) { 096 out.print(", "); 097 } 098 }); 099 out.print(">"); 100 } 101 out.print(name()); 102 } 103 public void TypeMethodReference.prettyPrint(PrettyPrinter out) { 104 out.print(getTypeAccess()); 105 out.print("::"); 106 if (hasTypeArgument()) { 107 out.print("<"); 108 out.join(getTypeArguments(), new PrettyPrinter.Joiner() { 109 @Override 110 public void printSeparator(PrettyPrinter out) { 111 out.print(", "); 112 } 113 }); 114 out.print(">"); 115 } 116 out.print(name()); 117 } 118 public void IntersectionCastExpr.prettyPrint(PrettyPrinter out) { 119 out.print("("); 120 out.print(getTypeAccess()); 121 if (hasTypeList()) { 122 out.print(" & "); 123 out.join(getTypeLists(), new PrettyPrinter.Joiner() { 124 @Override 125 public void printSeparator(PrettyPrinter out) { 126 out.print(" & "); 127 } 128 }); 129 } 130 out.print(") "); 131 out.print(getExpr()); 132 } 133 }