/*
 * Copyright 2014 Google Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.devtools.kythe.platform.java;


import com.google.common.collect.ImmutableList;
import com.google.devtools.kythe.common.FormattingLogger;
import com.google.devtools.kythe.platform.shared.AnalysisException;
import com.google.devtools.kythe.platform.shared.FileDataProvider;
import com.google.devtools.kythe.proto.Analysis.CompilationUnit;

import com.sun.tools.javac.api.JavacTool;

import java.util.List;

import javax.annotation.processing.Processor;
import javax.tools.JavaCompiler;

/**
 * Base implementation for the various analysis drivers.
 * Allows running {@link JavacAnalyzer} over compilations that are retrieved from various locations.
 */
public class JavacAnalysisDriver {
  private static final FormattingLogger logger =
      FormattingLogger.getLogger(JavacAnalysisDriver.class);
  private final List<Processor> processors;

  public JavacAnalysisDriver() {
    this(ImmutableList.<Processor>of());
  }

  public JavacAnalysisDriver(List<Processor> processors) {
    this.processors = processors;
  }

  /**
   * Provides a {@link JavaCompiler} that this code is compiled with instead of the default behavior
   * of loading the {@link JavaCompiler} available at runtime. This is needed to run the Java 6
   * compiler on the Java 7 runtime.
   */
  public static JavaCompiler getCompiler() {
    return JavacTool.create();
  }

  public void analyze(JavacAnalyzer analyzer, CompilationUnit compilationUnit,
      FileDataProvider fileDataProvider, boolean isLocalAnalysis) throws AnalysisException {
    JavaCompilationDetails details =
        JavaCompilationDetails.createDetails(compilationUnit, fileDataProvider, isLocalAnalysis, processors);
    if (details == null) {
      throw new AnalysisException(
          "Could not build javac compilation details; perhaps missing javac arguments?");
    }

    analyzer.analyzeCompilationUnit(details);
  }
}

@@ -2153,49 +2153,40 @@
     
-JavaCompilationDetails details =%0A        
+analyzer.analyzeCompilationUnit(
 Java
@@ -2203,16 +2203,25 @@
 nDetails
+%0A        
 .createD
@@ -2294,212 +2294,8 @@
 ors)
-;%0A    if (details == null) %7B%0A      throw new AnalysisException(%0A          %22Could not build javac compilation details; perhaps missing javac arguments?%22);%0A    %7D%0A%0A    analyzer.analyzeCompilationUnit(details
 );%0A 

Remove unneeded null check