blob: 835aa1ee7898daf21dfa4a523033a27fb12aba29 [file] [log] [blame]
/*
* Copyright 2016 The Bazel Authors. 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.idea.blaze.cpp;
import com.google.common.collect.ImmutableList;
import com.google.idea.blaze.base.model.BlazeProjectData;
import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
import com.google.idea.blaze.base.projectview.ProjectViewSet;
import com.google.idea.blaze.base.scope.BlazeContext;
import com.google.idea.sdkcompat.cidr.OCWorkspaceAdapter;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.jetbrains.cidr.lang.symbols.OCSymbol;
import com.jetbrains.cidr.lang.workspace.OCResolveConfiguration;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nullable;
/** Main entry point for C/CPP configuration data. */
public final class BlazeCWorkspace extends OCWorkspaceAdapter {
private final BlazeConfigurationResolver configurationResolver;
private BlazeConfigurationResolverResult resolverResult;
private BlazeCWorkspace(Project project) {
super(project);
this.configurationResolver = new BlazeConfigurationResolver(project);
this.resolverResult = BlazeConfigurationResolverResult.empty(project);
}
public static BlazeCWorkspace getInstance(Project project) {
return ServiceManager.getService(project, BlazeCWorkspace.class);
}
public void update(
BlazeContext context,
WorkspaceRoot workspaceRoot,
ProjectViewSet projectViewSet,
BlazeProjectData blazeProjectData) {
BlazeConfigurationResolverResult oldResult = resolverResult;
resolverResult =
configurationResolver.update(
context, workspaceRoot, projectViewSet, blazeProjectData, oldResult);
}
@Override
public Collection<VirtualFile> getLibraryFilesToBuildSymbols() {
// This method should return all the header files themselves, not the head file directories.
// (And not header files in the project; just the ones in the SDK and in any dependencies)
return ImmutableList.of();
}
@Override
public boolean areFromSameProject(@Nullable VirtualFile a, @Nullable VirtualFile b) {
return false;
}
@Override
public boolean areFromSamePackage(@Nullable VirtualFile a, @Nullable VirtualFile b) {
return false;
}
@Override
public boolean isInSDK(@Nullable VirtualFile file) {
return false;
}
@Override
public boolean isFromWrongSDK(OCSymbol symbol, @Nullable VirtualFile contextFile) {
return false;
}
@Override
public List<BlazeResolveConfiguration> getConfigurations() {
return resolverResult.getAllConfigurations();
}
@Override
public List<? extends OCResolveConfiguration> getConfigurationsForFile(
@Nullable VirtualFile sourceFile) {
if (sourceFile == null || !sourceFile.isValid()) {
return ImmutableList.of();
}
OCResolveConfiguration config = resolverResult.getConfigurationForFile(sourceFile);
return config == null ? ImmutableList.of() : ImmutableList.of(config);
}
@Nullable
BlazeConfigurationResolverDiff getConfigurationDiff() {
return resolverResult.getConfigurationDiff();
}
}