package jetbrains.mps.smodel.search;
/*Generated by MPS */
import org.jetbrains.annotations.NotNull;
import java.util.List;
import org.jetbrains.mps.openapi.model.SNode;
import org.jetbrains.mps.util.Condition;
import jetbrains.mps.scope.Scope;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.util.SNodeOperations;
import org.jetbrains.mps.openapi.model.SReference;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
/**
* @Deprecated
*/
@Deprecated
public interface ISearchScope {
@NotNull
List<SNode> getNodes(Condition<SNode> condition);
boolean isInScope(SNode node);
@NotNull
List<SNode> getNodes();
IReferenceInfoResolver getReferenceInfoResolver(SNode referenceNode, SNode targetConcept);
class Adapter extends Scope {
protected final ISearchScope searchScope;
public Adapter(ISearchScope searchScope) {
this.searchScope = searchScope;
}
@Override
public SNode resolve(SNode anchor, String refText) {
return null;
}
@Override
public Iterable<SNode> getAvailableElements(@Nullable final String prefix) {
if ((prefix == null || prefix.length() == 0)) {
return searchScope.getNodes();
}
return searchScope.getNodes(new Condition<SNode>() {
@Override
public boolean met(SNode p0) {
if (p0 == null) {
return false;
}
String presentation = getReferenceText(null, p0);
return presentation != null && presentation.startsWith(prefix);
}
});
}
@Override
public String getReferenceText(SNode anchor, SNode target) {
String resolveInfo = SNodeOperations.getResolveInfo(target);
if ((resolveInfo != null && resolveInfo.length() > 0)) {
return resolveInfo;
}
return target.getPresentation();
}
public ISearchScope getSearchScope() {
return searchScope;
}
@Override
public boolean contains(SNode node) {
return this.searchScope.isInScope(node);
}
}
class RefAdapter extends ISearchScope.Adapter {
@Nullable
private final SReference reference;
public RefAdapter(ISearchScope searchScope, @NotNull SReference reference) {
super(searchScope);
this.reference = reference;
}
@Override
public SNode resolve(SNode anchor, String refText) {
SNode sourceNode = reference.getSourceNode();
String role = reference.getRole();
SNode mostSpecificLink = new ConceptAndSuperConceptsScope(jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations.getConceptDeclaration(sourceNode)).getMostSpecificLinkDeclarationByRole(role);
if (mostSpecificLink == null) {
return null;
}
IReferenceInfoResolver infoResolver = searchScope.getReferenceInfoResolver(sourceNode, SLinkOperations.getTarget(jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations.cast(mostSpecificLink, MetaAdapterFactory.getConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, "jetbrains.mps.lang.structure.structure.LinkDeclaration")), MetaAdapterFactory.getReferenceLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf98055fef0L, "target")));
if (infoResolver == null) {
return null;
}
return infoResolver.resolve(refText, reference.getTargetSModelReference());
}
}
}