Marci-man
Marci-man

Reputation: 2233

Extend Eclipse Error / Warning mechanism to include other code hints

We are developing some automated tasks in Java in Eclipse. We are using our in-house Framework for that. In this framework we have certain getButton().press() and getButton().release()

Personally I forget a lot of the times to release a pressed button. Is there a way to tell eclipse or even the compiler to throw an error or at least a warning if a press statement is not followed by matching release? The release statements don't have to follow the press statement immediately.

Could you please also suggests tags for this question, I am not sure how what tags would be appropriate.

Upvotes: 1

Views: 100

Answers (1)

Armine
Armine

Reputation: 1695

The errors/warnings shown in Eclipse are called problem markers. You can add problem marker as a tag.

Here is how the problem markers are implemented in Eclipse:

  • Right before compiling the resource, they remove all problem markers from the resource:

    void compileResource(IResource resource) {
        resource.deleteMarkers(IMarker.PROBLEM, true, Resource.DEPTH_INFINITE);
        doCompileResource(resource);
    }
    
  • During compilation, errors are attached to the resource as follows:

    void reportError(IResource resource, int line, String msg) {
       IMarker m = resource.createMarker(IMarker.PROBLEM);
       m.setAttribute(IMarker.LINE_NUMBER, line);
       m.setAttribute(IMarker.MESSAGE, msg);
       m.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
       m.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
    }
    
  • Markers can be created in this way:

    IMarker marker = file.createMarker(IMarker.TASK);
    
  • And Markers can be deleted in this way:

    try {
        marker.delete();
    } catch (CoreException e) {
        // Something went wrong
    }
    

More you can find in Eclipse F&Q and Eclipse Help.

Also, this article may be useful too.

Upvotes: 1

Related Questions