Example usage for com.google.gwt.eclipse.core.editors.java GWTPartitions JSNI_METHOD

List of usage examples for com.google.gwt.eclipse.core.editors.java GWTPartitions JSNI_METHOD

Introduction

In this page you can find the example usage for com.google.gwt.eclipse.core.editors.java GWTPartitions JSNI_METHOD.

Prototype

String JSNI_METHOD

To view the source code for com.google.gwt.eclipse.core.editors.java GWTPartitions JSNI_METHOD.

Click Source Link

Usage

From source file:krasa.formatter.JsniFormattingUtil.java

License:Open Source License

/**
 * Returns a text edit that formats the given document according to the given settings.
 *
 * @param document/*from w w  w . j a va  2  s.  c  o m*/
 *            The document to format.
 * @param javaFormattingPrefs
 *            The formatting preferences for Java, used to determine the method level indentation.
 * @param javaScriptFormattingPrefs
 *            The formatting preferences for JavaScript. See org.eclipse.wst.jsdt.internal.formatter
 *            .DefaultCodeFormatterOptions and org.eclipse.wst.jsdt.core.formatter.DefaultCodeFormatterConstants
 * @param originalJsniMethods
 *            The original jsni methods to use if the formatter fails to format the method. The original jsni
 *            Strings must be in the same order that the jsni methods occur in the document. This is to work around
 *            the Java formatter blasting the jsni tabbing for the format-on-save action. May be null.
 * @return A text edit that when applied to the document, will format the jsni methods.
 */
@SuppressWarnings("unchecked")
public TextEdit format(IDocument document, Map javaFormattingPrefs, Map javaScriptFormattingPrefs,
        Range range) {
    TextEdit combinedEdit = new MultiTextEdit();
    ITypedRegion[] regions = computePartitioning(document, range);

    // Format all JSNI blocks in the document
    int i = 0;
    for (ITypedRegion region : regions) {
        if (region.getType().equals(GWTPartitions.JSNI_METHOD)) {
            String originalJsniMethod = null;
            TextEdit edit = format(document, new TypedPosition(region), javaFormattingPrefs,
                    javaScriptFormattingPrefs, originalJsniMethod);
            if (edit != null) {
                combinedEdit.addChild(edit);
            }
            i++;
        }
    }
    return combinedEdit;

}

From source file:krasa.formatter.JsniFormattingUtil.java

License:Open Source License

private static ITypedRegion[] computePartitioning(IDocument document, Range range) {
    ArrayList<ITypedRegion> iTypedRegions = new ArrayList<ITypedRegion>();
    String str = document.get();//  w  ww  .ja v a2  s  . c  o m
    String prefix = "/*-";
    String postfix = "-*/";
    int startIndex = 0;
    int endIndex = 0;

    while (startIndex != -1) {
        startIndex = str.indexOf(prefix, startIndex);
        endIndex = str.indexOf(postfix, startIndex);

        if (startIndex != -1 && endIndex != -1) {
            endIndex = endIndex + 3;
            if (isInRange(range, startIndex, endIndex)) {
                iTypedRegions
                        .add(new TypedRegion(startIndex, endIndex - startIndex, GWTPartitions.JSNI_METHOD));
            }
            startIndex += prefix.length();
        }
    }
    return iTypedRegions.toArray(new ITypedRegion[iTypedRegions.size()]);

}