private void commandLoad(Options options) { LoadResult result; Project project = codeAssist.getProject(options); try { progressMonitor.attach(project); if (options.isFileStdin()) { result = codeAssist.load(project, new File("(stdin)"), options.getHereDocReader(inReader)); } else { result = codeAssist.load(project, options.getFile(), options.getEncoding()); } if (options.isPrintAST()) { Logger.debug("AST:\n%s", result.getAST()); } if (options.isEmacsFormat()) { out.print("("); codeAssistError(result, options); out.println(")"); } else { codeAssistError(result, options); } } catch (Exception e) { commandException(e, options); } finally { progressMonitor.detach(project); } }
@Override public void run(Options opts) { splitSep = opts.get("splitSep", "\\s+"); joinSep = opts.get("joinSep", "\t"); inputFile = opts.getFile("inputFile", null); reverseCut = opts.has("reverseCut"); final Set<Integer> cutIndexes = new HashSet<Integer>(); for (String arg : opts.getArgs()) { cutIndexes.add(Integer.parseInt(arg)); } debug(">> cutIndexes " + cutIndexes); InputStream ins = getInputStream(inputFile, System.in); eachLine( ins, new LineAction() { @Override public void onLine(String line) { List<String> result = new ArrayList<String>(); String[] words = line.split(splitSep); int wordLen = words.length; debug(">> wordLen " + wordLen); for (int i = 0; i < wordLen; i++) { String word = words[i]; debug(">> Checking column " + i + ", word=" + word); boolean keep = !cutIndexes.contains(i); debug(" keep? " + keep); if (keep) { // Try negative index search keep = !cutIndexes.contains(i - wordLen); debug(" negative index keep? " + keep); } if (reverseCut) { keep = !keep; debug(" reversing keep value!"); } if (keep) { result.add(word); } } String first = result.remove(0); print(first); for (String word : result) { print(joinSep); print(word); } println(""); } }); }
private void commandTypeInference(Options options) { TypeInferenceResult result; Project project = codeAssist.getProject(options); try { progressMonitor.attach(project); if (options.isFileStdin()) { result = codeAssist.typeInference( project, new File("(stdin)"), options.getHereDocReader(inReader), options.getLocation()); } else { result = codeAssist.typeInference( project, options.getFile(), options.getEncoding(), options.getLocation()); } if (options.isPrintAST()) { Logger.debug("AST:\n%s", result.getAST()); } if (options.isTest()) { Set<String> data = new HashSet<String>(); for (IRubyObject klass : result.getTypeSet()) { data.add(klass.toString()); } test(options, data); } else { if (options.isEmacsFormat()) { out.print("("); out.print("(type"); for (IRubyObject klass : result.getTypeSet()) { out.print(" \""); out.print(klass); out.print("\""); } out.println(")"); codeAssistError(result, options); out.println(")"); } else { for (IRubyObject klass : result.getTypeSet()) { out.print("type: "); out.println(klass); } codeAssistError(result, options); } } } catch (Exception e) { if (options.isTest()) { testError(options); } commandException(e, options); } finally { progressMonitor.detach(project); } }
private void commandFindDefinition(Options options) { FindDefinitionResult result; Project project = codeAssist.getProject(options); try { progressMonitor.attach(project); if (options.isFileStdin()) { result = codeAssist.findDefinition( project, new File("(stdin)"), options.getHereDocReader(inReader), options.getLocation()); } else { result = codeAssist.findDefinition( project, options.getFile(), options.getEncoding(), options.getLocation()); } if (options.isPrintAST()) { Logger.debug("AST:\n%s", result.getAST()); } if (options.isTest()) { Set<String> data = new HashSet<String>(); for (SourceLocation location : result.getLocations()) { data.add(location.toString()); } test(options, data); } else { if (options.isEmacsFormat()) { out.print("("); out.print("(location"); for (SourceLocation location : result.getLocations()) { if (location.getFile() != null) out.printf(" (%s . %d)", emacsStringLiteral(location.getFile()), location.getLine()); } out.println(")"); codeAssistError(result, options); out.println(")"); } else { for (SourceLocation location : result.getLocations()) { out.printf("location: %d %s\n", location.getLine(), location.getFile()); } codeAssistError(result, options); } } } catch (Exception e) { if (options.isTest()) testError(options); commandException(e, options); } finally { progressMonitor.detach(project); } }
private void commandWhere(Options options) { WhereResult result; Project project = codeAssist.getProject(options); try { progressMonitor.attach(project); if (options.isFileStdin()) { result = codeAssist.where( project, new File("(stdin)"), options.getHereDocReader(inReader), options.getLine()); } else { result = codeAssist.where(project, options.getFile(), options.getEncoding(), options.getLine()); } if (options.isPrintAST()) { Logger.debug("AST:\n%s", result.getAST()); } if (options.isTest()) { Set<String> data = new HashSet<String>(); if (result.getName() != null) data.add(result.getName()); test(options, data); } else { if (options.isEmacsFormat()) { out.print("("); if (result.getName() != null) out.printf("(name . \"%s\")", result.getName()); codeAssistError(result, options); out.println(")"); } else { if (result.getName() != null) { out.print("name: "); out.println(result.getName()); } codeAssistError(result, options); } } } catch (Exception e) { if (options.isTest()) testError(options); commandException(e, options); } finally { progressMonitor.detach(project); } }
/** * It parses the provided file and parsing parameters followed by problem solving. * * @param args parameters describing the flatzinc file containing the problem to be solved as well * as options for problem solving. * <p>TODO what are the conditions for different exceptions being thrown? Write little info * below. * @throws ParseException * @throws TokenMgrError */ public static void main(String[] args) { Options opt = new Options(args); if (opt.getVerbose()) System.out.println("Flatzinc2JaCoP: compiling and executing " + args[args.length - 1]); Thread tread = java.lang.Thread.currentThread(); java.lang.management.ThreadMXBean b = java.lang.management.ManagementFactory.getThreadMXBean(); long startCPU = b.getThreadCpuTime(tread.getId()); Parser parser = new Parser(opt.getFile()); parser.setOptions(opt); try { parser.model(); } catch (FailException e) { System.err.println( "=====UNSATISFIABLE====="); // "*** Evaluation of model resulted in fail."); } catch (ArithmeticException e) { System.err.println("*** Evaluation of model resulted in integer overflow."); } catch (ParseException e) { System.out.println("*** Parser exception " + e); } catch (TokenMgrError e) { System.out.println("*** Parser exception " + e); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("*** Array out of bound exception " + e); } catch (OutOfMemoryError e) { System.out.println("*** Out of memory error; consider option -Xmx... for JVM"); } catch (StackOverflowError e) { System.out.println("*** Stack overflow exception error; consider option -Xss... for JVM"); } if (opt.getStatistics()) { System.out.println( "\nTotal CPU time : " + (b.getThreadCpuTime(tread.getId()) - startCPU) / (long) 1e+6 + "ms"); } }
private void commandCodeCompletion(Options options) { CodeCompletionResult result; Project project = codeAssist.getProject(options); try { progressMonitor.attach(project); if (options.isFileStdin()) { result = codeAssist.codeCompletion( project, new File("(stdin)"), options.getHereDocReader(inReader), options.getLocation()); } else { result = codeAssist.codeCompletion( project, options.getFile(), options.getEncoding(), options.getLocation()); } if (options.isPrintAST()) { Logger.debug("AST:\n%s", result.getAST()); } String prefix = options.getPrefix(); if (options.isTest()) { Set<String> data = new HashSet<String>(); for (CodeCompletionResult.CompletionCandidate completion : result.getCandidates()) { data.add(completion.getCompletion()); } test(options, data); } else { if (options.isEmacsFormat()) { out.print("("); out.print("(completion"); for (CodeCompletionResult.CompletionCandidate completion : result.getCandidates()) { if (prefix == null || completion.getCompletion().startsWith(prefix)) { out.printf( " (\"%s\" \"%s\" \"%s\" \"%s\")", completion.getCompletion(), completion.getQualifiedName(), completion.getBaseName(), completion.getKind()); } } out.println(")"); codeAssistError(result, options); out.println(")"); } else { for (CodeCompletionResult.CompletionCandidate completion : result.getCandidates()) { if (prefix == null || completion.getCompletion().startsWith(prefix)) { out.printf( "completion: %s %s %s %s\n", completion.getCompletion(), completion.getQualifiedName(), completion.getBaseName(), completion.getKind()); } } codeAssistError(result, options); } } } catch (Exception e) { if (options.isTest()) { testError(options); } commandException(e, options); } finally { progressMonitor.detach(project); } }