public void setLast(Token last) { lineLast = last.getLine(); colLast = last.getColumn(); }
public void addWarning(String warning, String solution) { Token lt = null; try { lt = LT(1); } catch (TokenStreamException ee) { } if (lt == null) lt = Token.badToken; Map row = new HashMap(); row.put("warning", warning); row.put("solution", solution); row.put("filename", getFilename()); row.put("line", Integer.valueOf(lt.getLine())); row.put("column", Integer.valueOf(lt.getColumn())); // System.out.println(row); warningList.add(row); }
public void initialize(Token t) { super.initialize(t); line = t.getLine(); col = t.getColumn(); if (t instanceof SourceInfo) { SourceInfo info = (SourceInfo) t; lineLast = info.getLineLast(); colLast = info.getColumnLast(); } }
public void requireFailed(String problem, String solution) throws SemanticException { // TODO: Needs more work. Token lt = null; int lineNum = Token.badToken.getLine(), colNum = Token.badToken.getColumn(); try { lt = LT(1); if(lt != null) { lineNum = lt.getLine(); colNum = lt.getColumn(); } } catch (TokenStreamException ee) { if(ee instanceof TokenStreamRecognitionException) { lineNum = ((TokenStreamRecognitionException) ee).recog.getLine(); colNum = ((TokenStreamRecognitionException) ee).recog.getColumn(); } } throw new SemanticException(problem + ";\n solution: " + solution, getFilename(), lineNum, colNum); }
public void matchGenericTypeBracketsFailed(String problem, String solution) throws SemanticException { Token lt = null; int lineNum = Token.badToken.getLine(), colNum = Token.badToken.getColumn(); try { lt = LT(1); if(lt != null) { lineNum = lt.getLine(); colNum = lt.getColumn(); } } catch (TokenStreamException ee) { if(ee instanceof TokenStreamRecognitionException) { lineNum = ((TokenStreamRecognitionException) ee).recog.getLine(); colNum = ((TokenStreamRecognitionException) ee).recog.getColumn(); } } throw new SemanticException(problem + ";\n solution: " + solution, getFilename(), lineNum, colNum); }
public void actionPerformed(ActionEvent ae) { Token token = (Token) ((JComponent) ae.getSource()).getClientProperty("token"); if (token.getType() == Token.EOF_TYPE) { scriptPane.select(0, 0); return; } try { int start = scriptPane.getLineStartOffset(token.getLine() - 1) + token.getColumn() - 1; scriptPane.select(start, start + token.getText().length()); scriptPane.requestFocus(); } catch (BadLocationException ex) { // IGNORE } }
/** * Clones the token */ public Token cloneToken(Token t) { CommonToken clone = new CommonToken(t.getType(),t.getText()); clone.setLine(t.getLine()); clone.setColumn(t.getColumn()); return clone; }
@Override public void tokenize(SourceCode sourceCode, Tokens tokenEntries) { StringBuilder buffer = sourceCode.getCodeBuffer(); GroovyLexer lexer = new GroovyLexer(new StringReader(buffer.toString())); TokenStream tokenStream = lexer.plumb(); try { Token token = tokenStream.nextToken(); while (token.getType() != Token.EOF_TYPE) { TokenEntry tokenEntry = new TokenEntry(token.getText(), sourceCode.getFileName(), token.getLine()); tokenEntries.add(tokenEntry); token = tokenStream.nextToken(); } } catch (TokenStreamException err) { // Wrap exceptions of the Groovy tokenizer in a TokenMgrError, so // they are correctly handled // when CPD is executed with the '--skipLexicalErrors' command line // option throw new TokenMgrError("Lexical error in file " + sourceCode.getFileName() + " at line " + lexer.getLine() + ", column " + lexer.getColumn() + ". Encountered: " + err.getMessage(), TokenMgrError.LEXICAL_ERROR); } finally { tokenEntries.add(TokenEntry.getEOF()); } } }
public void setLast(Token last) { lineLast = last.getLine(); colLast = last.getColumn(); }
public void addWarning(String warning, String solution) { Token lt = null; try { lt = LT(1); } catch (TokenStreamException ee) { } if (lt == null) lt = Token.badToken; Map row = new HashMap(); row.put("warning" ,warning); row.put("solution",solution); row.put("filename",getFilename()); row.put("line" ,new Integer(lt.getLine())); row.put("column" ,new Integer(lt.getColumn())); // System.out.println(row); warningList.add(row); }
private void scanScript(File file) throws Exception{ scriptPane.read(new FileReader(file), null); // create lexer Constructor constructor = lexerClass.getConstructor(new Class[]{InputStream.class}); CharScanner lexer = (CharScanner) constructor.newInstance(new Object[]{new FileInputStream(file)}); tokenPane.setEditable(true); tokenPane.setText(""); int line = 1; ButtonGroup bg = new ButtonGroup(); Token token = null; while(true){ token = lexer.nextToken(); JToggleButton tokenButton = new JToggleButton((String) tokens.get(new Integer(token.getType()))); bg.add(tokenButton); tokenButton.addActionListener(this); tokenButton.setToolTipText(token.getText()); tokenButton.putClientProperty("token", token); tokenButton.setMargin(new Insets(0, 1, 0, 1)); tokenButton.setFocusPainted(false); if(token.getLine()>line){ tokenPane.getDocument().insertString(tokenPane.getDocument().getLength(), "\n", null); line = token.getLine(); } insertComponent(tokenButton); if(token.getType()==Token.EOF_TYPE) break; } tokenPane.setEditable(false); tokenPane.setCaretPosition(0); }
public void initialize(Token t) { super.initialize(t); line = t.getLine(); col = t.getColumn(); if (t instanceof SourceInfo) { SourceInfo info = (SourceInfo) t; lineLast = info.getLineLast(); colLast = info.getColumnLast(); } }
public void matchGenericTypeBracketsFailed(String problem, String solution) throws SemanticException { Token lt = null; int lineNum = Token.badToken.getLine(), colNum = Token.badToken.getColumn(); try { lt = LT(1); if(lt != null) { lineNum = lt.getLine(); colNum = lt.getColumn(); } } catch (TokenStreamException ee) { if(ee instanceof TokenStreamRecognitionException) { lineNum = ((TokenStreamRecognitionException) ee).recog.getLine(); colNum = ((TokenStreamRecognitionException) ee).recog.getColumn(); } } throw new SemanticException(problem + ";\n solution: " + solution, getFilename(), lineNum, colNum); }
public void requireFailed(String problem, String solution) throws SemanticException { // TODO: Needs more work. Token lt = null; int lineNum = Token.badToken.getLine(), colNum = Token.badToken.getColumn(); try { lt = LT(1); if(lt != null) { lineNum = lt.getLine(); colNum = lt.getColumn(); } } catch (TokenStreamException ee) { if(ee instanceof TokenStreamRecognitionException) { lineNum = ((TokenStreamRecognitionException) ee).recog.getLine(); colNum = ((TokenStreamRecognitionException) ee).recog.getColumn(); } } throw new SemanticException(problem + ";\n solution: " + solution, getFilename(), lineNum, colNum); }
public void actionPerformed(ActionEvent ae){ Token token = (Token) ((JComponent) ae.getSource()).getClientProperty("token"); if(token.getType()==Token.EOF_TYPE){ scriptPane.select(0, 0); return; } try{ int start = scriptPane.getLineStartOffset(token.getLine()-1)+token.getColumn()-1; scriptPane.select(start, start+token.getText().length()); scriptPane.requestFocus(); } catch(BadLocationException ex){ // IGNORE } }
Token nextToken = tokenStream.nextToken(); while (nextToken.getType() != Token.EOF_TYPE) { handleToken(token, nextToken.getLine(), lines); token = nextToken; nextToken = tokenStream.nextToken(); handleToken(token, nextToken.getLine(), lines); saveMetric(context, groovyFile, CoreMetrics.LINES, nextToken.getLine()); saveMetric(context, groovyFile, CoreMetrics.NCLOC, loc); saveMetric(context, groovyFile, CoreMetrics.COMMENT_LINES, comments);
/** * Clones the token */ public Token cloneToken(Token t) { CommonToken clone = new CommonToken(t.getType(),t.getText()); clone.setLine(t.getLine()); clone.setColumn(t.getColumn()); return clone; }
private void handleToken(Token token, int nextTokenLine, List<String> lines) { int tokenType = token.getType(); int tokenLine = token.getLine(); if (isComment(tokenType)) { if (isNotHeaderComment(tokenLine)) { comments += nextTokenLine - tokenLine + 1 - numberEmptyLines(token, lines); } for (int commentLineNb = tokenLine; commentLineNb <= nextTokenLine; commentLineNb++) { fileLinesContext.setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, commentLineNb, 1); } } else if (isNotWhitespace(tokenType) && tokenLine != currentLine) { loc++; fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, tokenLine, 1); currentLine = tokenLine; } }
@Override public void tokenize(SourceCode sourceCode, Tokens tokenEntries) { StringBuilder buffer = sourceCode.getCodeBuffer(); GroovyLexer lexer = new GroovyLexer(new StringReader(buffer.toString())); TokenStream tokenStream = lexer.plumb(); try { Token token = tokenStream.nextToken(); while (token.getType() != Token.EOF_TYPE) { TokenEntry tokenEntry = new TokenEntry(token.getText(), sourceCode.getFileName(), token.getLine()); tokenEntries.add(tokenEntry); token = tokenStream.nextToken(); } } catch (TokenStreamException err) { // Wrap exceptions of the Groovy tokenizer in a TokenMgrError, so // they are correctly handled // when CPD is executed with the '--skipLexicalErrors' command line // option throw new TokenMgrError("Lexical error in file " + sourceCode.getFileName() + " at line " + lexer.getLine() + ", column " + lexer.getColumn() + ". Encountered: " + err.getMessage(), TokenMgrError.LEXICAL_ERROR); } finally { tokenEntries.add(TokenEntry.getEOF()); } } }