blob: 919d09f45cb34d6c9f526611fd70562a4f4ca7ae [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2015, 2020 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;
import java.util.List;
import org.eclipse.statet.ltk.model.core.elements.IModelElement;
import org.eclipse.statet.r.core.model.IRFrame;
import org.eclipse.statet.r.core.model.IRMethod;
import org.eclipse.statet.r.core.model.RElementName;
import org.eclipse.statet.r.core.model.RModel;
import org.eclipse.statet.r.ui.sourceediting.RFrameSearchPath;
import org.eclipse.statet.r.ui.sourceediting.RFrameSearchPath.RFrameIterator;
public class FCallNamePattern {
private final RElementName elementName;
private final String packageName;
private final String assignName;
private final int assignLength;
public FCallNamePattern(final RElementName name) {
this.elementName= name;
this.packageName= (name.getScope() != null
&& RElementName.isPackageFacetScopeType(name.getScope().getType()) ) ?
name.getScope().getSegmentName() : null;
if (this.elementName.getNextSegment() == null) {
this.assignName= this.elementName.getSegmentName();
this.assignLength= this.assignName.length();
}
else {
this.assignName= null;
this.assignLength= 0;
}
}
public final RElementName getElementName() {
return this.elementName;
}
public boolean matches(final RElementName candidateName) {
String candidate0;
return (candidateName != null
&& (this.elementName.equals(candidateName)
|| (this.assignName != null && candidateName.getNextSegment() == null
&& this.assignLength == (candidate0= candidateName.getSegmentName()).length() - 2
&& this.elementName.getType() == candidateName.getType()
&& candidate0.charAt(this.assignLength) == '<' && candidate0.charAt(this.assignLength + 1) == '-'
&& candidate0.regionMatches(false, 0, this.assignName, 0, this.assignLength) )));
}
public void searchFDef(final RFrameSearchPath searchPath) {
ITER_FRAMES: for (final RFrameIterator iter= searchPath.iterator(); iter.hasNext(); ) {
final IRFrame frame= iter.next();
if (this.packageName != null) {
final RElementName frameName= frame.getElementName();
if (!(frameName != null
&& RElementName.isPackageFacetScopeType(frameName.getType())
&& this.packageName.equals(frameName.getSegmentName()) )) {
continue ITER_FRAMES;
}
}
final List<? extends IModelElement> elements= frame.getModelChildren(null);
for (final IModelElement candidate : elements) {
if (candidate.getModelTypeId() == RModel.R_TYPE_ID
&& (candidate.getElementType() & IModelElement.MASK_C1) == IModelElement.C1_METHOD
&& matches((RElementName) candidate.getElementName()) ) {
handleMatch((IRMethod) candidate, frame, iter);
}
}
}
}
protected void handleMatch(final IRMethod element, final IRFrame frame,
final RFrameIterator iterator) {
}
}