Author: scabanovich
Date: 2010-12-29 07:17:58 -0500 (Wed, 29 Dec 2010)
New Revision: 27792
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseJavaUtil.java
Log:
JBIDE-8011
https://issues.jboss.org/browse/JBIDE-8011
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseJavaUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseJavaUtil.java 2010-12-29
12:16:36 UTC (rev 27791)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseJavaUtil.java 2010-12-29
12:17:58 UTC (rev 27792)
@@ -12,169 +12,18 @@
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jdt.core.IAnnotatable;
-import org.eclipse.jdt.core.IAnnotation;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IField;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IMember;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IPackageFragment;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeHierarchy;
import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.Signature;
-import org.jboss.tools.common.model.plugin.ModelPlugin;
-public class EclipseJavaUtil {
+public class EclipseJavaUtil extends org.jboss.tools.common.util.EclipseJavaUtil {
- public static String getMemberTypeAsString(IMember member) {
- if(member instanceof IField) return getMemberTypeAsString((IField)member);
- if(member instanceof IMethod) return getMemberTypeAsString((IMethod)member);
- return null;
- }
-
- public static String getMemberTypeAsString(IField f) {
- if(f == null) return null;
- try {
- String typeName = new
String(Signature.toCharArray(f.getTypeSignature().toCharArray()));
- return resolveType(f.getDeclaringType(), typeName);
- } catch (JavaModelException e) {
- ModelPlugin.getPluginLog().logError(e);
- }
- return null;
- }
-
- public static String getMemberTypeAsString(IMethod m) {
- if(m == null) return null;
- try {
- return resolveTypeAsString(m.getDeclaringType(), m.getReturnType());
- } catch (JavaModelException e) {
- ModelPlugin.getPluginLog().logError(e);
- }
- return null;
- }
-
- public static String resolveTypeAsString(IType type, String typeName) {
- if(type == null || typeName == null) return null;
- typeName = new String(Signature.toCharArray(typeName.toCharArray()));
- return resolveType(type, typeName);
- }
-
- static String NULL = ";;;"; //$NON-NLS-1$
-
- static class Resolved {
- IType type;
- Map<String, String> types = new HashMap<String, String>();
- Resolved(IType type) {
- this.type = type;
- }
-
- void setType(IType type) {
- this.type = type;
- types.clear();
- }
- }
-
- static Map<String,Resolved> resolved = new HashMap<String, Resolved>();
-
- static String getKey(IType type) {
- String n = type.getFullyQualifiedName();
- IJavaProject jp = type.getJavaProject();
- if(jp == null) return n;
- IProject p = jp.getProject();
- if(p == null || !p.isAccessible()) return n;
- return p.getName() + ":" + n; //$NON-NLS-1$
- }
- public static String resolveType(IType type, String typeName) {
- if(type == null) return null;
- if(type.isBinary() || typeName == null) return typeName;
- int i = typeName.indexOf("<");
- if(i >= 0) {
- int j = typeName.lastIndexOf(">");
- if(j >= i) {
-// typeName = typeName.substring(0, i);
- }
- }
-
- String n = getKey(type);
- Resolved r = resolved.get(n);
- if(r == null) {
- r = new Resolved(type);
- resolved.put(n, r);
-// if(resolved.size() % 100 == 0) {
-// System.out.println("-->" + resolved.size() + " " + n);
//$NON-NLS-1$ //$NON-NLS-2$
-// }
- }
- if(r.type != type) {
- r.setType(type);
- }
-
- String result = r.types.get(typeName);
-
- if(result != null) {
- return (result == NULL) ? null : result;
- }
-
- result = __resolveType(type, typeName);
-
- String nresult = result == null ? NULL : result;
-
- r.types.put(typeName, nresult);
-
-// System.out.println(n + " " + typeName);
-
- return result;
-
- }
-
- private static String __resolveType(IType type, String typeName) {
- if(type == null || typeName == null) return null;
- try {
- String resolvedArray[][] = type.resolveType(typeName);
-// resolvedArray == null for primitive types
- if(resolvedArray == null) return typeName;
- typeName = ""; //$NON-NLS-1$
- for (int i = 0; i < resolvedArray[0].length; i++)
- typeName += (!"".equals(typeName) ? "." : "") +
resolvedArray[0][i]; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- return typeName;
- } catch (JavaModelException e) {
- ModelPlugin.getPluginLog().logError(e);
- } catch (IllegalArgumentException ee) {
- System.out.println("Illegal " + typeName);
- }
- return null;
- }
-
- public static IType findType(IJavaProject javaProject, String qualifiedName) throws
JavaModelException {
- if(qualifiedName == null || qualifiedName.length() == 0) return null;
- IType type = javaProject.findType(qualifiedName);
- if(type != null) return type;
- int dot = qualifiedName.lastIndexOf('.');
- String packageName = (dot < 0) ? "" : qualifiedName.substring(0, dot);
//$NON-NLS-1$
- String shortName = qualifiedName.substring(dot + 1);
- IPackageFragmentRoot[] rs = javaProject.getPackageFragmentRoots();
- for (int i = 0; i < rs.length; i++) {
- IPackageFragment f = rs[i].getPackageFragment(packageName);
- if(f == null || !f.exists()) continue;
- ICompilationUnit[] us = f.getCompilationUnits();
- for (int j = 0; j < us.length; j++) {
- IType t = us[j].getType(shortName);
- if(t != null && t.exists()) return t;
- }
- }
- return null;
- }
-
public static boolean isDerivedClass(String type, String superType, IProject project) {
if(type == null) return false;
if(superType == null || superType.equals("java.lang.Object")) return true;
//$NON-NLS-1$
@@ -224,28 +73,4 @@
return suppers;
}
- public static IAnnotation findAnnotation(IType sourceType, IAnnotatable member, String
qulifiedAnnotationName) throws JavaModelException{
- IAnnotation[] annotations = member.getAnnotations();
- String simpleAnnotationTypeName = qulifiedAnnotationName;
- int lastDot = qulifiedAnnotationName.lastIndexOf('.');
- if(lastDot>-1) {
- simpleAnnotationTypeName = simpleAnnotationTypeName.substring(lastDot + 1);
- }
- for (IAnnotation annotation : annotations) {
- if(qulifiedAnnotationName.equals(annotation.getElementName())) {
- return annotation;
- }
- if(simpleAnnotationTypeName.equals(annotation.getElementName())) {
- String fullAnnotationclassName = EclipseJavaUtil.resolveType(sourceType,
simpleAnnotationTypeName);
- if(fullAnnotationclassName!=null) {
- IType annotationType =
sourceType.getJavaProject().findType(fullAnnotationclassName);
- if(annotationType!=null &&
annotationType.getFullyQualifiedName().equals(qulifiedAnnotationName)) {
- return annotation;
- }
- }
- }
- }
- return null;
- }
-
}
\ No newline at end of file