org.hisrc.jscm.codemodel.impl.ProgramImpl Maven / Gradle / Ivy
The newest version!
package org.hisrc.jscm.codemodel.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.hisrc.jscm.codemodel.JSCodeModel;
import org.hisrc.jscm.codemodel.JSFunctionDeclaration;
import org.hisrc.jscm.codemodel.JSProgram;
import org.hisrc.jscm.codemodel.JSProgramVisitor;
import org.hisrc.jscm.codemodel.JSSourceElement;
import org.hisrc.jscm.codemodel.lang.Validate;
import org.hisrc.jscm.codemodel.statement.JSStatement;
import org.hisrc.jscm.codemodel.statement.impl.StatementGeneratorImpl;
public class ProgramImpl extends StatementGeneratorImpl implements JSProgram {
private final List sourceElements = new ArrayList();
private final List unmodifiableSourceElements = Collections
.unmodifiableList(sourceElements);
public ProgramImpl(JSCodeModel codeModel) {
super(codeModel);
}
@Override
protected S add(S statement) {
Validate.notNull(statement);
this.sourceElements.add(statement);
return statement;
}
@Override
public List getSourceElements() {
return unmodifiableSourceElements;
}
@Override
public JSFunctionDeclaration functionDeclaration(String name) {
Validate.notNull(name);
final JSFunctionDeclaration functionDeclaration = new FunctionDeclarationImpl(
getCodeModel(), name);
sourceElements.add(functionDeclaration);
return functionDeclaration;
}
@Override
public V acceptProgramVisitor(
JSProgramVisitor visitor) throws E {
return visitor.visitProgram(this);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy