~ubuntu-branches/ubuntu/lucid/groovy/lucid

« back to all changes in this revision

Viewing changes to src/main/org/codehaus/groovy/control/messages/SimpleMessage.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2009-05-19 21:49:37 UTC
  • mfrom: (3.2.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090519214937-56mctwb05t3xd63r
Tags: 1.6.3-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2003-2007 the original author or authors.
3
 
 *
4
 
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 
 * you may not use this file except in compliance with the License.
6
 
 * You may obtain a copy of the License at
7
 
 *
8
 
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 
 *
10
 
 * Unless required by applicable law or agreed to in writing, software
11
 
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 
 * See the License for the specific language governing permissions and
14
 
 * limitations under the License.
15
 
 */
16
 
 
17
 
package org.codehaus.groovy.control.messages;
18
 
 
19
 
import java.io.PrintWriter;
20
 
 
21
 
import org.codehaus.groovy.control.Janitor;
22
 
import org.codehaus.groovy.control.ProcessingUnit;
23
 
import org.codehaus.groovy.control.SourceUnit;
24
 
 
25
 
 
26
 
 
27
 
/**
28
 
 *  A base class for compilation messages.
29
 
 *
30
 
 *  @author <a href="mailto:cpoirier@dreaming.org">Chris Poirier</a>
31
 
 *
32
 
 *  @version $Id: SimpleMessage.java 6778 2007-07-02 10:40:33Z glaforge $
33
 
 */
34
 
 
35
 
public class SimpleMessage extends Message
36
 
{
37
 
    protected String message;  // Message text
38
 
    protected Object data;     // Data, when the message text is an I18N identifier
39
 
    protected ProcessingUnit owner;
40
 
    
41
 
    public SimpleMessage( String message, ProcessingUnit source ) 
42
 
    {
43
 
        this( message, null, source );
44
 
    }
45
 
    
46
 
    public SimpleMessage( String message, Object data, ProcessingUnit source )
47
 
    {
48
 
        this.message = message;
49
 
        this.data    = null;
50
 
        this.owner = source;
51
 
    }
52
 
    
53
 
    
54
 
    public void write( PrintWriter writer, Janitor janitor )
55
 
    {
56
 
        if( owner instanceof SourceUnit )
57
 
        {
58
 
            String name = ((SourceUnit)owner).getName();
59
 
            writer.println( "" + name + ": " + message );
60
 
        }
61
 
        else
62
 
        {
63
 
            writer.println( message );
64
 
        }
65
 
    }
66
 
    
67
 
    
68
 
    public String getMessage()
69
 
    {
70
 
        return message;
71
 
    }
72
 
    
73
 
}
74
 
 
75
 
 
76
 
 
77
 
 
 
1
/*
 
2
 * Copyright 2003-2007 the original author or authors.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
package org.codehaus.groovy.control.messages;
 
18
 
 
19
import java.io.PrintWriter;
 
20
 
 
21
import org.codehaus.groovy.control.Janitor;
 
22
import org.codehaus.groovy.control.ProcessingUnit;
 
23
import org.codehaus.groovy.control.SourceUnit;
 
24
 
 
25
 
 
26
 
 
27
/**
 
28
 *  A base class for compilation messages.
 
29
 *
 
30
 *  @author <a href="mailto:cpoirier@dreaming.org">Chris Poirier</a>
 
31
 *
 
32
 *  @version $Id: SimpleMessage.java 6778 2007-07-02 10:40:33Z glaforge $
 
33
 */
 
34
 
 
35
public class SimpleMessage extends Message
 
36
{
 
37
    protected String message;  // Message text
 
38
    protected Object data;     // Data, when the message text is an I18N identifier
 
39
    protected ProcessingUnit owner;
 
40
    
 
41
    public SimpleMessage( String message, ProcessingUnit source ) 
 
42
    {
 
43
        this( message, null, source );
 
44
    }
 
45
    
 
46
    public SimpleMessage( String message, Object data, ProcessingUnit source )
 
47
    {
 
48
        this.message = message;
 
49
        this.data    = null;
 
50
        this.owner = source;
 
51
    }
 
52
    
 
53
    
 
54
    public void write( PrintWriter writer, Janitor janitor )
 
55
    {
 
56
        if( owner instanceof SourceUnit )
 
57
        {
 
58
            String name = ((SourceUnit)owner).getName();
 
59
            writer.println( "" + name + ": " + message );
 
60
        }
 
61
        else
 
62
        {
 
63
            writer.println( message );
 
64
        }
 
65
    }
 
66
    
 
67
    
 
68
    public String getMessage()
 
69
    {
 
70
        return message;
 
71
    }
 
72
    
 
73
}
 
74
 
 
75
 
 
76
 
 
77