Created
July 9, 2013 20:38
-
-
Save volgar1x/5961066 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
D2 sux