Skip to content

Instantly share code, notes, and snippets.

View edefazio's full-sized avatar
🙂
Focusing

edefazio

🙂
Focusing
View GitHub Profile
@edefazio
edefazio / example._draft_2_$macro.java
Created July 2, 2018 23:23
Demonstrate using $macros to modify _draft models to automate boilerplate
package example;
import draft.java.*;
import draft.java.file._export;
import draft.java.macro.*;
import junit.framework.TestCase;
import java.util.*;
public class _draft_2_$macro extends TestCase {
@edefazio
edefazio / tutorial._draft_2_$macro.java
Created July 2, 2018 23:34
demonstrate using $macros to modify _class models and reduce boilerplate code
package tutorial;
import draft.java.*;
import draft.java.file._export;
import draft.java.macro.*;
import junit.framework.TestCase;
import java.util.*;
/**
@edefazio
edefazio / draftJava.jsh
Created August 21, 2018 00:38
JShell script for generating (and exporting) Java code using the draft API
/env --module-path C:\temp\jars\draft.jar;C:\temp\jars\javaparser-core-3.6.14.jar; --add-modules draft
import draft.java.*;
import draft.java.auto.*;
_class _c = _class.of("draftshell.gen.Point").fields("int x,y");
_autoDto.to(_c);
_out.to("C:\\temp", _c);
@edefazio
edefazio / draft.tutorial.usecase.JavaPoet_v_draft.java
Last active February 19, 2019 18:38
compare the JavaPoet and draft.java APIs for generating .java code
package draft.tutorial.usecase;
import com.squareup.javapoet.*;
import draft.java.*;
import draft.java.macro.*;
import draft.java.runtime.*;
import draft.java.template.$method;
import java.io.IOException;
import java.util.*;
import javax.lang.model.element.Modifier;
@edefazio
edefazio / com.squareup.javapoet.adhoc.JavaPoetAdhocTest.java
Last active June 16, 2019 20:12
build JavaPoet models and compile / load and use dynamic instances at runtime with Adhoc
package com.squareup.javapoet.adhoc;
import com.squareup.javapoet.*;
import javax.lang.model.element.Modifier;
import junit.framework.TestCase;
import run.adhoc.*;
/**
* Show how to work with the JavaPoetAdhoc abstraction, to compile/load and
* use dynamically build code from JavaPoet models.
@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
*
@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 / 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 / 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 / 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