Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* SonarQube Java
* Copyright (C) 2012-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.java.model;
import com.sonar.sslr.api.RecognitionException;
import java.io.File;
import java.io.InterruptedIOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.StreamSupport;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.utils.AnnotationUtils;
import org.sonar.check.Rule;
import org.sonar.java.AnalysisException;
import org.sonar.java.CheckFailureException;
import org.sonar.java.ExceptionHandler;
import org.sonar.java.IllegalRuleParameterException;
import org.sonar.plugins.java.api.JavaVersionAwareVisitor;
import org.sonar.java.SonarComponents;
import org.sonar.java.annotations.VisibleForTesting;
import org.sonar.java.ast.visitors.SonarSymbolTableVisitor;
import org.sonar.java.ast.visitors.SubscriptionVisitor;
import org.sonar.java.caching.CacheContextImpl;
import org.sonar.java.exceptions.ApiMismatchException;
import org.sonar.java.exceptions.ThrowableUtils;
import org.sonar.plugins.java.api.InputFileScannerContext;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.JavaCheck;
import org.sonar.plugins.java.api.JavaFileScanner;
import org.sonar.plugins.java.api.JavaFileScannerContext;
import org.sonar.plugins.java.api.JavaVersion;
import org.sonar.plugins.java.api.ModuleScannerContext;
import org.sonar.plugins.java.api.caching.CacheContext;
import org.sonar.plugins.java.api.internal.EndOfAnalysis;
import org.sonar.plugins.java.api.tree.CompilationUnitTree;
import org.sonar.plugins.java.api.tree.SyntaxToken;
import org.sonar.plugins.java.api.tree.Tree;
import org.sonar.plugins.java.api.tree.Tree.Kind;
import org.sonarsource.performance.measure.PerformanceMeasure;
public class VisitorsBridge {
private static final Logger LOG = LoggerFactory.getLogger(VisitorsBridge.class);
private final Iterable extends JavaCheck> visitors;
private final List allScanners;
private final List scannersThatCannotBeSkipped;
private final SonarComponents sonarComponents;
protected InputFile currentFile;
protected final JavaVersion javaVersion;
private final List classpath;
protected boolean inAndroidContext = false;
private int fullyScannedFileCount = 0;
private int skippedFileCount = 0;
@VisibleForTesting
CacheContext cacheContext;
@VisibleForTesting
public VisitorsBridge(JavaFileScanner visitor) {
this(Collections.singletonList(visitor), new ArrayList<>(), null, new JavaVersionImpl());
}
@VisibleForTesting
public VisitorsBridge(Iterable extends JavaCheck> visitors, List projectClasspath, @Nullable SonarComponents sonarComponents) {
this(visitors, projectClasspath, sonarComponents, new JavaVersionImpl());
}
public VisitorsBridge(Iterable extends JavaCheck> visitors, List projectClasspath, @Nullable SonarComponents sonarComponents, JavaVersion javaVersion) {
this.visitors = visitors;
this.allScanners = new ArrayList<>();
this.scannersThatCannotBeSkipped = new ArrayList<>();
this.classpath = projectClasspath;
this.sonarComponents = sonarComponents;
this.cacheContext = CacheContextImpl.of(sonarComponents != null ? sonarComponents.context() : null);
this.javaVersion = javaVersion;
updateScanners();
}
private void updateScanners() {
allScanners.clear();
scannersThatCannotBeSkipped.clear();
allScanners.addAll(filterVisitors(visitors, this::isVisitorJavaVersionCompatible));
if (canSkipScanningOfUnchangedFiles()) {
scannersThatCannotBeSkipped.addAll(filterVisitors(visitors, this::isUnskippableVisitor));
}
}
private List filterVisitors(Iterable extends JavaCheck> visitors, Predicate