~vil/pydev/upstream

« back to all changes in this revision

Viewing changes to org.python.pydev/src/org/python/pydev/editor/model/ItemPointer.java

  • Committer: Vladimír Lapáček
  • Date: 2006-08-30 18:38:44 UTC
  • Revision ID: vladimir.lapacek@gmail.com-20060830183844-f4d82c1239a7770a
Initial import of upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Author: atotic
 
3
 * Created on Apr 14, 2004
 
4
 * License: Common Public License v1.0
 
5
 */
 
6
package org.python.pydev.editor.model;
 
7
 
 
8
import java.io.File;
 
9
 
 
10
import org.python.pydev.editor.codecompletion.revisited.visitors.Definition;
 
11
import org.python.pydev.parser.jython.SimpleNode;
 
12
 
 
13
/**
 
14
 * Pointer points to a python resource inside a file system. 
 
15
 * 
 
16
 * You can create one of these, and use PyOpenAction to open the 
 
17
 * right editor.
 
18
 */
 
19
public class ItemPointer {
 
20
 
 
21
        public Object file;     // IFile or File object
 
22
        public Location start; // (first character)
 
23
        public Location end;   // (last character)
 
24
    public Definition definition; //the definition that originated this ItemPointer (it might be null).
 
25
        
 
26
        public ItemPointer(Object file) {
 
27
                this(file, new Location(), new Location());
 
28
        }
 
29
 
 
30
        public ItemPointer(File file, SimpleNode n) {
 
31
        int line = n.beginLine;
 
32
        int col = n.beginColumn;
 
33
        
 
34
        this.file = file;
 
35
        this.start = new Location(line-1, col-1);
 
36
        this.end = new Location(line-1, col-1);
 
37
    }
 
38
    
 
39
        public ItemPointer(Object file, Location start, Location end) {
 
40
                this.file = file;
 
41
                this.start = start;
 
42
                this.end = end;
 
43
        }
 
44
    
 
45
    public ItemPointer(File file2, Location location, Location location2, Definition definition) {
 
46
        this(file2, location, location2);
 
47
        this.definition = definition;
 
48
    }
 
49
 
 
50
    @Override
 
51
    public String toString() {
 
52
        StringBuffer buffer = new StringBuffer("ItemPointer [");
 
53
        buffer.append(file);
 
54
        buffer.append(" - ");
 
55
        buffer.append(start);
 
56
        buffer.append(" - ");
 
57
        buffer.append(end);
 
58
        buffer.append("]");
 
59
        return buffer.toString();
 
60
    }
 
61
    
 
62
    @Override
 
63
    public boolean equals(Object obj) {
 
64
        if(!(obj instanceof ItemPointer)){
 
65
            return false;
 
66
        }
 
67
        
 
68
        ItemPointer i = (ItemPointer) obj;
 
69
        if(!i.file.equals(file)){
 
70
            return false;
 
71
        }
 
72
        if(!i.start.equals(start)){
 
73
            return false;
 
74
        }
 
75
        if(!i.end.equals(end)){
 
76
            return false;
 
77
        }
 
78
        
 
79
        return true;
 
80
    }
 
81
    
 
82
    @Override
 
83
    public int hashCode() {
 
84
        if(this.file != null){
 
85
            return this.file.hashCode() * 17;
 
86
        }else{
 
87
            return (this.end.column+1) * (this.start.line+2) * 9;
 
88
        }
 
89
    }
 
90
}