001/* 002 * SonarQube 003 * Copyright (C) 2009-2016 SonarSource SA 004 * mailto:contact AT sonarsource DOT com 005 * 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.api.batch.sensor.error.internal; 021 022import org.sonar.api.batch.fs.InputFile; 023import org.sonar.api.batch.fs.TextPointer; 024import org.sonar.api.batch.sensor.error.AnalysisError; 025import org.sonar.api.batch.sensor.error.NewAnalysisError; 026import org.sonar.api.batch.sensor.internal.DefaultStorable; 027import org.sonar.api.batch.sensor.internal.SensorStorage; 028 029import com.google.common.base.Preconditions; 030 031public class DefaultAnalysisError extends DefaultStorable implements NewAnalysisError, AnalysisError { 032 private InputFile inputFile; 033 private String message; 034 private TextPointer location; 035 036 public DefaultAnalysisError() { 037 super(null); 038 } 039 040 public DefaultAnalysisError(SensorStorage storage) { 041 super(storage); 042 } 043 044 @Override 045 public InputFile inputFile() { 046 return inputFile; 047 } 048 049 @Override 050 public String message() { 051 return message; 052 } 053 054 @Override 055 public TextPointer location() { 056 return location; 057 } 058 059 @Override 060 public NewAnalysisError onFile(InputFile inputFile) { 061 Preconditions.checkArgument(inputFile != null, "Cannot use a inputFile that is null"); 062 Preconditions.checkState(this.inputFile == null, "onFile() already called"); 063 this.inputFile = inputFile; 064 return this; 065 } 066 067 @Override 068 public NewAnalysisError message(String message) { 069 this.message = message; 070 return this; 071 } 072 073 @Override 074 public NewAnalysisError at(TextPointer location) { 075 Preconditions.checkState(this.location == null, "at() already called"); 076 this.location = location; 077 return this; 078 } 079 080 @Override 081 protected void doSave() { 082 Preconditions.checkNotNull(this.inputFile, "inputFile is mandatory on AnalysisError"); 083 storage.store(this); 084 } 085 086}