Code folding - getPlaceholderText not executing?

Hi everyone,

I was able to implement a FoldingBuilderEx class, and it works pretty well. I am specifically trying to code fold annotations that have lots of values. This works really well when the annotation is "on top" like this:

(before folding)

@NetworkAnnotation(
retentionTime = "",
destination = "",
purposeDescription = "Heya how is it going",
encryptedInTransmission = false)
final com.android.volley.Request<Object> add = queue.add(null)

(after folding)

@NetworkAnnotation ("Heya how is it going")
final com.android.volley.Request<Object> add = queue.add(null)

However, if the annotation is embedded in a method to annotate its parameters, like below:

manager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
new LocationListener() {
@Override
public void onLocationChanged(
@LocationAnnotation(
purpose={LocationPurpose.provide_location_based_content},
purposeDescription={"Provide location-based weather information"},
visibility={Visibility.WHILE_IN_USE},
frequency={"When the app is open"},
dataType={LocationDataType.FINE_GRAINED_LATITUDE_LONGITUDE}
)
Location location) {

}

Then the LocationAnnotation does not fold correctly. Instead it folds to this: @{ ... } and the getPlaceholderText method in the FoldingDescriptor I create is never even called.

Any help is greatly appreciated. Thanks!

0
2 comments

It might be builtin Java annotation folding, please check whether com.intellij.codeInsight.folding.impl.JavaFoldingBuilderBase#addAnnotationsToFold interferes here.

0

Hi there,

I think I have a similar problem. I want to create a FoldingDescriptor for large swagger annotations, e.g. ApiOperation. Plugin source code at https://github.com/ideadapt/intellij-swagger-annotations.

My class extends FoldingBuilderEx.

During development I have found that the CompositeFoldingBuilder only registers one FoldingDescriptor per region, hence I set the order of my extension in plugin.xml to "first". This made my unit tests and "runIde" work. There is already another thread about a similar issue https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000001164-Overriding-FoldingDescriptors-SOLVED-

Unit tests are green, gradle task runIde also works. Fine. But when I install the plugin from disk and open a Java project in Intellij, it does not work.

Yann Cebron says that it might be because com.intellij.codeInsight.folding.impl.JavaFoldingBuilderBase#addAnnotationsToFold interferes with my plugin code. According to the symptoms that is true (my plugin is loaded without errors, but annotation is still fold to @{...}). But what can I do to prevent this interference?

Then I stumbled upon this thread https://intellij-support.jetbrains.com/hc/en-us/community/posts/206787745-How-to-add-custom-FoldingBuilder, stating java code folding can not simply be overwritten the same way code folding of a custom language plugin might be ovewritten. Is this true? If so, how exactly would I use the proposed TextEditorHighlightingPass to accomplish java code folding customization?

 

Thanks for any help, leading me into the right direction :)

0

Please sign in to leave a comment.