Rational Programming Patterns

Sample code of a user micropattern

You can see here the sample code of a Java™ class that defines a simple COBOL micropattern. This micropattern adds a DISPLAY statement in the source code.

Figure 1. Sample code of a Java class
package com.micropattern.sample;

import com.ibm.pdp.engine.IMicroPattern;
import com.ibm.pdp.maf.rpp.base.RadicalElement;
import com.ibm.pdp.rpp.micropattern.AbstractSimpleMicroPatternHandler;

public class SimpleMicroPattern  extends AbstractSimpleMicroPatternHandler {
	@Override
	public String getId() {
		return "MP";
	}

	@Override
	public String process(final IMicroPattern microPattern, final RadicalElement radicalElement) {
		StringBuffer result = new StringBuffer();
		String label = radicalElement.getLabel();
		// If the micro pattern is declared in the COBOL code then add the declaration header.
		boolean inUserCode = microPattern.getProcessingContext().inUserCode();
		if(inUserCode)
			result.append(microPattern.getOriginalHeaderDeclaration());
		result.append("       DISPLAY \"" + label + "\".\n");
		// If the micro pattern is declared in the COBOL code then add the declaration footer.
		if(inUserCode)
			result.append(microPattern.getClosingSequence());
		return result.toString();

	}
}

Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)