Skip to content

Instantly share code, notes, and snippets.

@volgar1x
Created July 9, 2013 20:38
Show Gist options
  • Save volgar1x/5961066 to your computer and use it in GitHub Desktop.
Save volgar1x/5961066 to your computer and use it in GitHub Desktop.
package org.photon.dofusprotocolbuilder;
import org.apache.commons.cli.CommandLine;
import org.as3commons.asblocks.ASFactory;
import org.as3commons.asblocks.IASParser;
import org.as3commons.asblocks.dom.IASCompilationUnit;
import org.as3commons.asblocks.impl.ASTASClassType;
import org.photon.shared.inject.InjectConfig;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.File;
import java.io.FileReader;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Throwables.propagate;
/**
* @author blackrush
*/
@Singleton
public class MessageConverter implements Executable {
public static String getFullPath(String baseSourcesPath, String packageName) {
return baseSourcesPath + '/' + packageName.replace('.', '/');
}
@Inject
private CommandLine cmd;
@InjectConfig("photon.protocol.builder.sources")
private String sourcesPath;
@InjectConfig("photon.protocol.builder.messages-package")
private String packageName;
@Override
public boolean isEnabled() {
return !cmd.hasOption("help");
}
@Override
public void execute() {
ASFactory factory = new ASFactory();
IASParser parser = factory.newParser();
File base = new File(getFullPath(sourcesPath, packageName));
execute(parser, base);
}
protected void execute(IASParser parser, File directory) {
checkArgument(directory.isDirectory());
for (File child : directory.listFiles()) {
if (child.isDirectory()) {
execute(parser, child);
} else {
try {
convert(parser, child);
} catch (Exception e) {
throw propagate(e);
}
}
}
}
protected void convert(IASParser parser, File file) throws Exception {
IASCompilationUnit unit = parser.parseIn(new FileReader(file));
ASTASClassType messageClass = (ASTASClassType) unit.getType();
}
}
@Crystals
Copy link

Crystals commented Jul 9, 2013

D2 sux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment