当前位置: 首页>>代码示例>>Java>>正文


Java Context类代码示例

本文整理汇总了Java中org.netbeans.modules.editor.indent.spi.Context的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Context类属于org.netbeans.modules.editor.indent.spi包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: reformat

import org.netbeans.modules.editor.indent.spi.Context; //导入依赖的package包/类
public static String reformat(String text, CodeStyle style, int rightMargin) {
    StringBuilder sb = new StringBuilder(text);
        ClassPath empty = ClassPathSupport.createClassPath(new URL[0]);
        ClasspathInfo cpInfo = ClasspathInfo.create(JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries(), empty, empty);
        JavacTaskImpl javacTask = JavacParser.createJavacTask(cpInfo, null, null, null, null, null, null, null, Arrays.asList(FileObjects.memoryFileObject("","Scratch.java", text)));
        com.sun.tools.javac.util.Context ctx = javacTask.getContext();
        JavaCompiler.instance(ctx).genEndPos = true;
        CompilationUnitTree tree = javacTask.parse().iterator().next(); //NOI18N
        SourcePositions sp = JavacTrees.instance(ctx).getSourcePositions();
        TokenSequence<JavaTokenId> tokens = TokenHierarchy.create(text, JavaTokenId.language()).tokenSequence(JavaTokenId.language());
        for (Diff diff : Pretty.reformat(text, tokens, new TreePath(tree), sp, style, rightMargin)) {
            int start = diff.getStartOffset();
            int end = diff.getEndOffset();
            sb.delete(start, end);
            String t = diff.getText();
            if (t != null && t.length() > 0) {
                sb.insert(start, t);
            }
        }

    return sb.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:Reformatter.java

示例2: handleSmartEnter

import org.netbeans.modules.editor.indent.spi.Context; //导入依赖的package包/类
public boolean handleSmartEnter(Context context) throws BadLocationException {
    boolean wasSmartEnter = false;
    BaseDocument doc = (BaseDocument)context.document();
    int dotPos = context.caretOffset();

    wasSmartEnter = isSmartEnter(doc, dotPos);

    if (wasSmartEnter) {
        int line = Utilities.getLineOffset(doc, dotPos);
        assert line > 0;
        int baseIndent = getExistingIndent(doc, line - 1);
        doc.insertString(dotPos, "\n", null); //NOI18N
        Position position = doc.createPosition(dotPos);
        context.modifyIndent(Utilities.getRowStartFromLineOffset(doc, line), baseIndent + doc.getShiftWidth());
        context.modifyIndent(Utilities.getRowStartFromLineOffset(doc, line + 1), baseIndent);
        context.setCaretOffset(position.getOffset());
    }

    return wasSmartEnter;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:TagBasedLexerFormatter.java

示例3: HtmlIndenter

import org.netbeans.modules.editor.indent.spi.Context; //导入依赖的package包/类
public HtmlIndenter(Context context) {
    super(HTMLTokenId.language(), context);
    try {
        Document doc = context.document();
        FileObject file = DataLoadersBridge.getDefault().getFileObject(doc);
        CharSequence code = doc.getText(0, doc.getLength());
        HtmlSource source = new HtmlSource(code, null, file);
        SyntaxAnalyzerResult result = SyntaxAnalyzer.create(source).analyze();
        model = result.getHtmlModel();
        HtmlVersion version = result.getHtmlVersion();            
        //workaround for [Bug 204163] [71cat] wrong formatting
        if(version == HtmlVersion.XHTML5) {
            //we do not have a special model for xhtml5, just html5 model => 
            //use xhtml1.0 model for formatting
            version = HtmlVersion.XHTML10_TRANSATIONAL;
        }
        
        model = HtmlModelFactory.getModel(version);
        
    } catch (BadLocationException ex) {
        Exceptions.printStackTrace(ex);
    }
    assert model != null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:HtmlIndenter.java

示例4: reformat

import org.netbeans.modules.editor.indent.spi.Context; //导入依赖的package包/类
public void reformat(Context context, ParserResult info) {
    final Context formatContext = context;
    final BaseDocument doc = (BaseDocument) context.document();

    doc.runAtomic(new Runnable() {
        @Override
        public void run() {

            final int caretOffset = EditorRegistry.lastFocusedComponent() != null
                    ? EditorRegistry.lastFocusedComponent().getCaretPosition()
                    : 0;

            MutableTextInput mti = (MutableTextInput) doc.getProperty(MutableTextInput.class);
            try {
                mti.tokenHierarchyControl().setActive(false);

            } finally {
                mti.tokenHierarchyControl().setActive(true);
            }
        }
    });

}
 
开发者ID:daimor,项目名称:NBStudio,代码行数:24,代码来源:macFormatter.java

示例5: process

import org.netbeans.modules.editor.indent.spi.Context; //导入依赖的package包/类
public void process(Context context) throws BadLocationException{
    if (context.isIndent()) {
        //
        // A temporary workaround for issue #178512
        BaseDocument doc = (BaseDocument)context.document();
        int firstLine = Utilities.getLineOffset(doc, context.startOffset());
        int lastLine = Utilities.getLineOffset(doc, context.endOffset());
        if (firstLine == lastLine) {
            enterPressed(context);
        } else {
            reformat(context);
        }
    } else {
        reformat(context);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:TagBasedLexerFormatter.java

示例6: get

import org.netbeans.modules.editor.indent.spi.Context; //导入依赖的package包/类
public static IndentSpiPackageAccessor get() {
    if (INSTANCE == null) {
        // Enforce the static initializer in Context class to be run
        try {
            Class.forName(Context.class.getName(), true, Context.class.getClassLoader());
        } catch (ClassNotFoundException e) { }
    }
    return INSTANCE;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:IndentSpiPackageAccessor.java

示例7: reformat

import org.netbeans.modules.editor.indent.spi.Context; //导入依赖的package包/类
public void reformat() throws BadLocationException {
    assertEquals(context.startOffset(), 0);
    int lineStartOffset = context.lineStartOffset(context.startOffset());
    assertEquals(lineStartOffset, context.startOffset());
    context.modifyIndent(context.startOffset(), 2);
    assertEquals(context.lineIndent(lineStartOffset), 2);
    context.modifyIndent(context.startOffset(), 0);
    assertEquals(context.lineIndent(lineStartOffset), 0);
    List<Context.Region> regions = context.indentRegions();
    Context.Region region = regions.get(0);
    assertEquals(region.getStartOffset(), 0);
    assertEquals(region.getEndOffset(), context.document().getLength());
    context.document().insertString(context.startOffset(), TestLineTokenId.MIME_TYPE + "/", null);
    reformatPos = context.document().createPosition(context.startOffset());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:EmbeddedIndentTest.java

示例8: getIndentTaskFactory

import org.netbeans.modules.editor.indent.spi.Context; //导入依赖的package包/类
public IndentTask.Factory getIndentTaskFactory() {
    if (indentTaskFactory == null) {
        indentTaskFactory = new IndentTask.Factory() {
            public IndentTask createTask(Context context) {
                Formatter formatter = getFormatter();
                if (formatter != null && context.document() instanceof BaseDocument) {
                    return new Indenter(context, formatter);
                } else {
                    return null;
                }
            }
        };
    }
    return indentTaskFactory;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:LegacyFormattersProvider.java

示例9: getReformatTaskFactory

import org.netbeans.modules.editor.indent.spi.Context; //导入依赖的package包/类
public ReformatTask.Factory getReformatTaskFactory() {
    if (reformatTaskFactory == null) {
        reformatTaskFactory = new ReformatTask.Factory() {
            public ReformatTask createTask(Context context) {
                Formatter formatter = getFormatter();
                if (formatter != null && context.document() instanceof BaseDocument) {
                    return new Reformatter(context, formatter);
                } else {
                    return null;
                }
            }
        };
    }
    return reformatTaskFactory;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:LegacyFormattersProvider.java

示例10: reformat

import org.netbeans.modules.editor.indent.spi.Context; //导入依赖的package包/类
public void reformat(Context context, final int startOffset, final int endOffset)
        throws BadLocationException {
    final BaseDocument doc = (BaseDocument) context.document();
    doc.runAtomic(new Runnable() {

        public void run() {
            doReformat(doc, startOffset, endOffset);
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:XMLLexerFormatter.java

示例11: documentFrom

import org.netbeans.modules.editor.indent.spi.Context; //导入依赖的package包/类
/**
 * @requires context != null
 * @return a new Document from the given context.
 */
private static Document documentFrom(Context context) {
    try {
        return new ProtobufDocument(
                context.document()
                        .getText(ZERO, context.document().getLength()));
    } catch (BadLocationException ex) {
        throw new FailureException(
                "ProtobufIndentTask.documentFrom", ex);
    }
}
 
开发者ID:mwillema,项目名称:protobuf-netbeans-plugin,代码行数:15,代码来源:ProtobufIndentTask.java

示例12: ContextIndent

import org.netbeans.modules.editor.indent.spi.Context; //导入依赖的package包/类
/**
 * Constructor
 *
 * @param context the current Apex file.
 */
public ContextIndent(Context context) {
    this.context = context;
    document = context.document();
    tokenHierarchy = TokenHierarchy.get(document);
    indentLevelSize = org.netbeans.modules.editor.indent.api.IndentUtils.indentLevelSize(document);
}
 
开发者ID:fundacionjala,项目名称:oblivion-netbeans-plugin,代码行数:12,代码来源:ContextIndent.java

示例13: DocumentFormatter

import org.netbeans.modules.editor.indent.spi.Context; //导入依赖的package包/类
/**
 * Constructor
 *
 * @param context the current Apex file.
 * @param parserResult contains the tokens sequence of the Apex file
 */
public DocumentFormatter(Context context, ParserResult parserResult) {
    this.context = context;
    Document document = context.document();
    this.parserResult = (ApexParserResult) parserResult;
    contextIndent = new ContextIndent(context);
    Preferences preferences = CodeStylePreferences.get(document).getPreferences();
    bracesFormatter = new BracesFormatter(document, preferences, FormatOptions.getInstance());
    newLineFormatter = new NewLineFormatter(document);
    reformatTreeVisitor = new ReformatTreeVisitor(document,context.startOffset(), context.endOffset());
    optionsToReformat = new ArrayList<>();
    visitParserResult();
}
 
开发者ID:fundacionjala,项目名称:oblivion-netbeans-plugin,代码行数:19,代码来源:DocumentFormatter.java

示例14: reindent

import org.netbeans.modules.editor.indent.spi.Context; //导入依赖的package包/类
@Override
public void reindent(Context context) {
    ContextIndent contextIndent = new ContextIndent(context);

    try {
        int indentLevel = contextIndent.findCurrentDepthToIndent(context.startOffset());
        context.modifyIndent(context.startOffset(), indentLevel);
    } catch (BadLocationException ex) {
        LOG.log(Level.SEVERE, ex.toString(), ex);
    }
}
 
开发者ID:fundacionjala,项目名称:oblivion-netbeans-plugin,代码行数:12,代码来源:ApexFormatter.java

示例15: reformat

import org.netbeans.modules.editor.indent.spi.Context; //导入依赖的package包/类
@Override
public void reformat() throws BadLocationException {
    if (context.indentRegions().size() > 1) {
        throw new UnsupportedOperationException("The reformatter currently only supports one region per call.");
    }

    for (final Context.Region region : context.indentRegions()) {
        final String original = context.document().getText(region.getStartOffset(), region.getEndOffset() - region.getStartOffset());
        if (original == null || original.isEmpty()) {
            continue;
        }

        final String formatted = runGofmt(original);
        if (formatted == null || formatted.equals(original)) {
            continue;
        }

        Runnable applyer = new Runnable() {

            @Override
            public void run() {
                try {
                    context.document().remove(region.getStartOffset(), region.getEndOffset() - region.getStartOffset());
                    context.document().insertString(region.getStartOffset(), formatted, null);
                } catch (BadLocationException ex) {
                    LOGGER.log(Level.WARNING, ex.getLocalizedMessage(), ex);
                    throw new RuntimeException(ex);
                }
            }

        };

        if (context.document() instanceof BaseDocument) {
            ((BaseDocument)context.document()).runAtomicAsUser(applyer);
        } else {
            applyer.run();
        }
    }
}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:40,代码来源:GoReformatTask.java


注:本文中的org.netbeans.modules.editor.indent.spi.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。