blob: 648c5d386e781d72e8ebd69f822821567bf3ff09 [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.ui.editors;
import org.eclipse.jface.text.contentassist.IContextInformationExtension;
import org.eclipse.swt.graphics.Image;
import org.eclipse.statet.jcommons.collections.IntArrayList;
import org.eclipse.statet.jcommons.collections.IntList;
import org.eclipse.statet.ltk.ui.sourceediting.assist.IAssistInformationProposal;
import org.eclipse.statet.r.core.model.ArgsDefinition;
import org.eclipse.statet.r.core.model.IRMethod;
import org.eclipse.statet.r.ui.RLabelProvider;
public class RArgumentListContextInformation implements IAssistInformationProposal,
IContextInformationExtension {
private final int offset;
private final ArgsDefinition args;
private final String information;
private final int[] informationIndexes;
public RArgumentListContextInformation(final int offset, final IRMethod method) {
this.offset= offset;
this.args= method.getArgsDefinition();
final StringBuilder sb= new StringBuilder();
final IntList idxs= new IntArrayList();
new RLabelProvider().appendArgumentInformation(sb, idxs, this.args);
this.information= sb.toString();
this.informationIndexes= idxs.toArray();
}
public ArgsDefinition getArguments() {
return this.args;
}
@Override
public Image getImage() {
return null;
}
@Override
public String getContextDisplayString() {
return getInformationDisplayString();
}
@Override
public int getContextInformationPosition() {
return Math.max(this.offset, 0);
}
@Override
public String getInformationDisplayString() {
return this.information;
}
public int[] getInformationDisplayStringArgumentIdxs() {
return this.informationIndexes;
}
@Override
public boolean equals(final Object obj) {
// prevent stacking of context information at the same position
return true;
}
}