All Downloads are FREE. Search and download functionalities are using the official Maven repository.

spoon.pattern.Generator Maven / Gradle / Ivy

Go to download

Spoon is a tool for meta-programming, analysis and transformation of Java programs.

There is a newer version: 11.1.1-beta-14
Show newest version
/*
 * SPDX-License-Identifier: (MIT OR CECILL-C)
 *
 * Copyright (C) 2006-2023 INRIA and contributors
 *
 * Spoon is available either under the terms of the MIT License (see LICENSE-MIT.txt) or the Cecill-C License (see LICENSE-CECILL-C.txt). You as the user are entitled to choose the terms under which to adopt Spoon.
 */
package spoon.pattern;

import java.util.List;
import java.util.Map;

import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.CtType;
import spoon.reflect.factory.Factory;
import spoon.support.Experimental;
import spoon.support.util.ImmutableMap;

/**
 * Generates code from patterns. The core idea is to replace pattern parameters by objects.
 */
@Experimental
public interface Generator {
	/**
	 * @return a {@link Factory}, which has to be used to generate instances
	 */
	Factory getFactory();


	/**
	 * Main method to generate a new AST made from substituting of parameters by
	 * the values in `params`
	 * @param params - the substitution parameters, it can be CtElement, primitive literals like String, Integer, ... and or List or Set of them.
	 * @return List of generated elements
	 */
	 List generate(Map params);

	/** Utility method that provides the same feature as {@link #generate(Map)}, but with a {@link ImmutableMap} as parameter (a Spoon elegant utility type) */
	 List generate(ImmutableMap params);

	/**
	 * Generates a type with qualified name `typeQualifiedName`
	 * by replacing the generator parameters with the arguments given in `params`.
	 *
	 * Note: the root element of pattern must be a CtType.
	 *
	 * @param typeQualifiedName the qualified name of to be generated type
	 * @param params the pattern parameters
	 * @return the generated type
	 */
	> T generate(String typeQualifiedName, Map params);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy