KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > env > NameEnvironmentAnswer


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.compiler.env;
12
13 public class NameEnvironmentAnswer {
14     
15     // only one of the three can be set
16
IBinaryType binaryType;
17     ICompilationUnit compilationUnit;
18     ISourceType[] sourceTypes;
19     AccessRestriction accessRestriction;
20     
21     public NameEnvironmentAnswer(IBinaryType binaryType, AccessRestriction accessRestriction) {
22         this.binaryType = binaryType;
23         this.accessRestriction = accessRestriction;
24     }
25
26     public NameEnvironmentAnswer(ICompilationUnit compilationUnit, AccessRestriction accessRestriction) {
27         this.compilationUnit = compilationUnit;
28         this.accessRestriction = accessRestriction;
29     }
30
31     public NameEnvironmentAnswer(ISourceType[] sourceTypes, AccessRestriction accessRestriction) {
32         this.sourceTypes = sourceTypes;
33         this.accessRestriction = accessRestriction;
34     }
35     /**
36      * Returns the associated access restriction, or null if none.
37      */

38     public AccessRestriction getAccessRestriction() {
39         return this.accessRestriction;
40     }
41     /**
42      * Answer the resolved binary form for the type or null if the
43      * receiver represents a compilation unit or source type.
44      */

45     public IBinaryType getBinaryType() {
46         return this.binaryType;
47     }
48
49     /**
50      * Answer the compilation unit or null if the
51      * receiver represents a binary or source type.
52      */

53     public ICompilationUnit getCompilationUnit() {
54         return this.compilationUnit;
55     }
56
57     /**
58      * Answer the unresolved source forms for the type or null if the
59      * receiver represents a compilation unit or binary type.
60      *
61      * Multiple source forms can be answered in case the originating compilation unit did contain
62      * several type at once. Then the first type is guaranteed to be the requested type.
63      */

64     public ISourceType[] getSourceTypes() {
65         return this.sourceTypes;
66     }
67
68     /**
69      * Answer whether the receiver contains the resolved binary form of the type.
70      */

71     public boolean isBinaryType() {
72         return this.binaryType != null;
73     }
74
75     /**
76      * Answer whether the receiver contains the compilation unit which defines the type.
77      */

78     public boolean isCompilationUnit() {
79         return this.compilationUnit != null;
80     }
81
82     /**
83      * Answer whether the receiver contains the unresolved source form of the type.
84      */

85     public boolean isSourceType() {
86         return this.sourceTypes != null;
87     }
88     
89     public boolean ignoreIfBetter() {
90         return this.accessRestriction != null && this.accessRestriction.ignoreIfBetter();
91     }
92     
93     /*
94      * Returns whether this answer is better than the other awswer.
95      * (accessible is better than discouraged, which is better than
96      * non-accessible)
97      */

98     public boolean isBetter(NameEnvironmentAnswer otherAnswer) {
99         if (otherAnswer == null) return true;
100         if (this.accessRestriction == null) return true;
101         return otherAnswer.accessRestriction != null
102             && this.accessRestriction.getProblemId() < otherAnswer.accessRestriction.getProblemId();
103     }
104 }
105
Popular Tags