Java Code Examples for org.netbeans.editor.BaseDocument#putProperty()

The following examples show how to use org.netbeans.editor.BaseDocument#putProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CslTestBase.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected BaseDocument getDocument(FileObject fo, String mimeType, Language language) {
        try {
//             DataObject dobj = DataObject.find(fo);
//             assertNotNull(dobj);
//
//             EditorCookie ec = (EditorCookie)dobj.getCookie(EditorCookie.class);
//             assertNotNull(ec);
//
//             return (BaseDocument)ec.openDocument();
            BaseDocument doc = getDocument(readFile(fo), mimeType, language);
            try {
                DataObject dobj = DataObject.find(fo);
                doc.putProperty(Document.StreamDescriptionProperty, dobj);
            } catch (DataObjectNotFoundException dnfe) {
                fail(dnfe.toString());
            }

            return doc;
        }
        catch (Exception ex){
            fail(ex.toString());
            return null;
        }
    }
 
Example 2
Source File: GroovyTestBase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public BaseDocument createDocument(String s) {
    BaseDocument doc = super.getDocument(s);
    doc.putProperty(org.netbeans.api.lexer.Language.class, GroovyTokenId.language());
    doc.putProperty("mimeType", GroovyTokenId.GROOVY_MIME_TYPE);

    return doc;
}
 
Example 3
Source File: Utils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static BaseDocument loadDocument(String text) throws IOException {
    BaseDocument sd = new BaseDocument(true, "text/xml"); //NOI18N
    sd.putProperty(Language.class, XMLTokenId.language());
    try {
        sd.insertString(0, text, null);
        return sd;
    } catch (BadLocationException ble) {
        throw new IOException(ble.getLocalizedMessage());
    }
}
 
Example 4
Source File: TransferData.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void init(BaseDocument doc) throws BadLocationException {
    numberOfLines = TagBasedLexerFormatter.getNumberOfLines(doc);
    formattableLines = new boolean[numberOfLines];
    alreadyProcessedByNativeFormatter = new boolean[numberOfLines];
    Arrays.fill(formattableLines, true);
    originalIndents = new int[numberOfLines];
    transformedOffsets = new int[numberOfLines];

    for (int i = 0; i < numberOfLines; i++) {
        originalIndents[i] = TagBasedLexerFormatter.getExistingIndent(doc, i);
    }

    doc.putProperty(TRANSFER_DATA_DOC_PROPERTY, this);
}
 
Example 5
Source File: CslTestBase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public BaseDocument getDocument(String s, final String mimeType, final Language language) {
    try {
        BaseDocument doc = new BaseDocument(true, mimeType) {
            @Override
            public boolean isIdentifierPart(char ch) {
                if (mimeType != null) {
                    org.netbeans.modules.csl.core.Language l = LanguageRegistry.getInstance().getLanguageByMimeType(mimeType);
                    if (l != null) {
                        GsfLanguage gsfLanguage = l.getGsfLanguage();
                        if (gsfLanguage != null) {
                            return gsfLanguage.isIdentifierChar(ch);
                        }
                    }
                }

                return super.isIdentifierPart(ch);
            }
        };

        //doc.putProperty("mimeType", mimeType);
        doc.putProperty(org.netbeans.api.lexer.Language.class, language);

        doc.insertString(0, s, null);

        return doc;
    }
    catch (Exception ex){
        fail(ex.toString());
        return null;
    }
}
 
Example 6
Source File: BeforeSaveTasks.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private BeforeSaveTasks(BaseDocument doc) {
    this.doc = doc;
    Runnable beforeSaveRunnable = (Runnable)
            doc.getProperty("beforeSaveRunnable"); // Name of prop in sync with CloneableEditorSupport NOI18N
    if (beforeSaveRunnable != null) {
        throw new IllegalStateException("\"beforeSaveRunnable\" property of document " + doc + // NOI18N
                " is already occupied by " + beforeSaveRunnable); // NOI18N
    }
    beforeSaveRunnable = new Runnable() {
        public @Override void run() {
            runTasks();
        }
    };
    doc.putProperty("beforeSaveRunnable", beforeSaveRunnable); // NOI18N
}
 
Example 7
Source File: BeforeSaveTasks.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static synchronized BeforeSaveTasks get(BaseDocument doc) {
    BeforeSaveTasks beforeSaveTasks = (BeforeSaveTasks) doc.getProperty(BeforeSaveTasks.class);
    if (beforeSaveTasks == null) {
        beforeSaveTasks = new BeforeSaveTasks(doc);
        doc.putProperty(BeforeSaveTasks.class, beforeSaveTasks);
    }
    return beforeSaveTasks;
}
 
Example 8
Source File: TestUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static BaseDocument createSpringXMLConfigDocument(String content) throws Exception {
    Class<?> kitClass = CloneableEditorSupport.getEditorKit(SpringConstants.CONFIG_MIME_TYPE).getClass();
    BaseDocument doc = new BaseDocument(kitClass, false);
    doc.putProperty(Language.class, XMLTokenId.language());
    doc.insertString(0, content, null);
    return doc;
}
 
Example 9
Source File: TrailingWhitespaceRemoveTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void checkTrailingWhitespaceRemove(String policy, String result) throws Exception {
        MockServices.setServices(MockMimeLookup.class);
        MockMimeLookup.setInstances(MimePath.parse(""),
                new TrailingWhitespaceRemove.FactoryImpl()
        );
        
        RandomTestContainer container = DocumentTesting.initContainer(null);
        container.setName(this.getName());
//        container.putProperty(RandomTestContainer.LOG_OP, Boolean.TRUE);
//        container.putProperty(DocumentTesting.LOG_DOC, Boolean.TRUE);
        container.addOp(new Op());
        container.addCheck(new Check());

        // Init trailing spaces removal
//        Document doc = container.getInstance(Document.class);
        BaseDocument doc = new BaseDocument(BaseKit.class, false);
        UndoManager undoManager = new UndoManager();
        doc.addUndoableEditListener(undoManager);
        doc.putProperty(UndoManager.class, undoManager);

        container.putProperty(Document.class, doc); // Replace original doc

        RandomText randomText = RandomText.join(
                RandomText.lowerCaseAZ(1),
                RandomText.spaceTabNewline(1),
                RandomText.phrase(" \n ", 1)
        );
        container.putProperty(RandomText.class, randomText);
        
        // Do a fixed scenario
        DocumentTesting.insert(container.context(), 0, "abc\ndef\n\n123 \n567 \nghi");
        ModRootElement modRootElement = ModRootElement.get(doc);
        modRootElement.resetMods(null);

        DocumentTesting.insert(container.context(), 3, " a ");
        //  000000000011111111111222222222
        //  012345678901234567890123456789
        // "abc a ndefnn123 n567 nghi"
        DocumentTesting.insert(container.context(), 8, " \n ");
        //  000000000011111111111222222222
        //  012345678901234567890123456789
        // "abc a nd n efnn123 n567 nghi"
        DocumentTesting.insert(container.context(), 28, "\n ");
        //  000000000011111111111222222222
        //  012345678901234567890123456789
        // "abc a nd n efnn123 n567 nghin "
        removeTrailingWhitespace(container.context(), policy);
        // Should be
        //  000000000011111111111222222222
        //  012345678901234567890123456789
        // "abc andn efnn123 n567 nghin"
        assertEquals(result, doc.getText(0, doc.getLength()));
        

        RandomTestContainer.Round round = container.addRound();
        round.setOpCount(1000);
        round.setRatio(DocumentTesting.INSERT_CHAR, 6);
        round.setRatio(DocumentTesting.INSERT_TEXT, 3);
        round.setRatio(DocumentTesting.INSERT_PHRASE, 1);
        round.setRatio(DocumentTesting.REMOVE_CHAR, 3);
        round.setRatio(DocumentTesting.REMOVE_TEXT, 1);
        round.setRatio(DocumentTesting.UNDO, 1);
        round.setRatio(DocumentTesting.REDO, 1);
        round.setRatio(Op.NAME, 0.5d);
        container.run(1213202006348L);
//        container.run(0L); // Random operation

    }
 
Example 10
Source File: XMLSyntaxParserTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private BaseDocument getDocument(String path) throws Exception {
    BaseDocument basedoc = (BaseDocument)Util.getResourceAsDocument(path);
    //must set the language for XML lexer to work.
    basedoc.putProperty(Language.class, XMLTokenId.language());
    return basedoc;
}
 
Example 11
Source File: AbstractTestCase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected XMLSyntaxSupport getSyntaxSupport(String path) throws Exception {
    BaseDocument doc = getResourceAsDocument(path);
    //must set the language inside unit tests
    doc.putProperty(Language.class, XMLTokenId.language());
    return ((XMLSyntaxSupport)doc.getSyntaxSupport());
}
 
Example 12
Source File: PreviewHintFix.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public ChangeInfo implement() throws Exception {
    EditList edits = fix.getEditList();

    Document oldDoc = info.getSnapshot().getSource().getDocument(true);
    //OffsetRange range = edits.getRange();
    OffsetRange range = new OffsetRange(0, oldDoc.getLength());
    String oldSource = oldDoc.getText(range.getStart(), range.getEnd());

    String mimeType = (String) oldDoc.getProperty("mimeType"); //NOI18N
    BaseDocument newDoc = new BaseDocument(false, mimeType);

    Language language = (Language) oldDoc.getProperty(Language.class);
    newDoc.putProperty(Language.class, language);
    newDoc.insertString(0, oldSource, null);
    edits.applyToDocument(newDoc);
    String newSource = newDoc.getText(0, newDoc.getLength());

    String oldTitle = NbBundle.getMessage(PreviewHintFix.class, "CurrentSource");
    String newTitle = NbBundle.getMessage(PreviewHintFix.class, "FixedSource");

    final DiffController diffView = DiffController.create(
            new DiffSource(oldSource, oldTitle),
            new DiffSource(newSource, newTitle));


    JComponent jc = diffView.getJComponent();

    jc.setPreferredSize(new Dimension(800, 600));

    // Warp view to a particular diff?
    // I can't just always jump to difference number 0, because when a hint
    // has changed only the whitespace (such as the fix which moves =begin entries to column 0)
    // there are no diffs, even though I want to jump to the relevant line.
    final int index = 0;
    final int firstLine = diffView.getDifferenceCount() == 0 ? NbDocument.findLineNumber((StyledDocument) oldDoc, edits.getRange().
            getStart()) : -1;
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            if (firstLine != -1) {
                diffView.setLocation(DiffController.DiffPane.Base,
                        DiffController.LocationType.LineNumber, firstLine);
            } else if (diffView.getDifferenceCount() > 0) {
                diffView.setLocation(DiffController.DiffPane.Base,
                        DiffController.LocationType.DifferenceIndex, index);
            }
        }
    });

    JButton apply = new JButton(NbBundle.getMessage(PreviewHintFix.class, "Apply"));
    JButton ok = new JButton(NbBundle.getMessage(PreviewHintFix.class, "Ok"));
    JButton cancel = new JButton(NbBundle.getMessage(PreviewHintFix.class, "Cancel"));
    String dialogTitle = NbBundle.getMessage(PreviewHintFix.class, "PreviewTitle",
            fix.getDescription());

    DialogDescriptor descriptor =
            new DialogDescriptor(jc, dialogTitle, true,
            new Object[]{apply, ok, cancel}, ok, DialogDescriptor.DEFAULT_ALIGN, null, null,
            true);
    Dialog dlg = null;

    try {
        dlg = DialogDisplayer.getDefault().createDialog(descriptor);
        dlg.setVisible(true);
        if (descriptor.getValue() == apply) {
            fix.implement();
        }
    } finally {
        if (dlg != null) {
            dlg.dispose();
        }
    }

    return null;
}
 
Example 13
Source File: PHPFormatterTestBase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void reformatFileContents(String file, Map<String, Object> options, boolean isTemplate, IndentPrefs indentPrefs) throws Exception {
    FileObject fo = getTestFile(file);
    assertNotNull(fo);

    String text = read(fo);

    int formatStart = 0;
    int formatEnd = text.length();
    int startMarkPos = text.indexOf(FORMAT_START_MARK);

    if (startMarkPos >= 0) {
        formatStart = startMarkPos;
        text = text.substring(0, formatStart) + text.substring(formatStart + FORMAT_START_MARK.length());
        formatEnd = text.indexOf(FORMAT_END_MARK);
        text = text.substring(0, formatEnd) + text.substring(formatEnd + FORMAT_END_MARK.length());
        GSFPHPParserTestUtil.setUnitTestCaretPosition(formatEnd);
        if (!isTemplate) {
            formatEnd --;
        }
        if (formatEnd == -1) {
            throw new IllegalStateException();
        }
    }

    BaseDocument doc = getDocument(text);
    assertNotNull(doc);

    if (isTemplate) {
        int carretPosition = text.indexOf('^');
        if (carretPosition == -1) {
            carretPosition = formatEnd;
        } else {
            if (carretPosition < formatStart) {
                formatStart--;
            }
            if (carretPosition < formatEnd) {
                formatEnd--;
            }
            text = text.substring(0, carretPosition) + text.substring(carretPosition + 1);
        }

        TokenFormatter.setUnitTestCarretPosition(carretPosition);
        GSFPHPParserTestUtil.setUnitTestCaretPosition(carretPosition);
        doc.remove(0, doc.getLength());
        doc.insertString(0, text, null);
        doc.putProperty(TokenFormatter.TEMPLATE_HANDLER_PROPERTY, new Object());
    }

    Formatter formatter = getFormatter(indentPrefs);
    //assertNotNull("getFormatter must be implemented", formatter);

    setupDocumentIndentation(doc, indentPrefs);

    Preferences prefs = CodeStylePreferences.get(doc).getPreferences();
    for (String option : options.keySet()) {
        Object value = options.get(option);
        if (value instanceof Integer) {
            prefs.putInt(option, ((Integer) value).intValue());
        } else if (value instanceof String) {
            prefs.put(option, (String) value);
        } else if (value instanceof Boolean) {
            prefs.put(option, ((Boolean) value).toString());
        } else if (value instanceof CodeStyle.BracePlacement) {
            prefs.put(option, ((CodeStyle.BracePlacement) value).name());
        } else if (value instanceof CodeStyle.WrapStyle) {
            prefs.put(option, ((CodeStyle.WrapStyle) value).name());
        }
    }

    format(doc, formatter, formatStart, formatEnd, false);
    String after = doc.getText(0, doc.getLength());
    assertDescriptionMatches(file, after, false, ".formatted");
    GSFPHPParserTestUtil.setUnitTestCaretPosition(-1);
}
 
Example 14
Source File: PhpTypedTextInterceptorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected void insertChar(String original, char insertText, String expected, String selection, boolean codeTemplateMode, Map<String, Object> formatPrefs) throws Exception {
    String source = wrapAsPhp(original);
    String reformatted = wrapAsPhp(expected);
    Formatter formatter = getFormatter(null);

    int sourcePos = source.indexOf('^');
    assertNotNull(sourcePos);
    source = source.substring(0, sourcePos) + source.substring(sourcePos+1);

    int reformattedPos = reformatted.indexOf('^');
    assertNotNull(reformattedPos);
    reformatted = reformatted.substring(0, reformattedPos) + reformatted.substring(reformattedPos+1);

    JEditorPane ta = getPane(source);
    Caret caret = ta.getCaret();
    caret.setDot(sourcePos);
    if (selection != null) {
        int start = original.indexOf(selection);
        assertTrue(start != -1);
        assertTrue("Ambiguous selection - multiple occurrences of selection string",
                original.indexOf(selection, start+1) == -1);
        ta.setSelectionStart(start);
        ta.setSelectionEnd(start+selection.length());
        assertEquals(selection, ta.getSelectedText());
    }

    BaseDocument doc = (BaseDocument) ta.getDocument();

    if (codeTemplateMode) {
        // Copied from editor/codetemplates/src/org/netbeans/lib/editor/codetemplates/CodeTemplateInsertHandler.java
        String EDITING_TEMPLATE_DOC_PROPERTY = "processing-code-template"; // NOI18N
        doc.putProperty(EDITING_TEMPLATE_DOC_PROPERTY, Boolean.TRUE);
    }

    if (formatter != null) {
        configureIndenters(doc, formatter, true);
    }

    setupDocumentIndentation(doc, null);

    if (formatter != null && formatPrefs != null) {
        setOptionsForDocument(doc, formatPrefs);
    }
    runKitAction(ta, DefaultEditorKit.defaultKeyTypedAction, ""+insertText);

    String formatted = doc.getText(0, doc.getLength());
    assertEquals(reformatted, formatted);

    if (reformattedPos != -1) {
        assertEquals(reformattedPos, caret.getDot());
    }
}
 
Example 15
Source File: CslTestBase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected void insertChar(String original, char insertText, String expected, String selection, boolean codeTemplateMode) throws Exception {
    String source = original;
    String reformatted = expected;
    Formatter formatter = getFormatter(null);

    int sourcePos = source.indexOf('^');
    assertNotNull(sourcePos);
    source = source.substring(0, sourcePos) + source.substring(sourcePos+1);

    int reformattedPos = reformatted.indexOf('^');
    assertNotNull(reformattedPos);
    reformatted = reformatted.substring(0, reformattedPos) + reformatted.substring(reformattedPos+1);

    JEditorPane ta = getPane(source);
    Caret caret = ta.getCaret();
    caret.setDot(sourcePos);
    if (selection != null) {
        int start = original.indexOf(selection);
        assertTrue(start != -1);
        assertTrue("Ambiguous selection - multiple occurrences of selection string",
                original.indexOf(selection, start+1) == -1);
        ta.setSelectionStart(start);
        ta.setSelectionEnd(start+selection.length());
        assertEquals(selection, ta.getSelectedText());
    }

    BaseDocument doc = (BaseDocument) ta.getDocument();

    if (codeTemplateMode) {
        // Copied from editor/codetemplates/src/org/netbeans/lib/editor/codetemplates/CodeTemplateInsertHandler.java
        String EDITING_TEMPLATE_DOC_PROPERTY = "processing-code-template"; // NOI18N
        doc.putProperty(EDITING_TEMPLATE_DOC_PROPERTY, Boolean.TRUE);
    }

    if (formatter != null) {
        configureIndenters(doc, formatter, true);
    }

    setupDocumentIndentation(doc, null);

    runKitAction(ta, DefaultEditorKit.defaultKeyTypedAction, ""+insertText);

    String formatted = doc.getText(0, doc.getLength());
    assertEquals(reformatted, formatted);

    if (reformattedPos != -1) {
        assertEquals(reformattedPos, caret.getDot());
    }
}
 
Example 16
Source File: CslTestBase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected JEditorPane getPane(String text) throws Exception {
    if (!SwingUtilities.isEventDispatchThread()) {
        fail("You must run this test from the event dispatch thread! To do that, add @Override protected boolean runInEQ() { return true } from your testcase!");
    }
    String BEGIN = "$start$"; // NOI18N
    String END = "$end$"; // NOI18N
    int sourceStartPos = text.indexOf(BEGIN);
    int caretPos = -1;
    int sourceEndPos = -1;
    if (sourceStartPos != -1) {
        text = text.substring(0, sourceStartPos) + text.substring(sourceStartPos+BEGIN.length());
        sourceEndPos = text.indexOf(END);
        assertTrue(sourceEndPos != -1);
        text = text.substring(0, sourceEndPos) + text.substring(sourceEndPos+END.length());
    } else {
        caretPos = text.indexOf('^');
        if (caretPos != -1) {
            text = text.substring(0, caretPos) + text.substring(caretPos+1);
        }
    }

    JEditorPane pane = new JEditorPane();
    pane.setContentType(getPreferredMimeType());
    final NbEditorKit kit = ((NbEditorKit)getEditorKit(getPreferredMimeType()));


    Thread preload = new Thread(new Runnable() {

        @Override
        public void run() {
            // Preload actions and other stuff
            if (kit instanceof Callable) {
                try {
                    ((Callable) kit).call();
                } catch (Exception ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
            kit.getActions();
        }
    });
    preload.start();
    preload.join();
    pane.setEditorKit(kit);
    pane.setText(text);

    BaseDocument bdoc = (BaseDocument)pane.getDocument();

    bdoc.putProperty(org.netbeans.api.lexer.Language.class, getPreferredLanguage().getLexerLanguage());
    bdoc.putProperty("mimeType", getPreferredMimeType());

    //bdoc.insertString(0, text, null);
    if (sourceStartPos != -1) {
        assertTrue(sourceEndPos != -1);
        pane.setSelectionStart(sourceStartPos);
        pane.setSelectionEnd(sourceEndPos);
    } else if (caretPos != -1) {
        pane.getCaret().setDot(caretPos);
    }
    pane.getCaret().setSelectionVisible(true);

    return pane;
}
 
Example 17
Source File: JspLexerTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void testSyntaxTree(String testFile) throws Exception {
    FileObject source = getTestFile("testfiles/" + testFile);
    BaseDocument doc = getDocument(source);


    JspParseData jspParseData = new JspParseData((Map<String, String>) Collections.EMPTY_MAP, true, true, true);

    InputAttributes inputAttributes = new InputAttributes();
    inputAttributes.setValue(JspTokenId.language(), JspParseData.class, jspParseData, false);
    doc.putProperty(InputAttributes.class, inputAttributes);


    TokenHierarchy th = TokenHierarchy.get(doc);
    TokenSequence ts = th.tokenSequence();


    StringBuilder output = new StringBuilder(ts.toString());

    assertDescriptionMatches(source, output.toString(), false, ".pass", true);
}
 
Example 18
Source File: TagBasedLexerFormatter.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void enterPressed() throws BadLocationException{
    BaseDocument doc = (BaseDocument) context.document();
    
    if (isTopLevelLanguage(doc)) {
        doc.putProperty(TransferData.ORG_CARET_OFFSET_DOCPROPERTY, new Integer(context.caretOffset()));
    }

    Integer dotPos = (Integer) doc.getProperty(TransferData.ORG_CARET_OFFSET_DOCPROPERTY);
    //assert dotPos != null;
    if(dotPos == null) {
        dotPos = context.caretOffset();
    }
    
    int origDotPos = dotPos.intValue() - 1; // dotPos - "\n".length()
    
    if (indexWithinCurrentLanguage(doc, origDotPos - 1)) {
        if (isSmartEnter(doc, dotPos)) {
            handleSmartEnter(context);
        } else {
            int newIndent = 0;
            int lineNumber = Utilities.getLineOffset(doc, dotPos);
            boolean firstRow = false;
            
            if (Utilities.getRowStart(doc, origDotPos) == origDotPos){
                newIndent = getExistingIndent(doc, lineNumber);
                firstRow = true;
            } else if (lineNumber > 0){
                newIndent = getExistingIndent(doc, lineNumber - 1);
            }
            
            TokenHierarchy tokenHierarchy = TokenHierarchy.get(doc);
            TokenSequence[] tokenSequences = (TokenSequence[]) tokenHierarchy.tokenSequenceList(supportedLanguagePath(), 0, Integer.MAX_VALUE).toArray(new TokenSequence[0]);
            TextBounds[] tokenSequenceBounds = new TextBounds[tokenSequences.length];
            
            for (int i = 0; i < tokenSequenceBounds.length; i++) {
                tokenSequenceBounds[i] = findTokenSequenceBounds(doc, tokenSequences[i]);
            }

            JoinedTokenSequence tokenSequence = new JoinedTokenSequence(tokenSequences, tokenSequenceBounds);
            tokenSequence.moveStart(); tokenSequence.moveNext();

            int openingTagOffset = getTagEndingAtPosition(tokenSequence, origDotPos - 1);
            
            if (isOpeningTag(tokenSequence, openingTagOffset)){
                newIndent += doc.getShiftWidth();
            }

            context.modifyIndent(Utilities.getRowStart(doc, dotPos), newIndent);
            
            if (firstRow){
                context.setCaretOffset(context.caretOffset() - newIndent);
            }
        }
    }
}
 
Example 19
Source File: AbstractTestCase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected BaseDocument getDocument(String path) throws Exception {
    BaseDocument doc = getResourceAsDocument(path);
    //must set the language inside unit tests
    doc.putProperty(Language.class, XMLTokenId.language());
    return doc;
}
 
Example 20
Source File: AbstractTestCase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected XMLSyntaxSupport getSyntaxSupport(String path) throws Exception {
    BaseDocument doc = getResourceAsDocument(path);
    //must set the language inside unit tests
    doc.putProperty(Language.class, XMLTokenId.language());
    return XMLSyntaxSupport.getSyntaxSupport(doc);
}