How to add custom FoldingBuilder

Hi I need the same functionality as StdFileTypes.JAVA but with my own FoldingBuilder and did following(long way):

private static final LanguageFileType TWM_JAVA_FILE_TYPE = new TWMJavaLangFileType();

public void initComponent() {
ApplicationManager.getApplication().runWriteAction(
new Runnable() {
public void run() {
FileTypeManager.getInstance().registerFileType(TWM_JAVA_FILE_TYPE, new String[]{"java"});
}
}
);
}

public class TWMJavaLangFileType extends LanguageFileType {

protected TWMJavaLangFileType() {
super(new TWMJavaLanguage());
}

@NotNull
@NonNls
public String getName() {
return StdFileTypes.JAVA.getName();
}

@NotNull
public String getDescription() {
return StdFileTypes.JAVA.getDescription();
}

@NotNull
@NonNls
public String getDefaultExtension() {
return StdFileTypes.JAVA.getDefaultExtension();
}

@Nullable
public Icon getIcon() {
return StdFileTypes.JAVA.getIcon();
}
}

public class TWMJavaLanguage extends Language {

protected TWMJavaLanguage() {
super(StdLanguages.JAVA.getID(), StdLanguages.JAVA.getMimeTypes());
}

@Override
@Nullable
public ParserDefinition getParserDefinition() {
return StdLanguages.JAVA.getParserDefinition();
}

// Other wrappers
....................

@Override
@Nullable
public FoldingBuilder getFoldingBuilder() {
return new TWMFoldingBuilder(); //breakpoint here
}

}

and I added breakpoint for getFoldingBuilder() method and for TWMFoldingBuilder class methods and it seems I did something wrong, my FoldingBuilder implementation was not added properly

Thanks in advance

Edited by: Sargis Harutyunyan on Jun 3, 2008 3:55 PM

2 comments
Comment actions Permalink

Hello Sargis,

This is not the right way to implement this. If you need to provide custom
folding in Java, you need to provide your own TextEditorHighlightingPass
that will fold the parts of code that you need.

Hi I need the same functionality as StdFileTypes.JAVA but with my own
FoldingBuilder and did following(long way):

public void initComponent() {
ApplicationManager.getApplication().runWriteAction(
new Runnable() {
public void run() {

FileTypeManager.getInstance().registerFileType(TWM_JAVA_FILE_TYPE, new
String[]{"java"});
}
}
);
}
public class TWMJavaLangFileType extends LanguageFileType {

protected TWMJavaLangFileType() {
super(new TWMJavaLanguage());
}
@NotNull
@NonNls
public String getName() {
return StdFileTypes.JAVA.getName();
}
@NotNull
public String getDescription() {
return StdFileTypes.JAVA.getDescription();
}
@NotNull
@NonNls
public String getDefaultExtension() {
return StdFileTypes.JAVA.getDefaultExtension();
}
@Nullable
public Icon getIcon() {
return StdFileTypes.JAVA.getIcon();
}
}
public class TWMJavaLanguage extends Language {

protected TWMJavaLanguage() {
super(StdLanguages.JAVA.getID(),
StdLanguages.JAVA.getMimeTypes());
}
@Override
@Nullable
public ParserDefinition getParserDefinition() {
return StdLanguages.JAVA.getParserDefinition();
}
// Other wrappers
....................
@Override
@Nullable
public FoldingBuilder getFoldingBuilder() {
return new TWMFoldingBuilder(); //breakpoint here
}
}

and I added breakpoint for getFoldingBuilder() method and for
TWMFoldingBuilder class methods and it seems I did something wrong, my
FoldingBuilder implementation was not added properly

Thanks in advance

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Thanks for help Dmitry, I will dig more and try to do it with TextEditorHighlightingPass as you suggested

0

Please sign in to leave a comment.