Examples of IFormattingContext


Examples of com.puppetlabs.xtext.dommodel.formatter.context.IFormattingContext

    CommentFormattingOptions options = new CommentFormattingOptions(
      new ICommentFormatterAdvice.DefaultCommentAdvice(), 80);
    JavaLikeMLCommentContainer in = new ICommentContainerInformation.JavaLikeMLCommentContainer(0);
    CommentProcessor cp = new CommentProcessor();
    String source = "/* the\nquick\n     *brown\n * fox\n   \n\n*/ ";
    IFormattingContext fmtCtx = get(IFormattingContext.class);
    TextFlow s = cp.formatComment(source, in, in, options, fmtCtx);
    String expected = "/* the\n * quick\n * brown\n * fox\n */ ";
    assertEquals("Should produce expected result", expected, s.getText().toString());
  }
View Full Code Here

Examples of com.puppetlabs.xtext.dommodel.formatter.context.IFormattingContext

    "/***********************\n"//
        + " * 0123456789 0123456789\n * 0123456789 0123456789\n"//
        + " * abc\n" //
        + " * 0123456789 0123456789\n * 0123456789 0123456789\n"//
        + " */";
    IFormattingContext fmtCtx = get(IFormattingContext.class);
    TextFlow s = cp.formatComment(source, in, in, options, fmtCtx);
    assertEquals("Should produce expected result", expected, s.getText().toString());
  }
View Full Code Here

Examples of com.puppetlabs.xtext.dommodel.formatter.context.IFormattingContext

    "/* 0123456789 0123456789\n * 0123456789 0123456789\n"//
        + " * abc\n" //
        + " * 0123456789 0123456789\n * 0123456789 0123456789\n"//
        + " */";

    IFormattingContext fmtCtx = get(IFormattingContext.class);
    TextFlow s = cp.formatComment(source, in, in, options, fmtCtx);
    assertEquals("Should produce expected result", expected, s.getText().toString());
  }
View Full Code Here

Examples of com.puppetlabs.xtext.dommodel.formatter.context.IFormattingContext

    String expected = //
    "/*   0123456789 0123456789\n *   0123456789 0123456789\n"//
        + " * abc\n" //
        + " * 0123456789 0123456789\n * 0123456789 0123456789\n"//
        + " */";
    IFormattingContext fmtCtx = get(IFormattingContext.class);
    TextFlow s = cp.formatComment(source, in, in, options, fmtCtx);
    assertEquals("Should produce expected result", expected, s.getText().toString());
  }
View Full Code Here

Examples of com.puppetlabs.xtext.dommodel.formatter.context.IFormattingContext

    JavaLikeMLCommentContainer in = new ICommentContainerInformation.JavaLikeMLCommentContainer(2);
    CommentProcessor cp = new CommentProcessor();
    CommentFormattingOptions options = new CommentFormattingOptions(
      new ICommentFormatterAdvice.DefaultCommentAdvice(), 80);
    String source = "/* the\n  quick\n       *brown\n   * fox\n     \n  \n  */ ";
    IFormattingContext fmtCtx = get(IFormattingContext.class);
    TextFlow s = cp.formatComment(source, in, in, options, fmtCtx);
    // pad expected and result with 2 spaces to emulate the inserting of the result
    // (makes comparison look nicer if test fails)
    String expected = "  /* the\n   * quick\n   * brown\n   * fox\n   */ ";
    assertEquals("Should produce expected result", expected, "  " + CharSequences.trimLeft(s.getText()).toString());
View Full Code Here

Examples of org.eclipse.jface.text.formatter.IFormattingContext

            setRedraw(false);
          }

          if (fContentFormatter instanceof IContentFormatterExtension) {
            IContentFormatterExtension extension = (IContentFormatterExtension) fContentFormatter;
            IFormattingContext context = new FormattingContext();
            context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.valueOf(formatDocument));
            context.setProperty(FormattingContextProperties.CONTEXT_REGION, region);
            extension.format(document, context);
          }
          else {
            fContentFormatter.format(document, region);
          }
        }
        finally {
          try {
            if (rewriteSession != null) {
              IDocumentExtension4 extension = (IDocumentExtension4) document;
              extension.stopRewriteSession(rewriteSession);
            }
            else {
              setRedraw(true);
            }
          }
          finally {
            // end recording
            selection = getTextWidget().getSelection();
            cursorPosition = selection.x;
            selectionLength = selection.y - selection.x;
            endRecording(cursorPosition, selectionLength);
          }
        }
        break;
      case FORMAT_ACTIVE_ELEMENTS :
        rewriteSession = null;
        document = getDocument();
        try {
          /*
           * This command will format the node at cursor position
           * (and all its children)
           */
          // begin recording
          beginRecording(FORMAT_ACTIVE_ELEMENTS_TEXT, FORMAT_ACTIVE_ELEMENTS_TEXT, cursorPosition, selectionLength);
          IRegion region = null;
          Point s = getSelectedRange();
          if (s.y > -1) {
            // only format node at cursor position
            region = new Region(s.x, s.y);
          }

          if (document instanceof IDocumentExtension4) {
            IDocumentExtension4 extension = (IDocumentExtension4) document;
            DocumentRewriteSessionType type = (selection.y == 0 || selection.y > MAX_SMALL_FORMAT_LENGTH) ? DocumentRewriteSessionType.UNRESTRICTED : DocumentRewriteSessionType.UNRESTRICTED_SMALL;
            rewriteSession = (extension.getActiveRewriteSession() != null) ? null : extension.startRewriteSession(type);
          }
          else {
            setRedraw(false);
          }

          if (fContentFormatter instanceof IContentFormatterExtension) {
            IContentFormatterExtension extension = (IContentFormatterExtension) fContentFormatter;
            IFormattingContext context = new FormattingContext();
            context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.FALSE);
            context.setProperty(FormattingContextProperties.CONTEXT_REGION, region);
            extension.format(getDocument(), context);
          }
          else {
            fContentFormatter.format(getDocument(), region);
          }
View Full Code Here

Examples of org.eclipse.jface.text.formatter.IFormattingContext

            setRedraw(false);
          }

          if (fContentFormatter instanceof IContentFormatterExtension) {
            IContentFormatterExtension extension = (IContentFormatterExtension) fContentFormatter;
            IFormattingContext context = new FormattingContext();
            context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.valueOf(formatDocument));
            context.setProperty(FormattingContextProperties.CONTEXT_REGION, region);
            extension.format(document, context);
          }
          else {
            fContentFormatter.format(document, region);
          }
        }
        finally {
          try {
            if (rewriteSession != null) {
              IDocumentExtension4 extension = (IDocumentExtension4) document;
              extension.stopRewriteSession(rewriteSession);
            }
            else {
              setRedraw(true);
            }
          }
          finally {
            // end recording
            selection = getTextWidget().getSelection();
            cursorPosition = selection.x;
            selectionLength = selection.y - selection.x;
            endRecording(cursorPosition, selectionLength);
          }
        }
        break;
      case FORMAT_ACTIVE_ELEMENTS :
        rewriteSession = null;
        document = getDocument();
        try {
          /*
           * This command will format the node at cursor position
           * (and all its children)
           */
          // begin recording
          beginRecording(FORMAT_ACTIVE_ELEMENTS_TEXT, FORMAT_ACTIVE_ELEMENTS_TEXT, cursorPosition, selectionLength);
          IRegion region = null;
          Point s = getSelectedRange();
          if (s.y > -1) {
            // only format node at cursor position
            region = new Region(s.x, s.y);
          }

          if (document instanceof IDocumentExtension4) {
            IDocumentExtension4 extension = (IDocumentExtension4) document;
            DocumentRewriteSessionType type = (selection.y == 0 || selection.y > MAX_SMALL_FORMAT_LENGTH) ? DocumentRewriteSessionType.UNRESTRICTED : DocumentRewriteSessionType.UNRESTRICTED_SMALL;
            rewriteSession = (extension.getActiveRewriteSession() != null) ? null : extension.startRewriteSession(type);
          }
          else {
            setRedraw(false);
          }

          if (fContentFormatter instanceof IContentFormatterExtension) {
            IContentFormatterExtension extension = (IContentFormatterExtension) fContentFormatter;
            IFormattingContext context = new FormattingContext();
            context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.FALSE);
            context.setProperty(FormattingContextProperties.CONTEXT_REGION, region);
            extension.format(getDocument(), context);
          }
          else {
            fContentFormatter.format(getDocument(), region);
          }
View Full Code Here

Examples of org.eclipse.jface.text.formatter.IFormattingContext

      case FORMAT:
        {
          final Point selection= rememberSelection();
          final IRewriteTarget target= getRewriteTarget();
          final IDocument document= getDocument();
          IFormattingContext context= null;
          DocumentRewriteSession rewriteSession= null;

          if (document instanceof IDocumentExtension4) {
            IDocumentExtension4 extension= (IDocumentExtension4) document;
            DocumentRewriteSessionType type= selection.y == 0 || selection.y > 1000 ? DocumentRewriteSessionType.SEQUENTIAL : DocumentRewriteSessionType.UNRESTRICTED_SMALL;
            rewriteSession= extension.startRewriteSession(type);
          } else {
            setRedraw(false);
            target.beginCompoundChange();
          }

          try {

            final String rememberedContents= document.get();

            try {

              if (fContentFormatter instanceof IContentFormatterExtension) {
                final IContentFormatterExtension extension= (IContentFormatterExtension) fContentFormatter;
                context= createFormattingContext();
                if (selection.y == 0) {
                  context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE);
                } else {
                  context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.FALSE);
                  context.setProperty(FormattingContextProperties.CONTEXT_REGION, new Region(selection.x, selection.y));
                }
                extension.format(document, context);
              } else {
                IRegion r;
                if (selection.y == 0) {
                  IRegion coverage= getModelCoverage();
                  r= coverage == null ? new Region(0, 0) : coverage;
                } else {
                  r= new Region(selection.x, selection.y);
                }
                fContentFormatter.format(document, r);
              }

              updateSlaveDocuments(document);

            } catch (RuntimeException x) {
              // fire wall for https://bugs.eclipse.org/bugs/show_bug.cgi?id=47472
              // if something went wrong we undo the changes we just did
              // TODO to be removed after 3.0 M8
              document.set(rememberedContents);
              throw x;
            }

          } finally {

            if (document instanceof IDocumentExtension4) {
              IDocumentExtension4 extension= (IDocumentExtension4) document;
              extension.stopRewriteSession(rewriteSession);
            } else {
              target.endCompoundChange();
              setRedraw(true);
            }

            restoreSelection();
            if (context != null)
              context.dispose();
          }
          return;
        }
      default:
        super.doOperation(operation);
View Full Code Here

Examples of org.eclipse.jface.text.formatter.IFormattingContext

      case FORMAT:
        {
          final Point selection= rememberSelection();
          final IRewriteTarget target= getRewriteTarget();
          final IDocument document= getDocument();
          IFormattingContext context= null;
          DocumentRewriteSession rewriteSession= null;

          if (document instanceof IDocumentExtension4) {
            IDocumentExtension4 extension= (IDocumentExtension4) document;
            DocumentRewriteSessionType type= (selection.y == 0 && document.getLength() > 1000) || selection.y > 1000
              ? DocumentRewriteSessionType.SEQUENTIAL
              : DocumentRewriteSessionType.UNRESTRICTED_SMALL;
            rewriteSession= extension.startRewriteSession(type);
          } else {
            setRedraw(false);
            target.beginCompoundChange();
          }

          try {

            final String rememberedContents= document.get();

            try {

              if (fContentFormatter instanceof IContentFormatterExtension) {
                final IContentFormatterExtension extension= (IContentFormatterExtension) fContentFormatter;
                context= createFormattingContext();
                if (selection.y == 0) {
                  context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE);
                } else {
                  context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.FALSE);
                  context.setProperty(FormattingContextProperties.CONTEXT_REGION, new Region(selection.x, selection.y));
                }
                extension.format(document, context);
              } else {
                IRegion r;
                if (selection.y == 0) {
                  IRegion coverage= getModelCoverage();
                  r= coverage == null ? new Region(0, 0) : coverage;
                } else {
                  r= new Region(selection.x, selection.y);
                }
                fContentFormatter.format(document, r);
              }

              updateSlaveDocuments(document);

            } catch (RuntimeException x) {
              // fire wall for https://bugs.eclipse.org/bugs/show_bug.cgi?id=47472
              // if something went wrong we undo the changes we just did
              // TODO to be removed after 3.0 M8
              document.set(rememberedContents);
              throw x;
            }

          } finally {

            if (document instanceof IDocumentExtension4) {
              IDocumentExtension4 extension= (IDocumentExtension4) document;
              extension.stopRewriteSession(rewriteSession);
            } else {
              target.endCompoundChange();
              setRedraw(true);
            }

            restoreSelection();
            if (context != null)
              context.dispose();
          }
          return;
        }
      default:
        super.doOperation(operation);
View Full Code Here

Examples of org.eclipse.jface.text.formatter.IFormattingContext

      case FORMAT:
        {
          final Point selection= rememberSelection();
          final IRewriteTarget target= getRewriteTarget();
          final IDocument document= getDocument();
          IFormattingContext context= null;
          DocumentRewriteSession rewriteSession= null;

          if (document instanceof IDocumentExtension4) {
            IDocumentExtension4 extension= (IDocumentExtension4) document;
            DocumentRewriteSessionType type= (selection.y == 0 && document.getLength() > 1000) || selection.y > 1000
              ? DocumentRewriteSessionType.SEQUENTIAL
              : DocumentRewriteSessionType.UNRESTRICTED_SMALL;
            rewriteSession= extension.startRewriteSession(type);
          } else {
            setRedraw(false);
            target.beginCompoundChange();
          }

          try {

            final String rememberedContents= document.get();

            try {

              if (fContentFormatter instanceof IContentFormatterExtension) {
                final IContentFormatterExtension extension= (IContentFormatterExtension) fContentFormatter;
                context= createFormattingContext();
                if (selection.y == 0) {
                  context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE);
                } else {
                  context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.FALSE);
                  context.setProperty(FormattingContextProperties.CONTEXT_REGION, new Region(selection.x, selection.y));
                }
                extension.format(document, context);
              } else {
                IRegion r;
                if (selection.y == 0) {
                  IRegion coverage= getModelCoverage();
                  r= coverage == null ? new Region(0, 0) : coverage;
                } else {
                  r= new Region(selection.x, selection.y);
                }
                fContentFormatter.format(document, r);
              }

              updateSlaveDocuments(document);

            } catch (RuntimeException x) {
              // fire wall for https://bugs.eclipse.org/bugs/show_bug.cgi?id=47472
              // if something went wrong we undo the changes we just did
              // TODO to be removed after 3.0 M8
              document.set(rememberedContents);
              throw x;
            }

          } finally {

            if (document instanceof IDocumentExtension4) {
              IDocumentExtension4 extension= (IDocumentExtension4) document;
              extension.stopRewriteSession(rewriteSession);
            } else {
              target.endCompoundChange();
              setRedraw(true);
            }

            restoreSelection();
            if (context != null)
              context.dispose();
          }
          return;
        }
      default:
        super.doOperation(operation);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.