KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > eval > VariablesInfo


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.eval;
12
13 import org.eclipse.jdt.core.compiler.CharOperation;
14 import org.eclipse.jdt.internal.compiler.ClassFile;
15
16 /**
17  * This contains information about the installed variables such as
18  * their names, their types, the name of the class that defines them,
19  * the binary of the class (to be passed to the name environment when
20  * compiling the code snippet).
21  */

22 public class VariablesInfo {
23     GlobalVariable[] variables;
24     int variableCount;
25     char[] packageName;
26     char[] className;
27     ClassFile[] classFiles;
28 /**
29  * Creates a new variables info.
30  * The name of the global variable class is the simple name of this class.
31  * The package name can be null if the variables have been defined in the default package.
32  */

33 public VariablesInfo(char[] packageName, char[] className, ClassFile[] classFiles, GlobalVariable[] variables, int variableCount) {
34     this.packageName = packageName;
35     this.className = className;
36     this.classFiles = classFiles;
37     this.variables = variables;
38     this.variableCount = variableCount;
39 }
40 /**
41  * Returns the index of the given variable.
42  * Returns -1 if not found.
43  */

44 int indexOf(GlobalVariable var) {
45     for (int i = 0; i < this.variableCount; i++) {
46         if (var.equals(this.variables[i])) {
47             return i;
48         }
49     }
50     return -1;
51 }
52 /**
53  * Returns the variable with the given name.
54  * Returns null if not found.
55  */

56 GlobalVariable varNamed(char[] name) {
57     GlobalVariable[] vars = this.variables;
58     for (int i = 0; i < this.variableCount; i++) {
59         GlobalVariable var = vars[i];
60         if (CharOperation.equals(name, var.name)) {
61             return var;
62         }
63     }
64     return null;
65 }
66 }
67
Popular Tags