blob: 7c3ac389c51c65fbb8e873d2241019af6328e705 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2009, 2021 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.internal.r.core.builder;
import java.util.List;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.statet.internal.r.core.sourcemodel.RModelManagerImpl;
import org.eclipse.statet.internal.r.core.sourcemodel.RReconciler;
import org.eclipse.statet.r.core.RCore;
import org.eclipse.statet.r.core.RProject;
import org.eclipse.statet.r.core.model.RModel;
import org.eclipse.statet.r.core.model.RSourceUnit;
import org.eclipse.statet.r.core.model.RSourceUnitModelInfo;
import org.eclipse.statet.r.core.model.build.RSourceUnitModelContainer;
import org.eclipse.statet.r.core.rsource.ast.RAstNode;
import org.eclipse.statet.r.core.rsource.ast.SourceComponent;
public class RBuildReconciler extends RReconciler {
private final RTaskMarkerHandler taskScanner;
private MultiStatus statusCollector;
public RBuildReconciler(final RModelManagerImpl manager) {
super(manager);
this.taskScanner= new RTaskMarkerHandler();
}
public void init(final RProject project, final MultiStatus status) throws CoreException {
this.taskScanner.init(project);
this.statusCollector= status;
}
/** for file build
* @throws CoreException
**/
public RSourceUnitModelInfo build(final RSourceUnitModelContainer adapter, final IProgressMonitor monitor) {
final RSourceUnit su= adapter.getSourceUnit();
final int type= (su.getModelTypeId().equals(RModel.R_TYPE_ID) ? su.getElementType() : 0);
if (type == 0) {
return null;
}
if (this.stop || monitor.isCanceled()) {
throw new OperationCanceledException();
}
final Data data= new Data(adapter, monitor);
if (data.content == null) {
return null;
}
if (this.stop || monitor.isCanceled()) {
throw new OperationCanceledException();
}
updateAst(data, monitor);
if (this.stop || monitor.isCanceled()) {
throw new OperationCanceledException();
}
updateModel(data);
if (this.stop || monitor.isCanceled()) {
throw new OperationCanceledException();
}
// final ProblemRequestor problemRequestor= su.getProblemRequestor();
// if (problemRequestor != null) {
// problemRequestor.beginReportingSequence();
try {
final List<RAstNode> comments= ((SourceComponent) data.ast.getRoot()).getComments();
this.taskScanner.setup(data.content, (IResource)su.getResource());
for (final RAstNode comment : comments) {
this.taskScanner.checkForTasks(
comment.getStartOffset() + 1, comment.getEndOffset() );
}
}
catch (final Exception e) {
this.statusCollector.add(new Status(IStatus.ERROR, RCore.BUNDLE_ID, 0,
"Failed to create task marker(s).", e ));
}
// f2SyntaxReporter.run(su, ast, problemRequestor);
// problemRequestor.endReportingSequence();
// }
if (this.stop || monitor.isCanceled()) {
throw new OperationCanceledException();
}
return data.newModel;
}
}