/** * Sets regexp pattern for ignored strings. * * @param aIgnoreStringsRegexp regexp pattern for ignored strings */ public void setIgnoreStringsRegexp(String aIgnoreStringsRegexp) { if ((aIgnoreStringsRegexp != null) && (aIgnoreStringsRegexp.length() > 0)) { mPattern = Utils.getPattern(aIgnoreStringsRegexp); } else { mPattern = null; } }
/** * Verifies that a specified left curly brace is placed correctly according to policy. * * @param aBrace token for left curly brace * @param aStartToken token for start of expression */ private void verifyBrace(final DetailAST aBrace, final DetailAST aStartToken) { final String braceLine = getLines()[aBrace.getLineNo() - 1]; // calculate the previous line length without trailing whitespace. Need // to handle the case where there is no previous line, cause the line // being check is the first line in the file. final int prevLineLen = (aBrace.getLineNo() == 1) ? mMaxLineLength : Utils.lengthMinusTrailingWhitespace(getLines()[aBrace.getLineNo() - 2]); // Check for being told to ignore, or have '{}' which is a special case if ((braceLine.length() > (aBrace.getColumnNo() + 1)) && (braceLine.charAt(aBrace.getColumnNo() + 1) == '}')) {; // ignore } else if (getAbstractOption() == LeftCurlyOption.NL) { if (!Utils.whitespaceBefore(aBrace.getColumnNo(), braceLine)) { log(aBrace.getLineNo(), aBrace.getColumnNo(), "line.new", "{"); } } else if (getAbstractOption() == LeftCurlyOption.EOL) { if (Utils.whitespaceBefore(aBrace.getColumnNo(), braceLine) && ((prevLineLen + 2) <= mMaxLineLength)) { log(aBrace.getLineNo(), aBrace.getColumnNo(), "line.previous", "{"); } } else if (getAbstractOption() == LeftCurlyOption.NLOW) { if (aStartToken.getLineNo() == aBrace.getLineNo()) {; // all ok as on the same line } else if ((aStartToken.getLineNo() + 1) == aBrace.getLineNo()) { if (!Utils.whitespaceBefore(aBrace.getColumnNo(), braceLine)) { log(aBrace.getLineNo(), aBrace.getColumnNo(), "line.new", "{"); } else if ((prevLineLen + 2) <= mMaxLineLength) { log(aBrace.getLineNo(), aBrace.getColumnNo(), "line.previous", "{"); } } else if (!Utils.whitespaceBefore(aBrace.getColumnNo(), braceLine)) { log(aBrace.getLineNo(), aBrace.getColumnNo(), "line.new", "{"); } } }
@Override protected void postprocessHeaderLines() { final List<String> headerLines = getHeaderLines(); mHeaderRegexps.clear(); for (String line : headerLines) { try { // TODO: Not sure if cache in Utils is still necessary mHeaderRegexps.add(Utils.getPattern(line)); } catch (final PatternSyntaxException ex) { throw new ConversionException( "line " + (mHeaderRegexps.size() + 1) + " in header specification" + " is not a regular expression"); } } }
/** * Set the check class pattern. * * @param aChecks regular expression for filtered check classes. */ public void setChecks(final String aChecks) { mCheckPattern = aChecks; mCheckRegexp = Utils.getPattern(aChecks); }
/** * Constructs a <code>SuppressElement</code> for a file name pattern. Must either call {@link * #setColumns(String)} or {@link #setModuleId(String)} before using this object. * * @param aFiles regular expression for names of filtered files. * @throws PatternSyntaxException if there is an error. */ public SuppressElement(String aFiles) throws PatternSyntaxException { mFilePattern = aFiles; mFileRegexp = Utils.getPattern(aFiles); }
@Override protected void processFiltered(File aFile, List<String> aLines) { // check if already checked and passed the file final String fileName = aFile.getPath(); final long timestamp = aFile.lastModified(); if (mCache.alreadyChecked(fileName, timestamp)) { return; } try { final FileText text = FileText.fromLines(aFile, aLines); final FileContents contents = new FileContents(text); final DetailAST rootAST = TreeWalker.parse(contents); walk(rootAST, contents); } catch (final RecognitionException re) { Utils.getExceptionLogger().debug("RecognitionException occured.", re); getMessageCollector() .add( new LocalizedMessage( re.getLine(), re.getColumn(), Defn.CHECKSTYLE_BUNDLE, "general.exception", new String[] {re.getMessage()}, getId(), this.getClass(), null)); } catch (final TokenStreamRecognitionException tre) { Utils.getExceptionLogger().debug("TokenStreamRecognitionException occured.", tre); final RecognitionException re = tre.recog; if (re != null) { getMessageCollector() .add( new LocalizedMessage( re.getLine(), re.getColumn(), Defn.CHECKSTYLE_BUNDLE, "general.exception", new String[] {re.getMessage()}, getId(), this.getClass(), null)); } else { getMessageCollector() .add( new LocalizedMessage( 0, Defn.CHECKSTYLE_BUNDLE, "general.exception", new String[] {"TokenStreamRecognitionException occured."}, getId(), this.getClass(), null)); } } catch (final TokenStreamException te) { Utils.getExceptionLogger().debug("TokenStreamException occured.", te); getMessageCollector() .add( new LocalizedMessage( 0, Defn.CHECKSTYLE_BUNDLE, "general.exception", new String[] {te.getMessage()}, getId(), this.getClass(), null)); } catch (final Throwable err) { Utils.getExceptionLogger().debug("Throwable occured.", err); getMessageCollector() .add( new LocalizedMessage( 0, Defn.CHECKSTYLE_BUNDLE, "general.exception", new String[] {"" + err}, getId(), this.getClass(), null)); } if (getMessageCollector().size() == 0) { mCache.checkedOk(fileName, timestamp); } }