Class CategorizedProblem

  • All Implemented Interfaces:
    IProblem

    public abstract class CategorizedProblem
    extends Object
    implements IProblem
    Richer description of a Java problem, as detected by the compiler or some of the underlying technology reusing the compiler. With the introduction of org.eclipse.jdt.core.compiler.CompilationParticipant, the simpler problem interface IProblem did not carry enough information to better separate and categorize Java problems. In order to minimize impact on existing API, Java problems are still passed around as IProblem, though actual implementations should explicitly extend CategorizedProblem. Participants can produce their own problem definitions, and given these are categorized problems, they can be better handled by clients (such as user interface).

    A categorized problem provides access to:

    • its location (originating source file name, source position, line number)
    • its message description
    • predicates to check its severity (error, warning, or info)
    • its ID : a number identifying the very nature of this problem. All possible IDs for standard Java problems are listed as constants on IProblem.
    • its marker type : a string identifying the problem creator. It corresponds to the marker type chosen if this problem was to be persisted. Standard Java problems are associated to marker type "org.eclipse.jdt.core.problem").
    • its category ID : a number identifying the category this problem belongs to. All possible IDs for standard Java problem categories are listed in this class.

    Note: the compiler produces IProblems internally, which are turned into markers by the JavaBuilder so as to persist problem descriptions. This explains why there is no API allowing to reach IProblem detected when compiling. However, the Java problem markers carry equivalent information to IProblem, in particular their ID (attribute "id") is set to one of the IDs defined on this interface.

    Note: Standard Java problems produced by Java default tooling will be subclasses of this class. Technically, most API methods dealing with problems are referring to IProblem for backward compatibility reason. It is intended that CategorizedProblem will be subclassed for custom problem implementation when participating in compilation operations, so as to allow participant to contribute their own marker types, and thus defining their own domain specific problem/category IDs.

    Note: standard Java problems produced by Java default tooling will set the marker IMarker#SOURCE_ID attribute to JavaBuilder#SOURCE_ID; compiler participants may specify the IMarker#SOURCE_ID attribute of their markers by adding it to the extra marker attributes of the problems they generate; markers resulting from compiler participants' problems that do not have the IMarker#SOURCE_ID extra attribute set do not have the JavaBuilder#SOURCE_ID attribute set either.

    Since:
    3.2
    • Field Detail

      • CAT_UNSPECIFIED

        public static final int CAT_UNSPECIFIED
        List of standard category IDs used by Java problems, more categories will be added in the future.
        See Also:
        Constant Field Values
      • CAT_BUILDPATH

        public static final int CAT_BUILDPATH
        Category for problems related to buildpath
        See Also:
        Constant Field Values
      • CAT_SYNTAX

        public static final int CAT_SYNTAX
        Category for fatal problems related to syntax
        See Also:
        Constant Field Values
      • CAT_IMPORT

        public static final int CAT_IMPORT
        Category for fatal problems in import statements
        See Also:
        Constant Field Values
      • CAT_TYPE

        public static final int CAT_TYPE
        Category for fatal problems related to types, could be addressed by some type change
        See Also:
        Constant Field Values
      • CAT_MEMBER

        public static final int CAT_MEMBER
        Category for fatal problems related to type members, could be addressed by some field or method change
        See Also:
        Constant Field Values
      • CAT_INTERNAL

        public static final int CAT_INTERNAL
        Category for fatal problems which could not be addressed by external changes, but require an edit to be addressed
        See Also:
        Constant Field Values
      • CAT_JAVADOC

        public static final int CAT_JAVADOC
        Category for optional problems in Javadoc
        See Also:
        Constant Field Values
      • CAT_CODE_STYLE

        public static final int CAT_CODE_STYLE
        Category for optional problems related to coding style practices
        See Also:
        Constant Field Values
      • CAT_POTENTIAL_PROGRAMMING_PROBLEM

        public static final int CAT_POTENTIAL_PROGRAMMING_PROBLEM
        Category for optional problems related to potential programming flaws
        See Also:
        Constant Field Values
      • CAT_NAME_SHADOWING_CONFLICT

        public static final int CAT_NAME_SHADOWING_CONFLICT
        Category for optional problems related to naming conflicts
        See Also:
        Constant Field Values
      • CAT_DEPRECATION

        public static final int CAT_DEPRECATION
        Category for optional problems related to deprecation
        See Also:
        Constant Field Values
      • CAT_UNNECESSARY_CODE

        public static final int CAT_UNNECESSARY_CODE
        Category for optional problems related to unnecessary code
        See Also:
        Constant Field Values
      • CAT_UNCHECKED_RAW

        public static final int CAT_UNCHECKED_RAW
        Category for optional problems related to type safety in generics
        See Also:
        Constant Field Values
      • CAT_NLS

        public static final int CAT_NLS
        Category for optional problems related to internationalization of String literals
        See Also:
        Constant Field Values
      • CAT_RESTRICTION

        public static final int CAT_RESTRICTION
        Category for optional problems related to access restrictions
        See Also:
        Constant Field Values
      • CAT_MODULE

        public static final int CAT_MODULE
        Category for fatal problems relating to modules
        Since:
        3.14
        See Also:
        Constant Field Values
    • Constructor Detail

      • CategorizedProblem

        public CategorizedProblem()
    • Method Detail

      • getCategoryID

        public abstract int getCategoryID()
        Returns an integer identifying the category of this problem. Categories, like problem IDs are defined in the context of some marker type. Custom implementations of CategorizedProblem may choose arbitrary values for problem/category IDs, as long as they are associated with a different marker type. Standard Java problem markers (i.e. marker type is "org.eclipse.jdt.core.problem") carry an attribute "categoryId" persisting the originating problem category ID as defined by this method).
        Returns:
        id - an integer identifying the category of this problem
      • getMarkerType

        public abstract String getMarkerType()
        Returns the marker type associated to this problem, if it gets persisted into a marker by the JavaBuilder Standard Java problems are associated to marker type "org.eclipse.jdt.core.problem"). Note: problem markers are expected to extend "org.eclipse.core.resources.problemmarker" marker type.
        Returns:
        the type of the marker which would be associated to the problem
      • getExtraMarkerAttributeNames

        public String[] getExtraMarkerAttributeNames()
        Returns the names of the extra marker attributes associated to this problem when persisted into a marker by the JavaBuilder. Extra attributes are only optional, and are allowing client customization of generated markers. By default, no EXTRA attributes is persisted, and a categorized problem only persists the following attributes: The names must be eligible for marker creation, as defined by IMarker#setAttributes(String[], Object[]), and there must be as many names as values according to getExtraMarkerAttributeValues(). Note that extra marker attributes will be inserted after default ones (as described in getMarkerType(), and thus could be used to override defaults.
        Returns:
        the names of the corresponding marker attributes
      • getExtraMarkerAttributeValues

        public Object[] getExtraMarkerAttributeValues()
        Returns the respective values for the extra marker attributes associated to this problem when persisted into a marker by the JavaBuilder. Each value must correspond to a matching attribute name, as defined by getExtraMarkerAttributeNames(). The values must be eligible for marker creation, as defined by IMarker#setAttributes(String[], Object[])}.
        Returns:
        the values of the corresponding extra marker attributes
      • isInfo

        public boolean isInfo()
        Returns whether the severity of this problem is 'Info'.

        Note: This implementation always returns false, subclasses can override.

        Specified by:
        isInfo in interface IProblem
        Returns:
        true if the severity of this problem is 'Info', false otherwise
        Since:
        3.12