Commits

Stephen McKamey committed d17b315

adding ability to suppress client-side or server-side view output

Comments (0)

Files changed (4)

duel-compiler/src/main/java/org/duelengine/duel/ast/VIEWCommandNode.java

 	private static final String NAME = "$view";
 	private static final CommandName CMD = CommandName.VIEW;
 	private String name;
+	private boolean clientOnly;
+	private boolean serverOnly;
 
 	public VIEWCommandNode(int index, int line, int column) {
 		super(CMD, NAME, false, index, line, column);
 		this.name = value;
 	}
 
+	public boolean isClientOnly() {
+		return this.clientOnly;
+	}
+
+	public void setClientOnly(boolean value) {
+		this.clientOnly = value;
+	}
+
+	public boolean isServerOnly() {
+		return this.serverOnly;
+	}
+
+	public void setServerOnly(boolean value) {
+		this.serverOnly = value;
+	}
+
 	@Override
 	public boolean isSelf(String tag) {
 		return EXT_NAME.equalsIgnoreCase(tag) || NAME.equalsIgnoreCase(tag);
 		if (name == null || name.isEmpty()) {
 			throw new NullPointerException("name");
 		}
-		if (!"name".equalsIgnoreCase(name)) {
+		if ("name".equalsIgnoreCase(name)) {
+			if (value != null && !(value instanceof LiteralNode)) {
+				// Syntax error
+				throw new InvalidNodeException("VIEW name must be a string literal: "+value.getClass(), value);
+			}
+
+			this.name = (value == null ? null : ((LiteralNode)value).getValue());
+
+		} else if ("client-only".equalsIgnoreCase(name)) {
+			this.clientOnly = true;
+
+		} else if ("server-only".equalsIgnoreCase(name)) {
+			this.serverOnly = true;
+
+		} else {
 			throw new InvalidNodeException("Attribute invalid on VIEW declaration: "+name, value);
 		}
-		if (value != null && !(value instanceof LiteralNode)) {
-			// Syntax error
-			throw new InvalidNodeException("VIEW name must be a string literal: "+value.getClass(), value);
-		}
-
-		this.name = (value == null ? null : ((LiteralNode)value).getValue());
 	}
 }

duel-compiler/src/main/java/org/duelengine/duel/codegen/ClientCodeGen.java

 
 		List<String> namespaces = new ArrayList<String>();
 		for (VIEWCommandNode view : views) {
-			if (view == null) {
+			if (view == null || view.isServerOnly()) {
 				continue;
 			}
+
 			this.writeln(output, 0);
 
 			// prepend the client-side prefix

duel-compiler/src/main/java/org/duelengine/duel/codegen/JavaCodeGen.java

 
 		boolean importsWritten = false;
 		for (VIEWCommandNode view : views) {
-			if (view != null) {
-				CodeTypeDeclaration viewType = new CodeDOMBuilder(this.settings).buildView(view);
+			if (view == null || view.isClientOnly()) {
+				continue;
+			}
 
-				if (importsWritten) {
-					this.writeln(output, 0);
-				} else {
-					this.writePackage(output, viewType.getNamespace());
-					importsWritten = true;
-				}
+			CodeTypeDeclaration viewType = new CodeDOMBuilder(this.settings).buildView(view);
 
-				this.writeTypeDeclaration(output, viewType, 0);
+			if (importsWritten) {
 				this.writeln(output, 0);
+			} else {
+				this.writePackage(output, viewType.getNamespace());
+				importsWritten = true;
 			}
+
+			this.writeTypeDeclaration(output, viewType, 0);
+			this.writeln(output, 0);
 		}
 	}
 

duel-compiler/src/main/java/org/duelengine/duel/compiler/DuelCompiler.java

 
 			String outputName = inputFile.getName();
 			for (VIEWCommandNode view : views) {
+				if (view.isServerOnly()) {
+					// skip server-only views
+					continue;
+				}
+
 				// use the first view
 				outputName = settings.getClientPath(view.getName());
 				break;
 
 			codegen = new JavaCodeGen(settings);
 			for (VIEWCommandNode view : views) {
+				if (view.isClientOnly()) {
+					// skip client-only views
+					continue;
+				}
+
 				try {
 					File outputFile = new File(this.outputServerDir, settings.getServerPath(view.getName(), codegen));
 					outputFile.getParentFile().mkdirs();