// From:
// http://blog.efftinge.de/2008/10/multi-line-string-literals-in-java.html
// Takes a comment (/**/) and turns everything inside the comment to a string
// that is returned from S()
public static String S()
{
StackTraceElement element = new RuntimeException().getStackTrace()[1];
String name = element.getClassName().replace('.', '/') + ".java";
StringBuilder sb = new StringBuilder();
String line = null;
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream in = classLoader.getResourceAsStream(name);
String s = convertStreamToString(in, element.getLineNumber());
return s.substring(s.indexOf("/*") + 2, s.indexOf("*/"));
}
// From http://www.kodejava.org/examples/266.html
private static String convertStreamToString(InputStream is, int lineNum)
{
/*
* To convert the InputStream to String we use the BufferedReader.readLine()
* method. We iterate until the BufferedReader return null which means
* there's no more data to read. Each line will appended to a StringBuilder
* and returned as String.
*/
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
int i = 1;
try
{
while ((line = reader.readLine()) != null)
{
if (i++ >= lineNum)
{
sb.append(line + "\n");
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
is.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
return sb.toString();
}
public static void main(String[] args) throws Exception
{
String s = S(/*
Wow, we finally have
multiline strings in
Java! HOOO!
*/);
System.out.println(s);
}
class Simple
{
private int a = 0;
public void add(int b)
{
a = a + b;
}
public int getA()
{
return a;
}
}
class Difficult
{
private int a = 0;
public void add(int b)
{
if ((float)(a % 100) / 3 == (int)((a % 100) / 3) )
a = a + b;
else
a = a - b;
}
public int getA()
{
return a;
}
}
class D
{
var param1: boolean;
var param2: boolean;
function func1(...)
{
.........
if (param2)
param1 = abc;
else
param1 = xyz;
.........
}
function func2(...)
{
.........
if (param1 && asd)
param2 = ...;
...........
}
}
[380x239]
[650x155]