Quantcast
Channel: Oracle Bloggers
Viewing all articles
Browse latest Browse all 19780

Perl Code Folding

$
0
0

I took some first steps in working on Perl code folding for the Perl/NetBeans project that Sudeep Hazra is working on.

You can see the first signs of code folding above, though not completely correct yet.

The main class I changed was this one, as follows, giving you a lot of default functionality out of the box:

import org.netbeans.api.lexer.Language;
import org.netbeans.modules.csl.spi.DefaultLanguageConfig;
import org.netbeans.modules.csl.spi.LanguageRegistration;
import org.netbeans.perl.lexer.PerlTokenId;

//@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.lexer.LanguageProvider.class)
@LanguageRegistration(mimeType = "text/x-perl")
public class PerlLanguageProvider extends DefaultLanguageConfig {

    @Override
    public Language getLexerLanguage() {
        return PerlTokenId.getLanguage();
    }

    @Override
    public String getDisplayName() {
        return "Perl";
    }
//    @Override
//    public Language findLanguage(String mimeType) {
//        if ("text/x-perl".equals(mimeType)){
//            return new PerlLanguageHierarchy().language();
//        }
//
//        return null;
//    }
//
//    @Override
//    public LanguageEmbedding findLanguageEmbedding(Token token, LanguagePath lp, InputAttributes ia) {
//         return null;
//    }
} 

Next, unrelated but helpful, the brace matcher can be made to work quite simply by doing the following, which means that two classes can be deleted:

import org.netbeans.spi.editor.bracesmatching.BracesMatcher;
import org.netbeans.spi.editor.bracesmatching.BracesMatcherFactory;
import org.netbeans.spi.editor.bracesmatching.MatcherContext;
import org.netbeans.spi.editor.bracesmatching.support.BracesMatcherSupport;

@MimeRegistration(mimeType="text/x-perl", service=BracesMatcherFactory.class)
public class PerlBracesMatcherFactory implements BracesMatcherFactory {
    @Override
    public BracesMatcher createMatcher(MatcherContext context) {
        return BracesMatcherSupport.defaultMatcher(context, -1, -1);
    }
}

The Editors/text/x-perl section of the layer needs to be rewritten to the following:

<folder name="Editors">    <folder name="text">        <folder name="x-perl">            <attr name="displayName" bundlevalue="org.netbeans.perl.file.Bundle#Editors/text/x-perl"/>            <folder name="FoldManager">                <file name="org-netbeans-editor-CustomFoldManager$Factory.instance"/>            </folder>            <file name="org-netbeans-perl-parser-PerlParserFactory.instance"/>            <file name="org-netbeans-perl-parser-SyntaxErrorsHighlightingTaskFactory.instance"/>            <folder name="FontsColors">                <folder name="NetBeans">                    <folder name="Defaults">                        <file name="org-netbeans-perl-file-FontAndColors.xml" url="FontAndColors.xml">                            <attr name="SystemFileSystem.localizingBundle" bundlevalue="org.netbeans.perl.file.Bundle"/>                        </file>                    </folder>                </folder>            </folder>        </folder>    </folder></folder>

Surprised by any of the above information? Ha. That means you haven't followed the related tutorials:

http://platform.netbeans.org/tutorials/nbm-javacc-lexer.html
http://platform.netbeans.org/tutorials/nbm-javacc-parser.html

Do yourself a favor and follow the above two tutorials before even thinking about creating your own editor on top of the NetBeans IDE APIs. 

Next, I'm working on the FoldManager and its factory, which I so far have based on the following:

http://svn.debux.org/webmotion-ext/webmotion-plugin-netbeans/trunk/src/org/debux/webmotion/netbeans/WebMotionFoldManager.java

More soon. I'm aiming to have quite some fun documentation relating to code folding, which is one of the NetBeans IDE APIs about which sporadically (since, after all, how many people in the world are creating editors?) questions arise, soon!


Viewing all articles
Browse latest Browse all 19780

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>