InputFile.lines
Code IndexAdd Codota to your IDE (free)

Best code snippets using org.sonar.api.batch.fs.InputFile.lines(Showing top 15 results out of 315)

origin: SonarSource/sonarqube

private static void validateMaxLine(Map<Integer, Integer> m, InputFile inputFile) {
 int maxLine = inputFile.lines();
 for (int line : m.keySet()) {
  if (line > maxLine) {
   throw new IllegalStateException(String.format("Can't create measure for line %d for file '%s' with %d lines", line, inputFile, maxLine));
  }
 }
}
origin: SonarSource/sonarqube

private static void storeZeroCoverageForEachExecutableLine(final SensorContext context, InputFile f, DefaultMeasure<String> execLines) {
 NewCoverage newCoverage = context.newCoverage().onFile(f);
 Map<Integer, Integer> lineMeasures = KeyValueFormat.parseIntInt((String) execLines.value());
 for (Map.Entry<Integer, Integer> lineMeasure : lineMeasures.entrySet()) {
  int lineIdx = lineMeasure.getKey();
  if (lineIdx <= f.lines() && lineMeasure.getValue() > 0) {
   newCoverage.lineHits(lineIdx, 0);
  }
 }
 newCoverage.save();
}
origin: SonarSource/sonarqube

private void checkLineRange(int line) {
 Preconditions.checkArgument(line > 0, "Line number should be positive for file %s.", inputFile);
 Preconditions.checkArgument(line <= inputFile.lines(), "Line %s is out of range for file %s. File has %s lines.", line, inputFile, inputFile.lines());
}
origin: SonarSource/sonarqube

public static FileHashes create(InputFile f) {
 final byte[][] hashes = new byte[f.lines()][];
 FileMetadata.computeLineHashesForIssueTracking(f,
  (lineIdx, hash) -> hashes[lineIdx - 1] = hash);
 int size = hashes.length;
 Multimap<String, Integer> linesByHash = LinkedHashMultimap.create();
 String[] hexHashes = new String[size];
 for (int i = 0; i < size; i++) {
  String hash = hashes[i] != null ? Hex.encodeHexString(hashes[i]) : "";
  hexHashes[i] = hash;
  // indices in array are shifted one line before
  linesByHash.put(hash, i + 1);
 }
 return new FileHashes(hexHashes, linesByHash);
}
origin: SonarSource/sonarqube

private void validateLine(int line) {
 checkState(line <= inputFile.lines(), "Line %s is out of range in the file %s (lines: %s)", line, inputFile, inputFile.lines());
 checkState(line > 0, "Line number must be strictly positive: %s", line);
}
origin: SonarSource/sonarqube

 @Override
 public void execute(SensorContext context) {
  Iterator<InputFile> inputFiles = context.fileSystem().inputFiles(context.fileSystem().predicates().all()).iterator();

  if (!inputFiles.hasNext()) {
   throw new IllegalStateException("No files indexed");
  }

  InputFile file = inputFiles.next();
  context.newHighlighting()
   .onFile(file)
   .highlight(file.selectLine(1), TypeOfText.CONSTANT)
   .save();

  context.newHighlighting()
   .onFile(file)
   .highlight(file.selectLine(file.lines()), TypeOfText.COMMENT)
   .save();
 }
}
origin: SonarSource/sonarqube

private void createIssues(InputFile file, SensorContext context, String repo) {
 RuleKey ruleKey = RuleKey.of(repo, RULE_KEY);
 String severity = context.settings().getString(FORCE_SEVERITY_PROPERTY);
 for (int line = 1; line <= file.lines(); line++) {
  NewIssue newIssue = context.newIssue();
  newIssue
   .forRule(ruleKey)
   .at(newIssue.newLocation()
    .on(file)
    .at(file.selectLine(line))
    .message("This issue is generated on each line"))
   .overrideSeverity(severity != null ? Severity.valueOf(severity) : null);
  if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(5, 5))) {
   newIssue.gap(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY));
  } else {
   newIssue.effortToFix(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY));
  }
  newIssue.save();
 }
}
origin: SonarSource/sonarqube

private static void createIssues(InputFile file, SensorContext context, String repo) {
 RuleKey ruleKey = RuleKey.of(repo, RULE_KEY);
 for (int line = 1; line <= file.lines(); line++) {
  TextRange text = file.selectLine(line);
  // do not count empty lines, which can be a pain with end-of-file return
  if (text.end().lineOffset() == 0) {
   continue;
  }
  NewIssue newIssue = context.newIssue();
  newIssue
   .forRule(ruleKey)
   .at(newIssue.newLocation()
    .on(file)
    .at(text)
    .message("This bug issue is generated on each line"))
   .save();
 }
}
origin: SonarSource/sonarqube

@Override
public synchronized void blameResult(InputFile file, List<BlameLine> lines) {
 Preconditions.checkNotNull(file);
 Preconditions.checkNotNull(lines);
 Preconditions.checkArgument(allFilesToBlame.contains(file), "It was not expected to blame file %s", file);
 if (lines.size() != file.lines()) {
  LOG.debug("Ignoring blame result since provider returned {} blame lines but file {} has {} lines", lines.size(), file, file.lines());
  return;
 }
 Builder scmBuilder = ScannerReport.Changesets.newBuilder();
 DefaultInputFile inputFile = (DefaultInputFile) file;
 scmBuilder.setComponentRef(inputFile.batchId());
 Map<String, Integer> changesetsIdByRevision = new HashMap<>();
 int lineId = 1;
 for (BlameLine line : lines) {
  validateLine(line, lineId, file);
  Integer changesetId = changesetsIdByRevision.get(line.revision());
  if (changesetId == null) {
   addChangeset(scmBuilder, line);
   changesetId = scmBuilder.getChangesetCount() - 1;
   changesetsIdByRevision.put(line.revision(), changesetId);
  }
  scmBuilder.addChangesetIndexByLine(changesetId);
  lineId++;
 }
 writer.writeComponentChangesets(scmBuilder.build());
 allFilesToBlame.remove(file);
 count++;
 progressReport.message(count + "/" + total + " files analyzed");
}
origin: org.codehaus.sonar/sonar-batch

static void save(org.sonar.api.batch.sensor.SensorContext context, InputFile inputFile, @Nullable Iterable<CloneGroup> duplications) {
 if (duplications == null || Iterables.isEmpty(duplications)) {
  return;
 }
 Set<Integer> duplicatedLines = new HashSet<Integer>();
 int duplicatedBlocks = computeBlockAndLineCount(duplications, duplicatedLines);
 Map<Integer, Integer> duplicationByLine = new HashMap<Integer, Integer>();
 for (int i = 1; i <= inputFile.lines(); i++) {
  duplicationByLine.put(i, duplicatedLines.contains(i) ? 1 : 0);
 }
 saveMeasures(context, inputFile, duplicatedLines, duplicatedBlocks, duplicationByLine);
 saveDuplications(context, inputFile, duplications);
}
origin: org.codehaus.sonar/sonar-plugin-api

@Override
public DefaultIssue atLine(int line) {
 Preconditions.checkState(this.path != null && this.path instanceof InputFile, "atLine should be called after onFile.");
 Preconditions.checkArgument(line > 0, "line starts at 1, invalid value " + line + ".");
 int lines = ((InputFile) path).lines();
 Preconditions.checkArgument(line <= lines, "File " + path + " has " + lines + " lines. Unable to create issue at line " + line + ".");
 this.line = line;
 return this;
}
origin: Pablissimo/SonarTsPlugin

FileData(InputFile inputFile) {
 linesInFile = inputFile.lines();
 filename = inputFile.relativePath();
}
origin: org.codehaus.sonar/sonar-plugin-api

protected void validateLineArgument(InputFile inputFile, int line, String label) {
 Preconditions.checkArgument(line > 0 && line <= inputFile.lines(), "Invalid " + label + ": " + line + ". File " + inputFile + " has " + inputFile.lines()
  + " lines.");
}
origin: SonarSource/sonar-java

public int fileLength(File file) {
 return inputFromIOFile(file).lines();
}
origin: org.sonarsource.sonarqube/sonar-plugin-api

private void validateLine(int line) {
 checkState(line <= inputFile.lines(), "Line %s is out of range in the file %s (lines: %s)", line, inputFile, inputFile.lines());
 checkState(line > 0, "Line number must be strictly positive: %s", line);
}
org.sonar.api.batch.fsInputFilelines

Javadoc

Number of physical lines. This method supports all end-of-line characters. Formula is (number of line break + 1).

Returns 1 if the file is empty.
Returns 2 for foo\nbar.
Returns 3 for foo\nbar\n.

Popular methods of InputFile

  • file
    The underlying absolute java.io.File. It should not be used to read the file in the filesystem.
  • relativePath
    Relative path to module (for normal Sensors) or project (for SensorDescriptor#global() Sensors) base
  • absolutePath
    Normalized absolute path. File separator is forward slash ('/'), even on Microsoft Windows. This is
  • selectLine
    Returns a TextRange in the given file that select the full line.
  • newRange
    Returns a TextRange in the given file.
  • language
    Language, for example "java" or "php". Can be null if indexation of all files is enabled and no lang
  • type
    Does it contain main or test code ?
  • charset
    Charset to be used to decode this specific file.
  • path
    The underlying absolute Path. It should not be used to read the file in the filesystem.
  • contents
    Fetches the entire contents of the file, decoding with the #charset. Since 6.4 BOM is automatically
  • filename
  • inputStream
    Creates a stream of the file's contents. Depending on the runtime context, the source might be a fil
  • filename,
  • inputStream,
  • key,
  • newPointer,
  • status,
  • uri,
  • isEmpty,
  • toString

Popular classes and methods

  • setContentView (Activity)
  • setRequestProperty (URLConnection)
    Sets the value of the specified request header field. The value will only be used by the current URL
  • getSupportFragmentManager (FragmentActivity)
  • File (java.io)
    LocalStorage based File implementation for GWT. Should probably have used Harmony as a starting poin
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • URI (java.net)
    Represents a Uniform Resource Identifier (URI) reference. Aside from some minor deviations noted bel
  • Iterator (java.util)
    An iterator over a collection. Iterator takes the place of Enumeration in the Java Collections Frame
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Join (org.hibernate.mapping)

For IntelliJ IDEA,
Android Studio or Eclipse

  • Codota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutContact Us
  • Terms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)