1 /* 2 * Copyright 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.webkit.internal.codegen; 18 19 import com.android.tools.lint.LintCoreApplicationEnvironment; 20 import com.android.tools.lint.LintCoreProjectEnvironment; 21 22 import com.intellij.openapi.Disposable; 23 import com.intellij.openapi.util.Disposer; 24 25 /** 26 * Utility class for setting up the PSI environment. 27 * PSI is normally used within IntelliJ which means parts of the interface between PSI and the rest 28 * of IntelliJ need to be initialized in a specific way, or mocked, when using PSI from the command 29 * line. 30 */ 31 public class PsiProjectSetup { 32 public static final LintCoreProjectEnvironment sProjectEnvironment = createProjectEnvironment(); 33 34 private static LintCoreProjectEnvironment createProjectEnvironment() { 35 // Lint already uses PSI from the command line - so we copy their project configuration. 36 LintCoreApplicationEnvironment appEnv = LintCoreApplicationEnvironment.get(); 37 38 Disposable parentDisposable = Disposer.newDisposable(); 39 LintCoreProjectEnvironment projectEnvironment = 40 LintCoreProjectEnvironment.create(parentDisposable, appEnv); 41 42 return projectEnvironment; 43 } 44 } 45