PostSharp aspect don't compile and fire - postsharp

I have a problem with PostSharp, which in short can be described as "some aspects don't fire and are not shown in PostSharp Explorer".
As could be seen on a screenshot two aspects from Authorization namespace, which are inherited from MethodInterceptorAspect are presented in PostSharp explorer and two new aspects from ExceptionHandling namespace which are derived from OnExceptionAspect are not.
Below is a code of one of them: a 'standard' aspect made by manual, almost the same as working aspets except it derives from another base class. I tried to identify the problem commenting different parts of code but it didn't help.
[Serializable]
[AttributeUsage(AttributeTargets.All)]
public class HandleExceptionAttribute : OnExceptionAspect
{
/// <summary>
/// Method executed <b>after</b> the body of methods to which this aspect is applied,
/// in case that the method resulted with an exception (i.e., in a <c>catch</c> block).
/// </summary>
/// <param name="args">Advice arguments.</param>
public override void OnException(MethodExecutionArgs args)
{
// some exception handling code
}
}
Moreover I just added a simple aspect right from the sample and it also not shown in PostSharp Explorer.
Question
So the question is: why aspects don't compile and fire?

Unswering my own question / Question is updated
It seems it's a bug of PostSharp or maybe a conflict between PostSharp, ReSharper and Visual Studio.
After appling one of new aspects on abstract method (previously aspect was appliet at class level) I've got a build error about 'incompatibilty'. Then I made abstract method virtual and project compiled succesfully. And Resharper Explorer shown both new aspects with all their affects. To make it clear I made 'undo changes' and wanted to repeat my actions, but this time all aspects dissappeared from PostSharp Explorer like they are not applied at all (while they where still applied totally about 300 times) and ReSharper highlighted all aspects usages as uknown types.
After suspending ReSharper, clearing the solution, restarting the VisualStudio and rebuilding solution, three aspect appeared in PostSharp explorer and the forth one appeared after PostSharp was applied once again to the project, where this aspect was used.
So if your aspect don't fire - check your PostSharp setup in projects that use aspets.
Related questions and answers:
applying aspect defined in one project, to methods in other projects of solution
'Add PostSharp to this project' no action
Thanks to #Jakub for guiding comment!

Related

How to make IntelliJ IDEA highlight the implemented methods of an interface

In Eclipse, when I put the caret on an Interface a class is implementing, the methods are marked in the side bar by default (as small colored stripes). This way I can easily see the methods the class is implementing without having to go into the interface itself and check out what methods it contains
I haven't found anything similar in IntelliJ. Is this even possible somehow easily?
(As a side note, I use Kotlin when programming, but I assume that this feature is not found for Java either)
In Java, you can put the caret on the "implements" keyword and press Ctrl-Shift-F7 to highlight methods implemented via an interface (if the class implements multiple interfaces, you get a popup asking you which methods to highlight). An equivalent feature for Kotlin is not implemented at this time (as of Kotlin 1.3).
In the class body, you can indeed see the interface methods highlighted by gutter icons, as the other answer says.
Methods or properties that are overriding or implementing anything of a parent class or interface are marked next to the line numbers, finding out from which class or interface they are coming can be done by hovering over them:
Clicking on it will take you to the parent/interface definition.
The same mark, but with a downwards pointing arrow, is used in the interface/parent class and shows a list of implementations/overrides when clicked on.
All of this also works for java and scala.

Custom control within framework not configurable or visible in Xcode

I have created a small selection of custom controls that are tagged #IBDesignable to enable visual configuration within IB. They work perfectly in their parent project/workspace and, as I wanted them to be reusable, I've created a framework.
After importing the framework into another project, I can access the classes programmatically but there is no visual representation in IB and none of the #IBInspectable properties are displayed in the attributes inspector. There are no errors reported during build or run phases. I guess I'm missing something somewhere but does anyone have any pointers?
It would appear that this is not currently possible (using Carthage as a dependency manager at any rate) without considerable effort with workarounds. This kind of defeats the object IMO!
For now it seems that you need to import the framework project into the product project. Explanation here but, for now, this seems dead in the water.

What does this icon in Eclipse mean?

I am referring specifically to the green plus sign in the screenshot below.
[edit] This is taken from "Outline" view, and I am coding in Java.
This might help:
What do the icons in Eclipse mean?
From the icon index, the plus means add, the C means public class, and the warning means that there is a java element warning.
So from what I can assume, it means you can add a new public class, but is warning you of possible problems with your current project.
The green + sign is an overlay that shows that the visibility of the class is set to public. The orange is a warning that there could be a potential issue in that class. This might not necessarily stop your class from running or performing well. It is just telling you to be aware of something that may or may not be harmful.

applying aspect defined in one project, to methods in other projects of solution

I have created an aspect class inherited from OnMethodBoundaryAspect class of Postsharp. When I use the aspect in the same project where I have defined it, it works fine. But when I use the aspect in another project in my solution, the aspect would not be applied. In this case the PostSharp Explorer says "there is no aspect in the current solution, ..."
How can I solve this problem and use my aspect defined in project A to methods or classes in project B in my solution?
Thanks

Toolbar items dynamically

I need to create dynamically buttons in main toolbar. I found a solution, but I can create just one button (dynamic contribution item - class extending ContributionItem). But I need to create more than one button, but I cannot find the solution.
I'm fighting with task to create plugin, which parses a XML file containing structure of menu and toolbars. We've already done this plugin for Visual Studio. Its quite easy in principle, but I found swiftly, that not for Eclipse. There is one small but critical otherness. Plugins are implemented declaratively in Eclipse. The file plugin.xml is the gist of plugin's infrastructure, Java code is just ancillary.
The customer wants to refresh the menu and toolbar whenever the selected project is changed. Eclipse lacks several features needed to get the task done. Main menu and main toolbar are cteated at Eclipse's start-up and then they can be hardly rebuilt.
In the most cases the conditions defined at enabledWhen/visibleWhen elements are sufficient to filter contributions according to the context (active part, selected object, whatever else).
If you need to have more freedom, please try E4 ToolControl that allows you to implement your own UI elements:
#PostConstruct
public void createControls(Composite parent) {
//your custom code here
}
More details here https://www.vogella.com/tutorials/EclipseRCP/article.html#toolcontrols
From my understanding you want to have different buttons on the main toolbar depending on the selection of the project explorer (eg. 1 project is java project, the other is javascript etc.). First you will have to contribute to the main toolbar. I think there are some tutorial available so google will help.
The main steps are:
1. create a command (org.eclipse.ui.commmands)
2. create a handler (org.eclipse.ui.handlers) with the previously declared command id
3. contribute to the main toolbar (org.eclipse.ui.menus) with menucontribution and commandId with the following locationURI: toolbar:org.eclipse.ui.main.toolbar?after=misc
showing/hiding, enabling/disabling a menu item/button also can be done declaratively or "mixed". Declaratively means eg. using enabledWhen/visibleWhen...
Mixed means using property tester (org.eclipse.core.expressions.propertyTester). With this you can define your "enablement logic" in Java code.
In Eclipse e4 the UI is generated from a, EMF based, model. The Application.e4xmi serves as a base for that model. Contributions to the model can be done via fragments, which are again XML, or via processors. Processors are written in Java and use e4 services, like the part service, to modify the model at runtime.
I think you want to write a processor that parses your custom XML and modifies the eclipse e4 model accordingly.