Skip to content
This repository was archived by the owner on Oct 26, 2026. It is now read-only.

Add type shortcut parsing to type value in @implNote annotations - #102

Merged
hinerm merged 2 commits into
mainfrom
scijava/scijava-ops-engine/parse-type-shortcuts
Dec 13, 2023
Merged

hinerm merged 2 commits into
mainfrom
scijava/scijava-ops-engine/parse-type-shortcuts

Conversation

@gselzer

@gselzer gselzer commented Dec 12, 2023

Copy link
Copy Markdown
Member

This PR allows you to write the below class and call the internal Ops. Note that the absence of a type parameter in Function Ops worked before - now, you can write type=Computer or type=InplaceX (and type=Function, if you really want) instead of typing out the whole op class name. The arity of those types will be pulled off of the method.

For example, if you annotate a 5-parameter inplace Op with type=Inplace3, the Op will become a Inplaces.Arity5_3

/**
 * A static {@link Method}, exposed to Ops via YAML
 * 
 * @author Gabriel Selzer
 */
public class YAMLMethodOp {

	/**
	 * An example Op, implemented by a {@link Method}
	 *
	 * @implNote op name=example.sub
	 * @param aDouble the first double
	 * @param aDouble2 the second double
	 * @return the difference
	 */
	public static Double subtract(Double aDouble, Double aDouble2) {
		return aDouble - aDouble2;
	}

	/**
	 * Another example Op, implemented by a {@link Method}
	 *
	 * @implNote op name=example.xor, type=Inplace1
	 * @param aList the first integer {@link List}
	 * @param aList2 the second integer {@link List}
	 * @return the xor
	 */
	public static void xor(List<Integer> aList, List<Integer> aList2) {
		for(int i = 0; i < aList.size(); i++) {
			aList.set(i, aList.get(i) ^ aList2.get(i));
		}
	}

	/**
	 * A third example Op, implemented by a {@link Method}
	 *
	 * @implNote op name=example.and, type=Computer
	 * @param aList the first integer {@link List}
	 * @param aList2 the second integer {@link List}
	 * @param out the logical and of the two integer {@link List}s
	 */
	public static void and(List<Integer> aList, List<Integer> aList2, List<Integer> out) {
		out.clear();
		for(int i = 0; i < aList.size(); i++) {
			out.add(aList.get(i) & aList2.get(i));
		}
	}

}

Closes scijava/scijava#163

@gselzer gselzer added the enhancement New feature or request label Dec 12, 2023
@gselzer
gselzer requested a review from hinerm December 12, 2023 22:17
@gselzer gselzer self-assigned this Dec 12, 2023
@hinerm
hinerm force-pushed the scijava/scijava-ops-engine/parse-type-shortcuts branch from 998f226 to d4b2b36 Compare December 13, 2023 16:45
@hinerm
hinerm merged commit 05b74e7 into main Dec 13, 2023
@hinerm
hinerm deleted the scijava/scijava-ops-engine/parse-type-shortcuts branch December 13, 2023 17:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

Add shorthand for type interfaces in javadoc

2 participants