blob: 7c2a58f5ee0ea503f38ee618c4f927fb4ff5543d [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2009, 2019 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.jcommons.text.core.TextLineInformation;
import org.eclipse.statet.internal.r.core.sourcemodel.RModelManager;
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.IRModelInfo;
import org.eclipse.statet.r.core.model.IRSourceUnit;
import org.eclipse.statet.r.core.model.RModel;
import org.eclipse.statet.r.core.model.RSuModelContainer;
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 RModelManager 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 IRModelInfo build(final RSuModelContainer adapter, final IProgressMonitor monitor) {
final IRSourceUnit 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((IResource) su.getResource());
final TextLineInformation lines= data.content.getLines();
for (final RAstNode comment : comments) {
final int offset= comment.getStartOffset() + 1;
this.taskScanner.checkForTasks(data.content.getText().substring(
offset, offset + comment.getLength() - 1 ), offset, lines );
}
}
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;
}
}