blob: d19b73f2be05b6feac5e63cf87a7229ff73e066c [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.jcommons.lang.NonNullByDefault;
import org.eclipse.statet.jcommons.lang.Nullable;
import org.eclipse.statet.ltk.ui.sourceediting.assist.AssistInformationProposal;
import org.eclipse.statet.r.core.model.ArgsDefinition;
import org.eclipse.statet.r.core.model.IRMethod;
import org.eclipse.statet.r.ui.RLabelProvider;
@NonNullByDefault
public class RArgumentListContextInformation implements AssistInformationProposal,
IContextInformationExtension {
private final int offset; // can be negative for FragmentDocument
private final @Nullable ArgsDefinition args;
private final String information;
private final int[] informationArgumentIdxs;
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.informationArgumentIdxs= idxs.toArray();
}
public int getCallArgsOffset() {
return this.offset;
}
public @Nullable ArgsDefinition getArgsDefinition() {
return this.args;
}
@Override
public String getContextDisplayString() {
return getInformationDisplayString();
}
@Override
public @Nullable Image getImage() {
return null;
}
@Override
public int getContextInformationPosition() {
return Math.max(this.offset, 0);
}
@Override
public String getInformationDisplayString() {
return this.information;
}
public int[] getInformationDisplayStringArgumentIdxs() {
return this.informationArgumentIdxs;
}
@Override
public boolean equals(final @Nullable Object obj) {
// prevent stacking of context information at the same position
return true;
}
}