Package org.eclipse.jdt.core

Examples of org.eclipse.jdt.core.ISourceRange


    try {
      monitor.beginTask(WizardMessages.UpdateAllTests_beginTask, 5);
      if (!checkValidateEditStatus(fTestSuite, fShell))
        return;

      ISourceRange range = fTestSuite.getSourceRange();
      IDocument fullSource = new Document(fTestSuite.getBuffer()
          .getContents());
      String originalContent = fullSource.get(range.getOffset(), range
          .getLength());
      StringBuffer source = new StringBuffer(originalContent);
      TestSuiteClassListRange classRange = getTestSuiteClassListRange(source
          .toString());
      if (classRange != null) {
        monitor.worked(1);
        // String updatableCode=
        // source.substring(start,end+NewTestSuiteCreationWizardPage.endMarker.length());
        source.replace(classRange.getStart(), classRange.getEnd(),
            getUpdatableString(fSelectedTestCases));
        fullSource.replace(range.getOffset(), range.getLength(), source
            .toString());
        monitor.worked(1);
        String formattedContent = JUnitStubUtility
            .formatCompilationUnit(fTestSuite.getJavaProject(),
                fullSource.get(), fTestSuite
View Full Code Here


        return null;

      int nameStart = computeCaptionOffset(document) + offset;

      try {
        ISourceRange sourceRange = fMember.getSourceRange();
        IMethod foldedMethod = lambdaMethod;

        if (foldedMethod != null && !foldedMethod.exists()) {
          foldedMethod = findLambdaMethodIn(fMember);
          if (foldedMethod != null) {
View Full Code Here

        /* The member's name range may not be correct. However,
         * reconciling would trigger another element delta which would
         * lead to reentrant situations. Therefore, we optimistically
         * assume that the name range is correct, but double check the
         * received lines below. */
        ISourceRange nameRange = fMember.getNameRange();
        if (nameRange != null)
          nameStart = nameRange.getOffset();

      } catch (JavaModelException e) {
        // ignore and use default
      }

View Full Code Here

      if (!fMember.exists())
        return 0;

      try {
        ISourceRange sourceRange = fMember.getSourceRange();
        IMethod foldedMethod = lambdaMethod;

        if (foldedMethod != null && !foldedMethod.exists()) {
          foldedMethod = findLambdaMethodIn(fMember);
          if (foldedMethod != null) {
View Full Code Here

  }

  private IRegion computeImportProjectionRanges(IImportContainer element,
          FoldingStructureComputationContext ctx) {
    try {
      ISourceRange range = element.getSourceRange();
      String contents = null;
      if (SourceRange.isAvailable(range) && (contents = element.getSource()) != null) {
        Region importRegion = new Region(range.getOffset(), range.getLength());
        return importRegion;
        /*return alignRegion(importRegion, ctx);*/
      }
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

   * @return the regions to be folded
   */
  protected final IRegion[] computeProjectionRanges(ISourceReference reference,
          FoldingStructureComputationContext ctx) {
    try {
      ISourceRange range = reference.getSourceRange();
      if (!SourceRange.isAvailable(range))
        return new IRegion[0];

      String contents = reference.getSource();
      if (contents == null)
        return new IRegion[0];

      List<IRegion> regions = new ArrayList<IRegion>();
      if (!ctx.hasFirstType() && reference instanceof IType) {
        ctx.setFirstType((IType) reference);
        IRegion headerComment = computeHeaderComment(ctx);
        if (headerComment != null) {
          regions.add(headerComment);
          ctx.setHasHeaderComment();
        }
      }

      final int shift = range.getOffset();
      IScanner scanner = ctx.getScanner();
      scanner.resetTo(shift, shift + range.getLength());

      int start = shift;
      while (true) {

        int token = scanner.getNextToken();
        start = scanner.getCurrentTokenStartPosition();

        switch (token) {
        case ITerminalSymbols.TokenNameCOMMENT_JAVADOC:
        case ITerminalSymbols.TokenNameCOMMENT_BLOCK: {
          int end = scanner.getCurrentTokenEndPosition() + 1;
          regions.add(new Region(start, end - start));
          continue;
        }
        case ITerminalSymbols.TokenNameCOMMENT_LINE:
          continue;
        }

        break;
      }

      regions.add(new Region(start, shift + range.getLength() - start));

      return regions.toArray(new IRegion[regions.size()]);
    } catch (JavaModelException e) {} catch (InvalidInputException e) {}

    return new IRegion[0];
View Full Code Here

  }

  private IRegion computeHeaderComment(FoldingStructureComputationContext ctx)
          throws JavaModelException {
    // search at most up to the first type
    ISourceRange range = ctx.getFirstType().getSourceRange();
    if (range == null)
      return null;
    int start = 0;
    int end = range.getOffset();

    /* code adapted from CommentFormattingStrategy:
     * scan the header content up to the first type. Once a comment is
     * found, accumulate any additional comments up to the stop condition.
     * The stop condition is reaching a package declaration, import container,
View Full Code Here

  }

  private IRegion computeImportProjectionRanges(IImportContainer element,
          FoldingStructureComputationContext ctx) {
    try {
      ISourceRange range = element.getSourceRange();
      String contents = null;
      if (SourceRange.isAvailable(range) && (contents = element.getSource()) != null) {
        Region importRegion = new Region(range.getOffset(), range.getLength());
        return importRegion;
        /*return alignRegion(importRegion, ctx);*/
      }
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

   * @return the regions to be folded
   */
  protected final IRegion[] computeProjectionRanges(ISourceReference reference,
          FoldingStructureComputationContext ctx) {
    try {
      ISourceRange range = reference.getSourceRange();
      if (!SourceRange.isAvailable(range))
        return new IRegion[0];

      String contents = reference.getSource();
      if (contents == null)
        return new IRegion[0];

      List<IRegion> regions = new ArrayList<IRegion>();
      if (!ctx.hasFirstType() && reference instanceof IType) {
        ctx.setFirstType((IType) reference);
        IRegion headerComment = computeHeaderComment(ctx);
        if (headerComment != null) {
          regions.add(headerComment);
          ctx.setHasHeaderComment();
        }
      }

      final int shift = range.getOffset();
      IScanner scanner = ctx.getScanner();
      scanner.resetTo(shift, shift + range.getLength());

      int start = shift;
      while (true) {

        int token = scanner.getNextToken();
        start = scanner.getCurrentTokenStartPosition();

        switch (token) {
        case ITerminalSymbols.TokenNameCOMMENT_JAVADOC:
        case ITerminalSymbols.TokenNameCOMMENT_BLOCK: {
          int end = scanner.getCurrentTokenEndPosition() + 1;
          regions.add(new Region(start, end - start));
          continue;
        }
        case ITerminalSymbols.TokenNameCOMMENT_LINE:
          continue;
        }

        break;
      }

      regions.add(new Region(start, shift + range.getLength() - start));

      return regions.toArray(new IRegion[regions.size()]);
    } catch (JavaModelException e) {} catch (InvalidInputException e) {}

    return new IRegion[0];
View Full Code Here

  }

  private IRegion computeHeaderComment(FoldingStructureComputationContext ctx)
          throws JavaModelException {
    // search at most up to the first type
    ISourceRange range = ctx.getFirstType().getSourceRange();
    if (range == null)
      return null;
    int start = 0;
    int end = range.getOffset();

    /* code adapted from CommentFormattingStrategy:
     * scan the header content up to the first type. Once a comment is
     * found, accumulate any additional comments up to the stop condition.
     * The stop condition is reaching a package declaration, import container,
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.ISourceRange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.