Java 类org.eclipse.xtext.util.ITextRegion 实例源码

项目:solidity-ide    文件:SolidityFoldingRegionProvider.java   
@Override
protected void computeCommentFolding(IXtextDocument xtextDocument,
        IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor, ITypedRegion typedRegion,
        boolean initiallyFolded) {

    String text;
    try {
        text = xtextDocument.get(typedRegion.getOffset(), typedRegion.getLength());
        int lines = Strings.countLines(text);
        if (shouldCreateCommentFolding(lines)) {
            boolean collapse = shouldCollapse(typedRegion, lines);
            super.computeCommentFolding(xtextDocument, foldingRegionAcceptor, typedRegion, collapse);
        }
    } catch (BadLocationException e) {
        log.error(e, e);
    }

}
项目:xtext-extras    文件:XbaseValidator.java   
protected void checkNoJavaStyleTypeCasting(INode node) {
    BidiTreeIterator<INode> iterator = node.getAsTreeIterable().reverse().iterator();
    ILeafNode child = getFirstLeafNode(iterator);
    if (child != null && child.getGrammarElement() == grammarAccess.getXParenthesizedExpressionAccess().getRightParenthesisKeyword_2()) {
        INode expressionNode = getNode(iterator, grammarAccess.getXParenthesizedExpressionAccess().getXExpressionParserRuleCall_1());
        EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(expressionNode);
        if (semanticObject instanceof XFeatureCall || semanticObject instanceof XMemberFeatureCall) {
            XAbstractFeatureCall featureCall = (XAbstractFeatureCall) semanticObject;
            if (featureCall.isTypeLiteral()) {
                ICompositeNode parenthesizedNode = child.getParent();
                ITextRegion parenthesizedRegion = parenthesizedNode.getTextRegion();
                addIssue("Use 'as' keyword for type casting.", featureCall, parenthesizedRegion.getOffset(), parenthesizedRegion.getLength(), JAVA_STYLE_TYPE_CAST);
            }
        }
    }
}
项目:xtext-extras    文件:XbaseLocationInFileProvider.java   
@Override
public ITextRegion getSignificantTextRegion(EObject element) {
    if (element instanceof XAbstractFeatureCall) {
        XAbstractFeatureCall typeLiteral = typeLiteralHelper.getRootTypeLiteral((XAbstractFeatureCall) element);
        if (typeLiteral != null) {
            if (typeLiteral instanceof XMemberFeatureCall) {
                XAbstractFeatureCall target = (XAbstractFeatureCall) ((XMemberFeatureCall) typeLiteral).getMemberCallTarget();
                if (target.isTypeLiteral()) {
                    return super.getSignificantTextRegion(typeLiteral);
                }
            }
            INode node = NodeModelUtils.findActualNodeFor(typeLiteral);
            if (node != null) {
                return toZeroBasedRegion(node.getTextRegionWithLineInformation());
            }
        }
    }
    return super.getSignificantTextRegion(element);
}
项目:xtext-core    文件:StringBasedTextRegionAccessDiffBuilder.java   
@Override
public boolean isModified(ITextRegion region) {
    int offset = region.getOffset();
    int endOffset = offset + region.getLength();
    for (RewriteAction action : rewrites) {
        int rwOffset = action.originalFirst.getOffset();
        int rwEndOffset = action.originalLast.getEndOffset();
        if (rwOffset <= offset && offset < rwEndOffset) {
            return true;
        }
        if (rwOffset < endOffset && endOffset <= rwEndOffset) {
            return true;
        }
    }
    return false;
}
项目:xtext-core    文件:AbstractTraceRegionToString.java   
protected boolean shouldInclude(final AbstractTraceRegion region, final ILocationData location) {
  SourceRelativeURI _elvis = null;
  SourceRelativeURI _srcRelativePath = location.getSrcRelativePath();
  if (_srcRelativePath != null) {
    _elvis = _srcRelativePath;
  } else {
    SourceRelativeURI _associatedSrcRelativePath = region.getAssociatedSrcRelativePath();
    _elvis = _associatedSrcRelativePath;
  }
  final ITextRegion frame = this.getRemoteFrame(_elvis);
  if ((frame == null)) {
    return true;
  } else {
    return frame.contains(location);
  }
}
项目:xtext-core    文件:DefaultNodeModelFormatter.java   
@Override
public IFormattedRegion format(ICompositeNode root, int offset, int length) {
    String indent = getIndentation(root, offset);
    TokenStringBuffer buf = new TokenStringBuffer();
    ITokenStream out = offset == 0 ? buf : new FilterFirstWhitespaceStream(buf);
    ITokenStream fmt;
    if (formatter instanceof IFormatterExtension) {
        EObject semanticElement = NodeModelUtils.findActualSemanticObjectFor(root);
        if (semanticElement != null)
            fmt = ((IFormatterExtension) formatter).createFormatterStream(semanticElement, indent, out, false);
        else {
            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=380406
            ITextRegion rootRegion = root.getTextRegion();
            return new FormattedRegion(rootRegion.getOffset(), rootRegion.getLength(), root.getText());
        }
    } else
        fmt = formatter.createFormatterStream(indent, out, false);
    try {
        ITextRegion range = nodeModelStreamer.feedTokenStream(fmt, root, offset, length);
        return new FormattedRegion(range.getOffset(), range.getLength(), buf.toString());
    } catch (IOException e) {
        // this should never happen since TokenStringBuffer doesn't throw IOEs.
        throw new RuntimeException(e);
    }
}
项目:xtext-extras    文件:TreeAppendableUtil.java   
public ITreeAppendable traceSignificant(final ITreeAppendable appendable, final EObject source, final boolean useForDebugging) {
  ITreeAppendable _xifexpression = null;
  if ((appendable instanceof TreeAppendable)) {
    _xifexpression = ((TreeAppendable)appendable).trace(source, ILocationInFileProviderExtension.RegionDescription.SIGNIFICANT, useForDebugging);
  } else {
    ITreeAppendable _xblockexpression = null;
    {
      ITextRegion _significantTextRegion = this.locationProvider.getSignificantTextRegion(source);
      final ITextRegionWithLineInformation it = ((ITextRegionWithLineInformation) _significantTextRegion);
      ITreeAppendable _xifexpression_1 = null;
      if (((it != null) && (it != ITextRegion.EMPTY_REGION))) {
        int _offset = it.getOffset();
        int _length = it.getLength();
        int _lineNumber = it.getLineNumber();
        int _endLineNumber = it.getEndLineNumber();
        LocationData _locationData = new LocationData(_offset, _length, _lineNumber, _endLineNumber, null);
        _xifexpression_1 = appendable.trace(_locationData, useForDebugging);
      } else {
        _xifexpression_1 = appendable;
      }
      _xblockexpression = _xifexpression_1;
    }
    _xifexpression = _xblockexpression;
  }
  return _xifexpression;
}
项目:xtext-core    文件:DefaultDocumentHighlightService.java   
/**
 * Returns with {@code true} if the AST element selected from the resource
 * can provide document highlights, otherwise returns with {@code false}.
 * 
 * <p>
 * Clients may override this method to change the default behavior.
 * 
 * @param selectedElemnt
 *            the selected element resolved via the offset from the
 *            resource. Can be {@code null}.
 * @param resource
 *            the resource for the document.
 * @param offset
 *            the offset of the selection.
 * 
 * @return {@code true} if the document highlight is available for the
 *         selected element, otherwise {@code false}.
 *
 */
protected boolean isDocumentHighlightAvailableFor(final EObject selectedElemnt, final XtextResource resource,
        final int offset) {

    if (selectedElemnt == null || !getSelectedElementFilter().apply(selectedElemnt)) {
        return false;
    }

    final EObject containedElement = offsetHelper.resolveContainedElementAt(resource, offset);
    // Special handling to avoid such cases when the selection is not
    // exactly on the desired element.
    if (selectedElemnt == containedElement) {
        final ITextRegion region = locationInFileProvider.getSignificantTextRegion(containedElement);
        return !isNullOrEmpty(region)
                // Region is comparable to a selection in an editor,
                // therefore the end position is exclusive.
                && (region.contains(offset) || (region.getOffset() + region.getLength()) == offset);
    }

    return true;
}
项目:xtext-core    文件:DefaultLocationInFileProvider.java   
/**
 * @since 2.3
 */
protected ITextRegion getLocationOfContainmentReference(final EObject owner, EReference feature,
        final int indexInList, RegionDescription query) {
    Object referencedElement = null;
    if(feature.isMany()) {
        List<?> values = (List<?>) owner.eGet(feature);
        if(indexInList >= values.size())
            referencedElement = owner;
        else
            referencedElement = values.get(indexInList);
    }
    else {
        referencedElement = owner.eGet(feature);
    }
    return getTextRegion((EObject) referencedElement, query);
}
项目:xtext-core    文件:TokenRegionProviderTest.java   
@Test 
    public void testTokenRegionContainsRegion() throws Exception {
        String modelAsString = "a1 / /* comment */ b2";
        List<CommonToken> tokens = getTokens(modelAsString);
        for(int length=0; length < modelAsString.length(); ++length) {
            for(int offset = 0; offset + length < modelAsString.length(); ++offset) {
                ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(modelAsString, new TextRegion(offset, length));
//              System.out.println(offset + ":" + length + " -> " + tokenRegion);
                CommonToken firstToken = findTokenStartingAt(tokenRegion.getOffset(), tokens);
                assertTrue(firstToken.getStartIndex() <= offset);
                if(tokenRegion.getLength() != 0) {
                    CommonToken lastToken = findTokenStopingAt(tokenRegion.getOffset() + tokenRegion.getLength()-1, tokens);
                    assertTrue(lastToken.getStopIndex() >= offset + length -1);
                }
            }
        }
    }
项目:xtext-core    文件:AbstractFormatter2.java   
protected boolean isInRequestedRange(EObject obj) {
    Collection<ITextRegion> regions = request.getRegions();
    if (regions.isEmpty())
        return true;
    ITextRegionAccess access = request.getTextRegionAccess();
    IEObjectRegion objRegion = access.regionForEObject(obj);
    if (objRegion == null)
        return false;
    IHiddenRegion previousHidden = objRegion.getPreviousHiddenRegion();
    IHiddenRegion nextHidden = objRegion.getNextHiddenRegion();
    int objOffset = previousHidden != null ? previousHidden.getOffset() : 0;
    int objEnd = nextHidden != null ? nextHidden.getEndOffset() : access.regionForRootEObject().getEndOffset();
    for (ITextRegion region : regions) {
        int regionOffset = region.getOffset();
        int regionEnd = regionOffset + region.getLength();
        if (regionOffset <= objEnd && regionEnd >= objOffset)
            return true;
    }
    return false;
}
项目:xtext-core    文件:FormattingService.java   
protected List<ITextReplacement> format2(final XtextResource resource, final ITextRegion selection, final ITypedPreferenceValues preferences) {
  final FormatterRequest request = this.formatterRequestProvider.get();
  request.setAllowIdentityEdits(false);
  request.setFormatUndefinedHiddenRegionsOnly(false);
  if ((selection != null)) {
    request.setRegions(Collections.<ITextRegion>unmodifiableList(CollectionLiterals.<ITextRegion>newArrayList(selection)));
  }
  if ((preferences != null)) {
    request.setPreferences(preferences);
  }
  final ITextRegionAccess regionAccess = this.regionBuilder.forNodeModel(resource).create();
  request.setTextRegionAccess(regionAccess);
  final IFormatter2 formatter2 = this.formatter2Provider.get();
  final List<ITextReplacement> replacements = formatter2.format(request);
  return replacements;
}
项目:solidity-ide    文件:SolidityFoldingRegionProvider.java   
@Override
protected void computeObjectFolding(EObject eObject, IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor,
        boolean initiallyFolded) {
    if (FOLDING_TYPES.contains(eObject.eClass())) {
        super.computeObjectFolding(eObject, foldingRegionAcceptor, initiallyFolded);
    }
}
项目:xtext-core    文件:AbstractTraceRegionToString.java   
protected void add(final Map<SourceRelativeURI, AbstractTraceRegionToString.File> files, final SourceRelativeURI uri, final ITextRegion it, final AbstractTraceRegionToString.RegionHandle region, final AbstractTraceRegionToString.LocationHandle location) {
  AbstractTraceRegionToString.File file = files.get(uri);
  if ((file == null)) {
    AbstractTraceRegionToString.File _file = new AbstractTraceRegionToString.File(uri);
    AbstractTraceRegionToString.File _file_1 = file = _file;
    files.put(uri, _file_1);
  }
  this.add(file, it, region, location);
}
项目:xtext-extras    文件:TreeAppendable.java   
@Override
public ITreeAppendable trace(EObject object, EStructuralFeature feature, int indexInList) {
    ITextRegion textRegion = locationProvider.getFullTextRegion(object, feature, indexInList);
    if (!(textRegion instanceof ITextRegionWithLineInformation)) {
        if (log.isDebugEnabled())
            log.debug("location provider returned text region without line information. Synthesized dummy data.", new Exception());
        textRegion = new TextRegionWithLineInformation(textRegion.getOffset(), textRegion.getLength(), 0, 0);
    } 
    if (textRegion == ITextRegion.EMPTY_REGION) {
        return this;
    }
    ILocationData newData = createLocationData(traceURIConverter, object, (ITextRegionWithLineInformation) textRegion);
    return trace(Collections.singleton(newData), false);
}
项目:xtext-extras    文件:ImportedTypesCollector.java   
private boolean isIgnored(JvmType type, ITextRegion refRegion) {
    IParseResult parseResult = getResource().getParseResult();
    if (parseResult == null) {
        return false;
    }
    String completeText = parseResult.getRootNode().getText();
    CharSequence refText = completeText.subSequence(refRegion.getOffset(), refRegion.getOffset() + refRegion.getLength());
    return type.getQualifiedName().equals(refText);
}
项目:xtext-extras    文件:RewritableImportSection.java   
public List<ReplaceRegion> rewrite() {
    removeObsoleteStaticImports();
    final List<ReplaceRegion> replaceRegions = newArrayList();
    if (isSort) {
        List<XImportDeclaration> allImportDeclarations = newArrayList();
        allImportDeclarations.addAll(originalImportDeclarations);
        allImportDeclarations.addAll(addedImportDeclarations);
        allImportDeclarations.removeAll(removedImportDeclarations);
        String newImportSection = serializeImports(allImportDeclarations);
        importRegion = regionUtil.addLeadingWhitespace(importRegion, resource);
        importRegion = regionUtil.addTrailingWhitespace(importRegion, resource);
        return singletonList(new ReplaceRegion(importRegion, newImportSection));
    } else {
        for (XImportDeclaration removedImportDeclaration : removedImportDeclarations) {
            ICompositeNode node = NodeModelUtils.findActualNodeFor(removedImportDeclaration);
            if (node != null) {
                ITextRegion textRegion = node.getTextRegion();
                textRegion = regionUtil.addTrailingSingleWhitespace(textRegion, lineSeparator, resource);
                replaceRegions.add(new ReplaceRegion(textRegion, ""));
            }
        }
        addSectionToAppend(new IAcceptor<ReplaceRegion>() {
            @Override
            public void accept(ReplaceRegion t) {
                replaceRegions.add(t);
            }
        });
    }
    return replaceRegions;
}
项目:xtext-extras    文件:TypeUsageCollector.java   
protected void acceptPreferredType(EObject owner, EReference referenceToTypeOrMember) {
    ITextRegion refRegion = locationInFileProvider.getFullTextRegion(owner, referenceToTypeOrMember, 0);
    if (refRegion.getLength() > 0) {
        IParseResult parseResult = resource.getParseResult();
        if(parseResult != null) {
            String completeText = parseResult.getRootNode().getText();
            String refText = completeText.substring(refRegion.getOffset(), refRegion.getOffset() + refRegion.getLength());
            PreferredType preferredType = findPreferredType(owner, referenceToTypeOrMember, refText);
            if (preferredType != null) {
                if (preferredType.referencedType != null) {
                    acceptType(preferredType.referencedType, preferredType.usedType, refRegion);
                } else {
                    String suffix = refText.substring(preferredType.unresolvedTypeName.length());
                    if (owner instanceof XFeatureCall) {
                        XFeatureCall featureCall = (XFeatureCall) owner; 
                        if (typeLiteralHelper.isPotentialTypeLiteral(featureCall, null)) {
                            XAbstractFeatureCall root = typeLiteralHelper.getRootTypeLiteral(featureCall);
                            if (root != null) {
                                ITextRegion region = locationInFileProvider.getSignificantTextRegion(root);
                                if (region.getOffset() == refRegion.getOffset()) {
                                    suffix = completeText.substring(region.getOffset(), region.getOffset() + region.getLength());
                                    suffix = suffix.substring(preferredType.unresolvedTypeName.length());
                                    refRegion = region;
                                }
                            }
                        }
                    }
                    acceptUnresolvedType(preferredType.unresolvedTypeName, suffix, refRegion);
                }
            }
        }
    }
}
项目:xtext-core    文件:TokenRegionProviderTest.java   
@Test 
public void testBug486454() throws Exception {
    String model = "t";
    ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(1, 0));
    assertEquals(0, tokenRegion.getOffset());
    assertEquals(1, tokenRegion.getLength());
}
项目:xtext-core    文件:NodeModelStreamer.java   
@Override
public ITextRegion feedTokenStream(ITokenStream out, ICompositeNode in, int offset, int length) throws IOException {
    List<INode> nodes = getLeafs(in, offset, offset + length);
    if (nodes.isEmpty())
        return new TextRegion(in.getOffset(), 0);
    if (out instanceof ITokenStreamExtension)
        ((ITokenStreamExtension) out).init(findRootRuleForRegion(nodes.get(0)));
    boolean lastIsTokenOrComment = false;
    for (INode node : nodes) {
        boolean currentIsTokenOrComment = tokenUtil.isCommentNode(node) || tokenUtil.isToken(node);
        if (lastIsTokenOrComment && currentIsTokenOrComment)
            writeHiddenEmpty(out);
        lastIsTokenOrComment = currentIsTokenOrComment;
        if (node instanceof ILeafNode) {
            ILeafNode leaf = (ILeafNode) node;
            if (leaf.isHidden())
                writeHidden(out, leaf);
            else
                writeSemantic(out, leaf);
        } else if (node instanceof ICompositeNode)
            writeSemantic(out, (ICompositeNode) node);
    }
    out.flush();
    int rStart = nodes.get(0).getOffset();
    int rLength = nodes.get(nodes.size() - 1).getEndOffset() - rStart;
    return new TextRegion(rStart, rLength);
}
项目:xtext-core    文件:TextReplacerContext.java   
protected boolean isInRequestedRange(ITextReplacement repl) {
    Collection<ITextRegion> regions = document.getRequest().getRegions();
    if (regions.isEmpty())
        return true;
    for (org.eclipse.xtext.util.ITextRegion region : regions)
        if (region.getOffset() <= repl.getOffset()
                && region.getOffset() + region.getLength() >= repl.getEndOffset())
            return true;
    return false;
}
项目:xtext-extras    文件:TypeUsages.java   
public void addTypeUsage(
        JvmDeclaredType typeToImport,
        JvmDeclaredType usedType,
        ITextRegion textRegion,
        JvmMember context) {
    simpleName2types.put(typeToImport.getSimpleName(), typeToImport);
    types2usages.put(typeToImport, new TypeUsage(usedType, textRegion, context));
}
项目:xtext-core    文件:TokenRegionProviderTest.java   
@Test 
public void testTokenMerge() throws Exception {
    String model = "  ";
    ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(1, 0));
    assertEquals(0, tokenRegion.getOffset());
    assertEquals(2, tokenRegion.getLength());
}
项目:xtext-extras    文件:TreeAppendableUtil.java   
public ITreeAppendable traceWithComments(final ITreeAppendable appendable, final EObject source) {
  ITreeAppendable _xifexpression = null;
  if ((appendable instanceof TreeAppendable)) {
    _xifexpression = ((TreeAppendable)appendable).trace(source, ILocationInFileProviderExtension.RegionDescription.INCLUDING_COMMENTS, false);
  } else {
    ITreeAppendable _xblockexpression = null;
    {
      ITextRegion _switchResult = null;
      final ILocationInFileProvider locationProvider = this.locationProvider;
      boolean _matched = false;
      if (locationProvider instanceof ILocationInFileProviderExtension) {
        _matched=true;
        _switchResult = ((ILocationInFileProviderExtension)this.locationProvider).getTextRegion(source, ILocationInFileProviderExtension.RegionDescription.INCLUDING_COMMENTS);
      }
      if (!_matched) {
        _switchResult = this.locationProvider.getFullTextRegion(source);
      }
      final ITextRegionWithLineInformation it = ((ITextRegionWithLineInformation) _switchResult);
      ITreeAppendable _xifexpression_1 = null;
      if (((it != null) && (it != ITextRegion.EMPTY_REGION))) {
        int _offset = it.getOffset();
        int _length = it.getLength();
        int _lineNumber = it.getLineNumber();
        int _endLineNumber = it.getEndLineNumber();
        LocationData _locationData = new LocationData(_offset, _length, _lineNumber, _endLineNumber, null);
        _xifexpression_1 = appendable.trace(_locationData);
      } else {
        _xifexpression_1 = appendable;
      }
      _xblockexpression = _xifexpression_1;
    }
    _xifexpression = _xblockexpression;
  }
  return _xifexpression;
}
项目:xtext-core    文件:TokenRegionProviderTest.java   
@Test 
public void testTokenMerge_1() throws Exception {
    String model = " ab ";
    ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(2, 0));
    assertEquals(1, tokenRegion.getOffset());
    assertEquals(2, tokenRegion.getLength());
}
项目:xtext-extras    文件:ImportsCollector.java   
public EObject findActualSemanticObjectFor(final ICompositeNode rootNode, final ITextRegion textRegion) {
  ILeafNode leafNodeAtOffset = NodeModelUtils.findLeafNodeAtOffset(rootNode, textRegion.getOffset());
  EObject semanticElementOffset = leafNodeAtOffset.getSemanticElement();
  ICompositeNode actualOffsetNode = NodeModelUtils.findActualNodeFor(semanticElementOffset);
  int _offset = textRegion.getOffset();
  int _length = textRegion.getLength();
  final int endOffset = (_offset + _length);
  while (((actualOffsetNode.getParent() != null) && (actualOffsetNode.getTotalEndOffset() < endOffset))) {
    actualOffsetNode = actualOffsetNode.getParent();
  }
  final EObject actualSemanticObj = actualOffsetNode.getSemanticElement();
  return actualSemanticObj;
}
项目:xtext-core    文件:DefaultLocationInFileProvider.java   
/**
 * @since 2.3
 */
protected ITextRegion doGetTextRegion(EObject obj, /* @NonNull */ RegionDescription query) {
    ICompositeNode node = findNodeFor(obj);
    if (node == null) {
        if (obj.eContainer() == null)
            return ITextRegion.EMPTY_REGION;
        return getTextRegion(obj.eContainer(), query);
    }
    List<INode> nodes = null;
    if (query == RegionDescription.SIGNIFICANT)
        nodes = getLocationNodes(obj);
    if (nodes == null || nodes.isEmpty())
        nodes = Collections.<INode>singletonList(node);
    return createRegion(nodes, query);
}
项目:xtext-core    文件:DefaultLocationInFileProvider.java   
protected ITextRegion createRegion(final List<INode> nodes) {
    ITextRegion result = ITextRegion.EMPTY_REGION;
    for (INode node : nodes) {
        if (!isHidden(node)) {
            ITextRegionWithLineInformation region = node.getTextRegionWithLineInformation();
            if (region.getLength() != 0) {
                result = result.merge(toZeroBasedRegion(region));
            }
        }
    }
    return result;
}
项目:xtext-core    文件:AbstractTraceRegionToString.java   
protected void add(final AbstractTraceRegionToString.File file, final ITextRegion it, final AbstractTraceRegionToString.RegionHandle region, final AbstractTraceRegionToString.LocationHandle location) {
  int _offset = it.getOffset();
  AbstractTraceRegionToString.Insert _insert = new AbstractTraceRegionToString.Insert(_offset, true, region, location);
  file.inserts.add(_insert);
  int _offset_1 = it.getOffset();
  int _length = it.getLength();
  int _plus = (_offset_1 + _length);
  AbstractTraceRegionToString.Insert _insert_1 = new AbstractTraceRegionToString.Insert(_plus, false, region, location);
  file.inserts.add(_insert_1);
}
项目:xtext-extras    文件:ClasspathBasedIdeTypesProposalProvider.java   
@Override
public void createTypeProposals(final EReference reference, final ContentAssistContext context, final Predicate<ITypeDescriptor> filter, final IIdeContentProposalAcceptor acceptor) {
  ITextRegion importSectionRegion = null;
  XImportSection importSection = null;
  boolean _isImportDeclaration = this.isImportDeclaration(reference, context);
  boolean _not = (!_isImportDeclaration);
  if (_not) {
    importSection = this.importsConfiguration.getImportSection(context.getResource());
    importSectionRegion = this.importSectionRegionUtil.computeRegion(context.getResource());
  }
  Iterable<ITypeDescriptor> _typeDescriptors = this.getTypeDescriptors(context);
  for (final ITypeDescriptor typeDesc : _typeDescriptors) {
    {
      boolean _canAcceptMoreProposals = acceptor.canAcceptMoreProposals();
      boolean _not_1 = (!_canAcceptMoreProposals);
      if (_not_1) {
        return;
      }
      boolean _canPropose = this.canPropose(typeDesc, context, filter);
      if (_canPropose) {
        final ContentAssistEntry entry = this.createProposal(reference, typeDesc, context, importSection, importSectionRegion);
        final int priority = ((XbaseIdeContentProposalPriorities) this.proposalPriorities).getTypeRefPriority(typeDesc, entry);
        acceptor.accept(entry, priority);
      }
    }
  }
}
项目:xtext-extras    文件:ClasspathBasedIdeTypesProposalProvider.java   
protected ContentAssistEntry createProposal(final EReference reference, final ITypeDescriptor typeDesc, final ContentAssistContext context, final XImportSection importSection, final ITextRegion importSectionRegion) {
  ContentAssistEntry _xblockexpression = null;
  {
    final boolean importDecl = this.isImportDeclaration(reference, context);
    final String qualifiedName = this.qualifiedNameConverter.toString(typeDesc.getQualifiedName());
    String _xifexpression = null;
    if (importDecl) {
      _xifexpression = qualifiedName;
    } else {
      _xifexpression = typeDesc.getSimpleName();
    }
    final String proposal = _xifexpression;
    final Procedure1<ContentAssistEntry> _function = (ContentAssistEntry it) -> {
      if (importDecl) {
        it.setLabel(typeDesc.getSimpleName());
        it.setDescription(proposal);
      } else {
        it.setDescription(qualifiedName);
        if (((importSectionRegion != null) && this.isImportDeclarationRequired(typeDesc, qualifiedName, context, importSection))) {
          this.addImportDeclaration(it, importSectionRegion, typeDesc, qualifiedName, context);
        }
      }
    };
    _xblockexpression = this.proposalCreator.createProposal(proposal, context, _function);
  }
  return _xblockexpression;
}
项目:xtext-extras    文件:XbaseLocationInFileProviderTest.java   
@Test public void testFeatureCall_01() throws Exception {
    String text = "newArrayList('a')";
    XFeatureCall featureCall = castedExpression(text);
    ITextRegion region = locationInFileProvider.getSignificantTextRegion(featureCall);
    String significant = text.substring(region.getOffset(), region.getOffset() + region.getLength());
    assertEquals(text, significant);
}
项目:xtext-core    文件:ContentAssistContextFactory.java   
public boolean doComputePrefix(ICompositeNode node, StringBuilder result) {
    List<ILeafNode> hiddens = Lists.newArrayListWithCapacity(2);
    for (INode child : node.getChildren()) {
        if (child instanceof ICompositeNode) {
            if (!doComputePrefix((ICompositeNode) child, result))
                return false;
        }
        else {
            ILeafNode leaf = (ILeafNode) child;
            ITextRegion leafRegion = leaf.getTextRegion();
            if (leafRegion.getOffset() > completionOffset)
                return false;
            if (leaf.isHidden()) {
                if (result.length() != 0)
                    hiddens.add((ILeafNode) child);
            }
            else {
                Iterator<ILeafNode> iter = hiddens.iterator();
                while (iter.hasNext()) {
                    result.append(iter.next().getText());
                }
                hiddens.clear();
                result.append(getNodeTextUpToCompletionOffset(leaf));
                if (leafRegion.getOffset() + leafRegion.getLength() > completionOffset)
                    return false;
            }
        }
    }
    return true;
}
项目:xtext-extras    文件:XbaseLocationInFileProviderTest.java   
@Test public void testFeatureCall_04() throws Exception {
    String text = "String::<Invalid>valueOf('a')";
    XMemberFeatureCall featureCall = castedExpression(text);
    ITextRegion region = locationInFileProvider.getSignificantTextRegion(featureCall);
    String significant = text.substring(region.getOffset(), region.getOffset() + region.getLength());
    assertEquals(text.substring(text.indexOf('>') + 1), significant);
}
项目:xtext-extras    文件:XbaseLocationInFileProviderTest.java   
@Test public void testFeatureCall_05() throws Exception {
    String text = "((newArrayList('a')))";
    XFeatureCall featureCall = castedExpression(text);
    ITextRegion region = locationInFileProvider.getFullTextRegion(featureCall);
    String textRegion = text.substring(region.getOffset(), region.getOffset() + region.getLength());
    assertEquals("newArrayList('a')", textRegion);
}
项目:xtext-extras    文件:XbaseLocationInFileProviderTest.java   
@Test public void testStaticFeatureCall_01() throws Exception {
    String text = "String::<Invalid>valueOf('a')";
    XMemberFeatureCall featureCall = castedExpression(text);
    ITextRegion region = locationInFileProvider.getSignificantTextRegion(featureCall, XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET, 0);
    String significant = text.substring(region.getOffset(), region.getOffset() + region.getLength());
    assertEquals("String", significant);
}
项目:xtext-core    文件:FormatterTestHelper.java   
protected void assertReplacementsAreInRegion(List<ITextReplacement> rep, Collection<ITextRegion> regions,
        String doc) {
    Set<ITextReplacement> invalid = Sets.newHashSet();
    ALLOWED: for (ITextRegion allowed : regions)
        for (ITextReplacement r : rep) {
            if (allowed.contains(r))
                continue ALLOWED;
            invalid.add(r);
        }
    if (!invalid.isEmpty()) {
        String visualized = new TextRegionsToString().addAllReplacements(invalid).toString();
        fail("One or more TextReplacements are outside of the allowed region. Region: " + regions, visualized);
    }
}
项目:xtext-extras    文件:XbaseLocationInFileProviderTest.java   
@Test public void testStaticFeatureCall_06() throws Exception {
    String text = "java::util::UnknownThing::emptyList";
    XMemberFeatureCall featureCall = castedExpression(text);
    ITextRegion region = locationInFileProvider.getFullTextRegion(featureCall, XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET, 0);
    String significant = text.substring(region.getOffset(), region.getOffset() + region.getLength());
    assertEquals("java::util::UnknownThing", significant);
}
项目:xtext-core    文件:ContentAssistContextFactory.java   
public ContentAssistContext.Builder doCreateContext(
        INode lastCompleteNode, 
        EObject currentModel, EObject previousModel,
        INode currentNode, String prefix) {
    ContentAssistContext.Builder context = contentAssistContextProvider.get();

    context.setRootNode(rootNode);
    context.setLastCompleteNode(lastCompleteNode);
    context.setCurrentNode(currentNode);

    context.setRootModel(parseResult.getRootASTElement());
    context.setCurrentModel(currentModel);
    context.setPreviousModel(previousModel);
    context.setOffset(completionOffset);
    context.setPrefix(prefix);
    int regionLength = prefix.length();
    if (selection.getLength() > 0) {
        regionLength = regionLength + selection.getLength();
    }
    ITextRegion region = new TextRegion(completionOffset - prefix.length(), regionLength);
    if (selection.getOffset() >= 0 && selection.getLength() >= 0) {
        context.setSelectedText(document.substring(selection.getOffset(), selection.getOffset() + selection.getLength()));
    }
    context.setReplaceRegion(region);
    context.setResource(resource);
    return context;
}
项目:xtext-extras    文件:XbaseLocationInFileProviderTest.java   
@Test public void testStaticFeatureCall_09() throws Exception {
    String text = "java.util.Collections::emptyList";
    XMemberFeatureCall featureCall = castedExpression(text);
    ITextRegion region = locationInFileProvider.getSignificantTextRegion(featureCall, XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET, 0);
    String significant = text.substring(region.getOffset(), region.getOffset() + region.getLength());
    assertEquals("java.util.Collections", significant);
}