|
Java example source code file (JavaLang.java)
The JavaLang.java Java example source code/* * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.apple.internal.jobjc.generator.utils; import java.io.StringWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Set; import java.util.TreeSet; import com.apple.internal.jobjc.generator.Utils; import com.apple.internal.jobjc.generator.Utils.Substituter; /** * Utility for generating Java source code. */ public abstract class JavaLang { public static String makeSingleton(final String instanceVariable, final String methodName, final String className, final String...constructorArgs) { return generateSingleton(new Substituter( "#private $CLASS $IVAR = null;~" + "#public $CLASS $METHOD() {~" + "##return $IVAR != null ? $IVAR : ($IVAR = new $CLASS($CTORARGS));~" + "#}~"), instanceVariable, methodName, className, constructorArgs); } public static String makeStaticSingleton(final String instanceVariable, final String methodName, final String className, final String...constructorArgs) { return generateSingleton(new Substituter( "#private static $CLASS $IVAR = null;~" + "#public static $CLASS $METHOD() {~" + "##return $IVAR != null ? $IVAR : ($IVAR = new $CLASS($CTORARGS));~" + "#}~"), instanceVariable, methodName, className, constructorArgs); } private static String generateSingleton(final Substituter singleton, final String instanceVariable, final String methodName, final String className, final String...constructorArgs) { singleton.replace("IVAR", instanceVariable); singleton.replace("METHOD", methodName); singleton.replace("CLASS", className); singleton.replace("CTORARGS", Utils.joinWComma(constructorArgs)); return singleton.toString(); } /// public static class JLTertiary{ public Object cond, tExp, fExp; public JLTertiary(){} public JLTertiary(Object cond, Object tExp, Object fExp){ this.cond = cond; this.tExp = tExp; this.fExp = fExp; } @Override public String toString() { return "((" + cond + ")\n\t? (" + tExp + ")\n\t: (" + fExp + "))"; } } public static class JLCall{ public String fun; public List<Object> args = new ArrayList |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.