Skip to main content
summaryrefslogtreecommitdiffstats
blob: 713699a2dcfd0b04660ab083d53729af0394b32a (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*******************************************************************************
 * Copyright (c) 2001, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jem.internal.adapters.jdom;
/*


 */

import java.io.File;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.*;
import org.eclipse.jem.internal.java.adapters.nls.ResourceHandler;
/**
 * Insert the type's description here.
 * Creation date: (8/16/2000 11:06:46 PM)
 * @author: Administrator
 */
public class JDOMClassFinder {
	
	private static JDOMClassFinder instance;
/**
 * JDOMClassFinder constructor comment.
 */
public JDOMClassFinder() {
	super();
}
protected IPath getBinaryPathFromQualifiedName(String qualifiedName) {
	return new Path(qualifiedName.replace('.', File.separatorChar) + ".class");//$NON-NLS-1$
}
public IType getBinaryType(String qualifiedName) {
	
	IJavaElement found = getJavaElement(qualifiedName);
	if (found != null)
		return ((IClassFile) found).getType();
	return null;
}
public IJavaElement getJavaElement(String qualifiedName) {
	try {
		if (getSourceProject() != null)
			return getSourceProject().findElement(getPathFromQualifiedName(qualifiedName));
	} catch (JavaModelException jme) {
		System.out.println(ResourceHandler.getString("Error_Looking_Up_Type_ERROR_", (new Object[] {qualifiedName, jme.getMessage()}))); //$NON-NLS-1$ = "Error looking up type: "
	}
	return null;
}
protected IPath getPathFromQualifiedName(String qualifiedName) {
	return new Path(qualifiedName.replace('.', File.separatorChar) + ".java");//$NON-NLS-1$
}
protected IJavaProject getSourceProject() {
	//return (IJavaProject) ((JavaRefPackage)EPackage.Registry.INSTANCE.getEPackage(JavaRefPackage.eNS_URI)).getJavaRefFactory().getJavaContext();
	return null;
}
public IType getType(String qualifiedName) {
		IJavaElement found = getJavaElement(qualifiedName);
		if (found != null)
			if (found instanceof IClassFile)
				return ((IClassFile) found).getType();
			else
				if (found instanceof ICompilationUnit) {
					ICompilationUnit foundCU = (ICompilationUnit) found;
					// strip the ".java", lifted from CompilationUnit.getMainTypeName()
					String cuMainTypeName = foundCU.getElementName();
					cuMainTypeName = cuMainTypeName.substring(0, cuMainTypeName.length() - 5);
					return foundCU.getType(cuMainTypeName);
				}
	return null;
}
/**
 * Insert the method's description here.
 * Creation date: (8/16/2000 11:19:48 PM)
 * @return com.ibm.etools.java.adapters.JDOMClassFinder
 */
public static JDOMClassFinder instance() {
	if (instance == null)
		instance = new JDOMClassFinder();
	return instance;
}
}

Back to the top