Skip to main content
summaryrefslogtreecommitdiffstats
blob: 23d2cccc086f25d3f57e4bd5f77e089dcc72b80f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*******************************************************************************
 * Copyright (c) 2001, 2008 Oracle Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Oracle Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.common.internal.types;

import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.osgi.util.NLS;

/**
 * Diagnostic Factory for type comparator diagnostics.
 * 
 * @author cbateman
 * 
 */
public final class TypeComparatorDiagnosticFactory
{
    /**
     * The id used in the source field of all Diagnostic's created by this
     * factory to uniquely identify TypeComparator validation as their source
     * type.
     */
    public final static String SOURCE_IDENTIFIER                     = "org.eclipse.jst.jsf.common.types.TypeComparator"; //$NON-NLS-1$

    /**
     * A method expression was expected, but something else (i.e. a value
     * expression) was provided.
     */
    public final static int    METHOD_EXPRESSION_EXPECTED_ID = 0;

    /**
     * Value expression type was incompatible with the expected type.
     */
    public static final int    INCOMPATIBLE_TYPES_ID         = 1;

    /**
     * A value expression was expected, but something else (i.e. a method
     * expression) was provided.
     */
    public static final int    VALUE_EXPRESSION_EXPECTED_ID  = 2;

    /**
     * Method expression signature did not match what was expected.
     */
    public static final int    INCOMPATIBLE_METHOD_TYPES_ID  = 3;

    /**
     * A property was expected to be readable but no getter was found.
     */
    public static final int    PROPERTY_NOT_READABLE_ID      = 4;

    /**
     * A property was expected to be writable but no setter was found
     */
    public static final int    PROPERTY_NOT_WRITABLE_ID      = 5;
    
    /**
     * the number of diagnostic ids
     */
    public static final int    NUM_IDS = 6;

    private final TypeComparatorPreferences _prefs;

    /**
     * @param prefs
     */
    public TypeComparatorDiagnosticFactory(final TypeComparatorPreferences prefs)
    {
        _prefs = prefs;
    }
    // A method expression was supplied as expected, but its signature did
    // * not match the expected.
    /**
     * @return a diagnostic
     */
    public Diagnostic create_METHOD_EXPRESSION_EXPECTED()
    {
        return create(METHOD_EXPRESSION_EXPECTED_ID, Messages
                .getString("TypeComparator.Expression.No_Method")); //$NON-NLS-1$
    }

    /**
     * @param params
     * @return a diagnostic
     */
    public Diagnostic create_INCOMPATIBLE_TYPES(final Object[] params)
    {
        return create(
                INCOMPATIBLE_TYPES_ID,
                NLS
                        .bind(
                                Messages
                                        .getString("TypeComparator.Expression.Incompatible_Value"), params)); //$NON-NLS-1$
    }

    /**
     * @return a diagnostic
     */
    public Diagnostic create_VALUE_EXPRESSION_EXPECTED()
    {
        return create(VALUE_EXPRESSION_EXPECTED_ID, Messages
                .getString("TypeComparator.Expression.No_Value")); //$NON-NLS-1$
    }

    /**
     * @param params
     * @return a diagnostic
     */
    public Diagnostic create_INCOMPATIBLE_METHOD_TYPES(final Object[] params)
    {
        return create(INCOMPATIBLE_METHOD_TYPES_ID, NLS.bind(Messages
                .getString("TypeComparator.Expression.Incompatible_Method"), //$NON-NLS-1$
                params));
    }

    /**
     * @return a diagnostic
     */
    public Diagnostic create_PROPERTY_NOT_READABLE()
    {
        return create(PROPERTY_NOT_READABLE_ID, Messages
                .getString("TypeComparator.Expression.Not.Gettable")); //$NON-NLS-1$
    }

    /**
     * @return a diagnostic
     */
    public Diagnostic create_PROPERTY_NOT_WRITABLE()
    {
        return create(PROPERTY_NOT_WRITABLE_ID, Messages
                .getString("TypeComparator.Expression.Expected.Settable")); //$NON-NLS-1$
    }

    private BasicDiagnostic create(int diagnosticId, String message)
    {
        final int severity = _prefs.getDefaultSeverity(diagnosticId);
        return new BasicDiagnostic(severity, SOURCE_IDENTIFIER, diagnosticId, message,
                null);
    }
}

Back to the top