summaryrefslogtreecommitdiff
path: root/sources/scalac/symtab/SourceCompleter.java
blob: 1656f2029f6e98a2ae5289da5297086f934d0e42 (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
/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
**                                                                      **
** $Id$
\*                                                                      */

package scalac.symtab;

import scalac.*;
import scalac.ast.parser.*;
import scalac.typechecker.Analyzer;
import java.io.*;


public class SourceCompleter extends Type.LazyType {

    /** the global compilation environment
     */
    protected Global global;
    protected String filename;
    private boolean completed = false;

    public SourceCompleter(Global global, String filename) {
        this.global = global;
        this.filename = filename;
    }

    /** complete class symbol c by loading the class
     */
    public void complete(Symbol c) {
	if (completed) {
	    c.setInfo(Type.ErrorType);
	} else if (filename != null) {
	    try {
		String fname = filename;
		long msec = System.currentTimeMillis();
		Unit unit = new Unit(global, new Sourcefile(filename, false));
		filename = null;
		global.PHASE.PARSER.createPhase(global).apply(unit);
		((Analyzer)global.PHASE.ANALYZER.createPhase(global)).lateEnter(unit, c);
		global.operation("added " + fname + " in " +
			(System.currentTimeMillis() - msec) + "ms");
	    } catch (IOException e) {
		e.printStackTrace();
		global.error("i/o error while loading " + c);
		c.setInfo(Type.ErrorType);
	    }
	    completed = true;
	}
    }
}