Skip to content

Commit

Permalink
optimize code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
康志强 committed Jul 15, 2022
1 parent e872614 commit d2f4133
Show file tree
Hide file tree
Showing 81 changed files with 178 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private static URL[] getDistinctURLs(LinkedList<URL> urls) {
Set<URL> urlSet = new HashSet<>(urls.size());

for (Iterator i = urls.iterator(); i.hasNext(); ) {
URL url = (URL)i.next();
URL url = (URL) i.next();

if (urlSet.contains(url)) {
i.remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class ClassUtils {

public static <T> T newInstance(String className) throws Exception {
return (T)newInstance(ClassLoaderUtils.loadClass(className));
return (T) newInstance(ClassLoaderUtils.loadClass(className));
}

public static <T> T newInstance(String className, Class referrer) throws Exception {
Expand All @@ -39,7 +39,7 @@ public static <T> T newInstance(String className, ClassLoader classLoader) throw
public static <T> T newInstance(Class clazz) throws Exception {
Constructor constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
return (T)constructor.newInstance();
return (T) constructor.newInstance();
}

public static boolean isAbstractOrInterface(Class<?> clazz) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static byte[] toByteArray(final InputStream input, final long size) throw
throw new IllegalArgumentException("Size cannot be greater than Integer max value: " + size);
}

return toByteArray(input, (int)size);
return toByteArray(input, (int) size);
}

public static byte[] toByteArray(final InputStream input) throws IOException {
Expand Down Expand Up @@ -59,7 +59,7 @@ public static int copy(final InputStream input, final OutputStream output) throw
if (count > Integer.MAX_VALUE) {
return -1;
}
return (int)count;
return (int) count;
}

public static long copy(final InputStream input, final OutputStream output, final int bufferSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class MethodUtils {

public static <T> T invoke(Object obj, Method method, Object... args) throws Exception {
return (T)method.invoke(obj, args);
return (T) method.invoke(obj, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private static void scanClassInJar(Set<Class<?>> classes, String packageName, UR

JarFile jar;
try {
jar = ((JarURLConnection)url.openConnection()).getJarFile();
jar = ((JarURLConnection) url.openConnection()).getJarFile();
} catch (IOException e) {
logger.error("Failed to get jar file, url is " + url, e);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
*/
package com.alibaba.compileflow.engine.common.util;

import com.alibaba.compileflow.engine.definition.bpmn.Gateway;
import com.alibaba.compileflow.engine.definition.common.*;
import com.alibaba.compileflow.engine.definition.tbbpm.GatewayNode;
import com.alibaba.compileflow.engine.definition.common.FlowModel;
import com.alibaba.compileflow.engine.definition.common.GatewayElement;
import com.alibaba.compileflow.engine.definition.common.Node;
import com.alibaba.compileflow.engine.definition.common.Stateless;

/**
* @author yusu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Process getProcess() {
}

public <T extends FlowElement> T getFlowElement(String id) {
return (T)processes.stream().map(process -> process.getElement(id))
return (T) processes.stream().map(process -> process.getElement(id))
.filter(Objects::nonNull).findFirst()
.orElseThrow(() -> new CompileFlowException("Undefined element, element id is " + id));
}
Expand All @@ -51,7 +51,7 @@ public <T extends FlowElement> T getFlowElement(String id) {
public List<TransitionNode> getTransitionNodes() {
return processes.stream().map(Process::getFlowElements).flatMap(Collection::stream)
.filter(flowElement -> flowElement instanceof TransitionNode)
.map(flowElement -> (TransitionNode)flowElement)
.map(flowElement -> (TransitionNode) flowElement)
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public FlowElement getElement(String id) {
@Override
public List<FlowNode> getAllNodes() {
return flowElements.stream().filter(e -> e instanceof FlowNode)
.map(e -> (FlowNode)e).collect(Collectors.toList());
.map(e -> (FlowNode) e).collect(Collectors.toList());
}

@Override
Expand All @@ -189,7 +189,7 @@ public void addNode(FlowNode node) {

@Override
public FlowNode getNode(String id) {
return (FlowNode)getElement(id);
return (FlowNode) getElement(id);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public FlowElement getElement(String id) {
@Override
public List<FlowNode> getAllNodes() {
return flowElements.stream().filter(e -> e instanceof FlowNode)
.map(e -> (FlowNode)e).collect(Collectors.toList());
.map(e -> (FlowNode) e).collect(Collectors.toList());
}

@Override
Expand All @@ -110,7 +110,7 @@ public void addNode(FlowNode node) {

@Override
public FlowNode getNode(String id) {
return (FlowNode)getElement(id);
return (FlowNode) getElement(id);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package com.alibaba.compileflow.engine.definition.tbbpm;

import com.alibaba.compileflow.engine.definition.common.action.HasAction;
import com.alibaba.compileflow.engine.definition.common.action.HasInOutAction;
import com.alibaba.compileflow.engine.definition.common.action.IAction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.alibaba.compileflow.engine.definition.common.WaitElement;
import com.alibaba.compileflow.engine.definition.common.action.HasInOutAction;
import com.alibaba.compileflow.engine.definition.common.action.IAction;

/**
* @author wuxiang
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.alibaba.compileflow.engine.definition.common.WaitElement;
import com.alibaba.compileflow.engine.definition.common.action.HasInOutAction;
import com.alibaba.compileflow.engine.definition.common.action.IAction;

/**
* @author wuxiang
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static FlowClassLoader getInstance() {
if (instance == null) {
try {
URL url = new URL("file:///" + CompileConstants.FLOW_COMPILE_CLASS_DIR);
instance = new FlowClassLoader(new URL[] {url},
instance = new FlowClassLoader(new URL[]{url},
FlowClassLoader.class.getClassLoader());
} catch (MalformedURLException e) {
throw new CompileFlowException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public void compile(JavaSource javaSource, File outputFile, CompileOption compil

File javaSourceFile = javaSource.getJavaSourceFile();
String targetClassName = javaSource.getTargetFullClassName();
String[] fileNames = new String[] {javaSourceFile.getAbsolutePath()};
String[] classNames = new String[] {targetClassName};
String[] fileNames = new String[]{javaSourceFile.getAbsolutePath()};
String[] classNames = new String[]{targetClassName};

List<IProblem> problems = new ArrayList<>();
INameEnvironment env = new INameEnvironment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/
package com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser;

import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.ParseConfig;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.FlowSource;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.ParseConfig;

/**
* @author wuxiang
Expand All @@ -29,4 +29,4 @@ public interface FlowParser<S extends FlowSource, R> extends Parser {

R parse(S source, ParseConfig parseConfig);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public abstract class AbstractParserProvider<T extends Parser> implements Parser
@Override
@SuppressWarnings("unchecked")
public T getParser(String name) {
return Optional.ofNullable((T)parserMap.get(name)).orElseThrow(
return Optional.ofNullable((T) parserMap.get(name)).orElseThrow(
() -> new CompileFlowException("No parser found, name is " + name));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ public AbstractFlowElementParserProvider getParserProvider() {
@SuppressWarnings("unchecked")
protected boolean attachPlatformChildElement(Element childElement, E element, ParseContext parseContext) {
if (element instanceof HasVar && childElement instanceof ExtensionElements) {
((ExtensionElements)childElement).getExtensionElements().stream()
((ExtensionElements) childElement).getExtensionElements().stream()
.filter(extensionElement -> "var".equals(extensionElement.getName()))
.map(this::buildExtensionVar)
.forEach(((HasVar)element)::addVar);
.forEach(((HasVar) element)::addVar);
return false;
}
if (element instanceof ElementContainer && childElement instanceof FlowElement) {
((ElementContainer)element).addElement(childElement);
((ElementContainer) element).addElement(childElement);
return true;
}
if (element instanceof HasAction && childElement instanceof IAction) {
((HasAction)element).setAction((IAction)childElement);
((HasAction) element).setAction((IAction) childElement);
return true;
}
if (element instanceof Activity && childElement instanceof LoopCharacteristics) {
((Activity)element).setLoopCharacteristics((LoopCharacteristics)childElement);
((Activity) element).setLoopCharacteristics((LoopCharacteristics) childElement);
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import com.alibaba.compileflow.engine.definition.common.Element;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.FlowElementParser;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.ParseContext;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.XMLSource;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.provider.ParserProviderSupport;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.provider.support.AbstractFlowElementParserProvider;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.XMLSource;

/**
* @author wuxiang
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ public AbstractFlowElementParserProvider getParserProvider() {
@SuppressWarnings("unchecked")
protected boolean attachPlatformChildElement(Element childElement, E element, ParseContext parseContext) {
if (element instanceof FlowNode && childElement instanceof Transition) {
((FlowNode)element).addOutgoingTransition((Transition)childElement);
((FlowNode) element).addOutgoingTransition((Transition) childElement);
return true;
}
if (element instanceof HasAction && childElement instanceof IAction) {
((HasAction)element).setAction((IAction)childElement);
((HasAction) element).setAction((IAction) childElement);
return true;
}
if (element instanceof HasVar && childElement instanceof IVar) {
((HasVar)element).addVar((IVar)childElement);
((HasVar) element).addVar((IVar) childElement);
return true;
}
if (element instanceof NodeContainer && childElement instanceof FlowNode) {
((NodeContainer)element).addNode((FlowNode)childElement);
((NodeContainer) element).addNode((FlowNode) childElement);
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected AbstractFlowElementParserProvider getFlowElementParserProvider() {
@Override
protected BpmnModel convertToFlowModel(Element top) {
if (top instanceof Definitions) {
Definitions definitions = (Definitions)top;
Definitions definitions = (Definitions) top;
List<Process> processes = definitions.getProcesses();
if (CollectionUtils.isEmpty(processes)) {
throw new CompileFlowException("No process founded");
Expand Down Expand Up @@ -109,20 +109,20 @@ private void buildFlowTransition(BpmnModel bpmnModel) {
Process process = bpmnModel.getProcess();
buildFlowTransition(process);
process.getFlowElements().stream().filter(flowElement -> flowElement instanceof SubProcess)
.map(e -> (SubProcess)e)
.map(e -> (SubProcess) e)
.forEach(this::buildFlowTransition);
}

private void buildFlowTransition(ElementContainer<FlowElement, FlowNode> elementContainer) {
elementContainer.getAllElements().stream().filter(flowElement -> flowElement instanceof SequenceFlow)
.map(e -> (SequenceFlow)e).forEach(sequenceFlow -> {
FlowNode source = elementContainer.getNode(sequenceFlow.getSourceRef());
FlowNode target = elementContainer.getNode(sequenceFlow.getTargetRef());
source.addOutgoingFlow(sequenceFlow);
source.addOutgoingNode(target);
target.addIncomingFlow(sequenceFlow);
target.addIncomingNode(source);
});
.map(e -> (SequenceFlow) e).forEach(sequenceFlow -> {
FlowNode source = elementContainer.getNode(sequenceFlow.getSourceRef());
FlowNode target = elementContainer.getNode(sequenceFlow.getTargetRef());
source.addOutgoingFlow(sequenceFlow);
source.addOutgoingNode(target);
target.addIncomingFlow(sequenceFlow);
target.addIncomingNode(source);
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import com.alibaba.compileflow.engine.definition.bpmn.BpmnModelConstants;
import com.alibaba.compileflow.engine.definition.bpmn.CallActivity;
import com.alibaba.compileflow.engine.definition.common.Element;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.support.AbstractBpmnElementParser;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.ParseContext;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.XMLSource;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.support.AbstractBpmnElementParser;

/**
* @author wuxiang
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import com.alibaba.compileflow.engine.definition.bpmn.BpmnModelConstants;
import com.alibaba.compileflow.engine.definition.bpmn.Expression;
import com.alibaba.compileflow.engine.definition.common.Element;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.support.AbstractBpmnElementParser;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.ParseContext;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.XMLSource;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.support.AbstractBpmnElementParser;

/**
* @author wuxiang
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import com.alibaba.compileflow.engine.definition.bpmn.Definitions;
import com.alibaba.compileflow.engine.definition.bpmn.Process;
import com.alibaba.compileflow.engine.definition.common.Element;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.support.AbstractBpmnElementParser;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.ParseContext;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.XMLSource;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.support.AbstractBpmnElementParser;

/**
* @author wuxiang
Expand All @@ -48,7 +48,7 @@ protected Definitions doParse(XMLSource xmlSource, ParseContext parseContext) th
@Override
protected void attachChildElement(Element childElement, Definitions element, ParseContext parseContext) {
if (childElement instanceof Process) {
element.getProcesses().add((Process)childElement);
element.getProcesses().add((Process) childElement);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import com.alibaba.compileflow.engine.definition.bpmn.BpmnModelConstants;
import com.alibaba.compileflow.engine.definition.bpmn.EndEvent;
import com.alibaba.compileflow.engine.definition.common.Element;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.support.AbstractBpmnElementParser;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.ParseContext;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.XMLSource;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.support.AbstractBpmnElementParser;

/**
* @author wuxiang
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import com.alibaba.compileflow.engine.definition.bpmn.BpmnModelConstants;
import com.alibaba.compileflow.engine.definition.bpmn.ExclusiveGateway;
import com.alibaba.compileflow.engine.definition.common.Element;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.support.AbstractBpmnElementParser;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.ParseContext;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.XMLSource;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.support.AbstractBpmnElementParser;

/**
* @author wuxiang
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import com.alibaba.compileflow.engine.definition.common.extension.AbstractExtensionElement;
import com.alibaba.compileflow.engine.definition.common.extension.ExtensionAttribute;
import com.alibaba.compileflow.engine.definition.common.extension.ExtensionElement;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.support.AbstractBpmnElementParser;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.ParseContext;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.XMLSource;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.support.AbstractBpmnElementParser;

/**
* @author wuxiang
Expand All @@ -38,7 +38,7 @@ protected ExtensionElements doParse(XMLSource xmlSource, ParseContext parseConte
while (!xmlSource.endWith(BpmnModelConstants.BPMN_ELEMENT_EXTENSION_ELEMENTS)) {
if (xmlSource.hasNext()) {
ExtensionElement extensionElement = parseExtensionElement(xmlSource);
AbstractExtensionElement parentElement = (AbstractExtensionElement)parseContext.getParent();
AbstractExtensionElement parentElement = (AbstractExtensionElement) parseContext.getParent();
parentElement.addExtensionElement(extensionElement);
extensionElements.addExtensionElements(extensionElement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import com.alibaba.compileflow.engine.definition.bpmn.BpmnModelConstants;
import com.alibaba.compileflow.engine.definition.bpmn.InclusiveGateway;
import com.alibaba.compileflow.engine.definition.common.Element;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.support.AbstractBpmnElementParser;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.ParseContext;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.model.XMLSource;
import com.alibaba.compileflow.engine.process.preruntime.converter.impl.parser.support.AbstractBpmnElementParser;

/**
* @author wuxiang
Expand Down
Loading

0 comments on commit d2f4133

Please sign in to comment.