Skip to content

Instantly share code, notes, and snippets.

View edefazio's full-sized avatar
🙂
Focusing

edefazio

🙂
Focusing
View GitHub Profile
@edefazio
edefazio / lut.LutBuilderTest.java
Created December 18, 2019 15:46
Example of building a Lookup table at runtime from a Map (implemented as a Switch statement)
package lut;
import junit.framework.TestCase;
import java.util.HashMap;
import java.util.Map;
public class LutBuilderTest extends TestCase {
/**
@edefazio
edefazio / lut.LutBuilder.java
Created December 18, 2019 15:44
Build Compile and Load Java code for a LookupTable (implemented as a Switch statement) at runtime from a Map
package lut;
import org.jdraft._class;
import org.jdraft._method;
import org.jdraft.pattern.$case;
import org.jdraft.pattern.$method;
import org.jdraft.runtime._runtime;
import org.jdraft.text.Stencil;
import org.jdraft.text.Translator;
@edefazio
edefazio / use.jdraft.lut.LutBuilderTest.java
Created December 17, 2019 21:39
Using the LutBuilder to statically generate code & compile & use a LookupTable Class replacing a Map lookup with switch code
package use.jdraft.lut;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
public class LutBuilderTest extends TestCase {
//this will house the Lut
@edefazio
edefazio / use.jdraft.lut.LutBuilder.java
Created December 17, 2019 21:36
Use case for building dynamic Java Code at runtime which represents a LookupTable implemented via switch statements
package use.jdraft.lut;
import java.util.Map;
import org.mrcode.Translator;
import org.mrcode.java.Stmt;
import org.mrcode.java._class;
import org.mrcode.java._method;
import org.mrcode.java.pattern.$case;
import org.mrcode.java.pattern.$method;
@edefazio
edefazio / use.jdraft.lut.Lut.java
Created December 17, 2019 21:31
Interfaces for Lookup Tables...(so we can use dynamically built classes can implement at runtime)
package use.jdraft.lut;
/**
* Realized Lookup Table (Lut)
* Switch lookup table
*
* @author Eric
*
*/
public interface Lut {
@edefazio
edefazio / test.othertools.JavaParserLucaAccumulateTest.java
Last active October 15, 2019 14:50
jdraft metaprogramming example following the JavaParser Example presented by Luca Molteni
package test.othertools;
import junit.framework.TestCase;
import org.jdraft._method;
import org.jdraft.pattern.$typeRef;
/**
* Luca Molteni presented an example at the Voxxed Days Ticino 2019
* https://youtu.be/1pSj6OQsq9k?list=PLRsbF2sD7JVorYibvQrrG34UQ6YE3PaVP&t=2214
* replaced using jdraft API
@edefazio
edefazio / test.othertools.JavaParserLucaReplace2Test.java
Last active October 15, 2019 13:49
jdraft metaprogramming example built from Voxxed Days Ticino 2019
package test.othertools;
import junit.framework.TestCase;
import org.jdraft._class;
import org.jdraft._method;
import org.jdraft.pattern.$method;
import org.jdraft.runtime._proxy;
/**
* A Rewrite taken from the presentation at Voxxed Days Ticino 2019 by Luca Molteni
@edefazio
edefazio / use.jdraft.BuildAndUseTest.java
Created August 7, 2019 15:08
Using jdraft to dynamically build and create / use objects
import org.jdraft.*;
import org.jdraft.adhoc.*;
import org.jdraft.macro.*;
import java.net.UUID;
public class BuildAndUseTest extends TestCase {
public void testBuildAndUseModel(){
@edefazio
edefazio / org.jdraft.mr.PosUtil.java
Created August 4, 2019 18:22
Recalculating the positions after adding things to a compilationUnit
package org.jdraft.mr;
import com.github.javaparser.*;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node;
import com.github.javaparser.utils.PositionUtils;
import junit.framework.TestCase;
import org.jdraft._field;
import org.jdraft._method;
@edefazio
edefazio / com.squareup.javapoet.adhoc.JavaPoetAdhoc.java
Created June 16, 2019 20:09
Integrate JavaPoet with AdHoc to make compiling loading and using dynamic JavaPoet models easy
package com.squareup.javapoet.adhoc;
import com.squareup.javapoet.JavaFile;
import run.adhoc.*;
/**
* Adapts JavaPoet's {@link JavaFile} code model to the {@link javax.tools.JavaCompiler}
* infrastructure through Adhocs {@link CodeModelFile}. We want to reduce the
* friction for compiling / loading and using the Java source code models
*