Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters')
-rw-r--r--plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JDOMAdaptor.java351
-rw-r--r--plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JDOMClassFinder.java94
-rw-r--r--plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JDOMSearchHelper.java370
-rw-r--r--plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaClassJDOMAdaptor.java703
-rw-r--r--plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaFieldJDOMAdaptor.java291
-rw-r--r--plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaJDOMAdapterFactory.java233
-rw-r--r--plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaMethodJDOMAdaptor.java364
-rw-r--r--plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaModelListener.java44
-rw-r--r--plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaReflectionSynchronizer.java349
9 files changed, 0 insertions, 2799 deletions
diff --git a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JDOMAdaptor.java b/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JDOMAdaptor.java
deleted file mode 100644
index 372b8399a..000000000
--- a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JDOMAdaptor.java
+++ /dev/null
@@ -1,351 +0,0 @@
-/*******************************************************************************
- * 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;
-/*
- * $RCSfile: JDOMAdaptor.java,v $
- * $Revision: 1.8 $ $Date: 2005/10/18 14:58:18 $
- */
-
-import java.io.File;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.xmi.XMIResource;
-import org.eclipse.jdt.core.*;
-import org.eclipse.jem.java.*;
-import org.eclipse.jem.internal.java.adapters.JavaReflectionAdaptor;
-import org.eclipse.jem.internal.java.adapters.nls.ResourceHandler;
-import org.eclipse.jem.java.internal.impl.JavaRefFactoryImpl;
-/**
- * Insert the type's description here.
- * Creation date: (6/6/2000 4:42:50 PM)
- * @author: Administrator
- */
-public abstract class JDOMAdaptor extends JavaReflectionAdaptor {
-
- protected final static JavaRefPackage JAVA_PACK = JavaRefFactoryImpl.getPackage();
- protected IJavaProject sourceProject;
- final public static int INVALID_LINENO = -1;
- final protected Integer fLINENOLock = new Integer(INVALID_LINENO);
- // This object is not static, as it is used as synchronization element.
- private int fResolvedLineNo = INVALID_LINENO; // Line offset in source file
- private int fResolvedColNo = INVALID_LINENO; // Column offset in source file
- public JDOMAdaptor(Notifier target, IJavaProject workingProject) {
- super(target);
- setSourceProject(workingProject);
- }
- protected void clearSource() {
- // To be overidden if needed.
- }
-
- /**
- * Called by subclasses in canReflect(). If the target is not in a resource, or the
- * resource is not loaded, then it can't reflect. Mustn't reflect if the target
- * has been unloaded.
- *
- * @return
- */
- protected boolean isResourceLoaded() {
- Resource res = ((EObject) getTarget()).eResource();
- return res != null && res.isLoaded();
- }
-
- /**
- * Scan for CRs and LFs within a character buffer
- * Creation date: (8/17/2001 2:14:13 PM)
- * @return int LineNo at charOffset
- * @param charOffset int
- * @param buffer org.eclipse.jdt.core.IBuffer
- */
- private void computeLineOffset(int charOffset, IBuffer buffer) {
-
- fResolvedColNo = fResolvedLineNo = INVALID_LINENO;
-
- if (buffer == null)
- return;
-
- char[] charBuff = buffer.getCharacters();
-
- if (charBuff == null)
- return;
-
- int LineCount = 0;
- int ColNo = 0;
- for (int i = 0; i <= charOffset; i++) {
- ColNo++;
- if (charBuff[i] == '\r') {
- LineCount++;
- ColNo = 0;
- if (charBuff[i + 1] == '\n')
- i++; // skip LineFeed followed a CR
- } else if (charBuff[i] == '\n') {
- LineCount++;
- ColNo = 0;
- }
-
- }
- fResolvedColNo = ColNo;
- fResolvedLineNo = LineCount;
- }
- /**
- * computeMethodID - generate the unique ID to be used to identify a method.
- * Similar to a Signature, but hopefully more readable.
- * The name format will be:
- * simpleTypeName.methodName(my.package.Parm_Type1,parmType2
- * Note: This implementation is tightly coupled with ReflectionAdapter.getTypeNamesFromMethodID().
- */
- public static String computeMethodID(IMethod jdomMethod) {
- return computeMethodID(jdomMethod, jdomMethod.getDeclaringType(), null);
- }
- /**
- * computeMethodID - generate the unique ID to be used to identify a method.
- * Similar to a Signature, but hopefully more readable.
- * The name format will be:
- * simpleTypeName.methodName(my.package.Parm_Type1,parmType2
- * Note: This implementation is tightly coupled with ReflectionAdapter.getTypeNamesFromMethodID().
- */
- public static String computeMethodID(IMethod jdomMethod, IType type, Map typeCache) {
- StringBuffer out = new StringBuffer();
- out.append(type.getTypeQualifiedName());
- out.append(C_CLASS_MEMBER_DELIMITER);
- out.append(jdomMethod.getElementName());
- out.append(C_METHOD_PARM_DELIMITER);
- String[] parmTypeNames = jdomMethod.getParameterTypes();
- String parmName;
- for (int i = 0; i < parmTypeNames.length; i++) {
- parmName = convertJDOMtypeName(parmTypeNames[i]);
- parmName = JDOMSearchHelper.getResolvedTypeName(parmName, type, typeCache);
- out.append(parmName);
- if (i < (parmTypeNames.length - 1))
- out.append(C_PARM_PARM_DELIMITER);
- }
- try {
- if (jdomMethod.isConstructor())
- out.append(S_CONSTRUCTOR_TOKEN);
- } catch (JavaModelException e) {
- }
- return out.toString();
- }
- /**
- * computeMethodName - generate the name to be used to identify a method.
- * For the moment, names are simple, and UUID's are complex.
- */
- public static String computeMethodName(IMethod jdomMethod) {
- return jdomMethod.getElementName();
- }
- /**
- * Java content has changed, but no structural changes that require
- * to reflectValues(); e.g., the body of a method has changed.
- * Creation date: (8/17/2001 10:47:58 AM)
- */
- public void contentChanged() {
- synchronized (fLINENOLock) {
- fResolvedLineNo = INVALID_LINENO;
- fResolvedColNo = INVALID_LINENO;
- }
- }
- /**
- * computeMethodID - generate the unique ID to be used to identify a method.
- * Similar to a Signature, but hopefully more readable.
- * The name format will be:
- * methodName_parmType1_parmType2
- */
- public static String convertJDOMtypeName(String jdomTypeName) {
- return signatureToString(jdomTypeName);
- }
- /**
- * createJavaField - instantiate a Java Field based on the passed Java Model IField
- * We are deferring field contents assuming that its adaptor will reflect its details.
- */
- public Field createJavaField(IField jdomField, XMIResource resource) {
- String name = jdomField.getElementName();
- Field newField = getJavaFactory().createField();
- newField.setName(name);
- resource.setID(newField, ((JavaClass) getTarget()).getName() + C_CLASS_MEMBER_DELIMITER + name);
- return newField;
- }
- /**
- * createJavaMethod - instantiate a Java Method based on the passed Java Model IMethod
- * We are deferring method contents assuming that its adaptor will reflect its details.
- * We need to store enough info in the empty Method to find its Java source.
- * The UUID will eventually hold enough info to identify the source, so we use it.
- */
- public Method createJavaMethod(IMethod jdomMethod, XMIResource resource) {
- Method newMethod = getJavaFactory().createMethod();
- // We use a simple name, but a complex ID
- newMethod.setName(computeMethodName(jdomMethod));
- resource.setID(newMethod, computeMethodID(jdomMethod, getType(), getTypeResolutionCache()));
- return newMethod;
- }
- protected IPath getBinaryPathFromQualifiedName(String qualifiedName) {
- return new Path(qualifiedName.replace('.', File.separatorChar) + ".class"); //$NON-NLS-1$
- }
- public IType getBinaryType(String qualifiedName) {
- try {
- if (getSourceProject() != null) {
- IJavaElement found = getSourceProject().findElement(getBinaryPathFromQualifiedName(qualifiedName));
- if (found != null)
- return ((IClassFile) found).getType();
- }
- } 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;
- }
- /**
- * Compute a column number from the ISourceRange offset
- * Cache the line number thereafter. Source change will
- * Invoke the contentChanged() method.
- * Creation date: (8/17/2001 11:16:51 AM)
- * @return int
- */
- public int getColNo() {
-
- synchronized (fLINENOLock) {
- if (fResolvedColNo == INVALID_LINENO)
- resolveLineColNo();
- }
- return fResolvedColNo;
- }
- /**
- * Compute a line number from the ISourceRange offset
- * Cache the line number thereafter. Source change will
- * Invoke the contentChanged() method.
- * Creation date: (8/17/2001 11:16:51 AM)
- * @return int
- */
- public int getLineNo() {
-
- synchronized (fLINENOLock) {
- if (fResolvedLineNo == INVALID_LINENO)
- resolveLineColNo();
- }
- return fResolvedLineNo;
- }
- /**
- * Insert the method's description here.
- * Creation date: (8/17/2001 1:18:29 PM)
- */
- public abstract Object getReflectionSource();
- /*
- * Resolve a type name in the context of a Type.
- * (Borrowed from org.eclipse.jdt.ui.codemanipulation.StubUtility.getResolvedTypeName())
- * The input is a simple or qualified name, NOT a signature
- * The output will be a qualified name, NOT a signature
- */
- public static String getResolvedTypeName(String typeName, IType declaringType) {
- String name = typeName;
- try {
- name = JDOMSearchHelper.resolveSimpleTypeName(declaringType, typeName);
- } catch (JavaModelException e) {
- // ignore
- }
- return name;
- }
-
- protected IJavaProject getSourceProject() {
- return sourceProject;
- }
- protected abstract IType getType();
- protected abstract Map getTypeResolutionCache();
-
- public void releaseSourceType() {
- flushReflectedValuesIfNecessary(true); // induce clients to get Notified.
- }
-
- public Notification releaseSourceTypeNoNotification() {
- return flushReflectedValuesIfNecessaryNoNotification(true); // induce clients to get Notified.
- }
- /**
- * Insert the method's description here.
- * Creation date: (8/21/2001 8:09:34 AM)
- */
- private void resolveLineColNo() {
-
- IMember rs = (IMember) getReflectionSource();
- if (rs != null) {
- int offset = INVALID_LINENO;
- try {
- ISourceRange sr = rs.getNameRange();
- if (sr.getLength() <= 0)
- return;
- offset = sr.getOffset();
- } catch (JavaModelException je) {
- return;
- }
- ICompilationUnit cu = rs.getCompilationUnit();
- if (cu != null) {
- try {
- IBuffer buffer = cu.getBuffer();
- computeLineOffset(offset, buffer);
- } catch (JavaModelException je) {
- }
- }
- }
- }
- protected void setSourceProject(IJavaProject workingProject) {
- sourceProject = workingProject;
- }
- /**
- * Converts a type signature to a readable string.
- *
- * Uses Signature.toString(), then tries to undo bad replacement for inner classes.
- *
- */
- public static String signatureToString(String signature) throws IllegalArgumentException {
- boolean hasDollar = (signature.indexOf(Signature.C_DOLLAR) != -1);
- String result = Signature.toString(signature);
- if (hasDollar) {
- int newPos = result.lastIndexOf("."); //$NON-NLS-1$
- if (newPos != -1) {
- result = result.substring(0, newPos) + "$" + result.substring(newPos + 1); //$NON-NLS-1$
- }
- }
- return result;
- }
- /**
- * setType - set our type here
- */
- protected String typeNameFromSignature(String sig) {
- return typeNameFromSignature(sig, getType());
- }
- /**
- * setType - set our type here
- */
- protected String typeNameFromSignature(String sig, IType parent) {
- return typeNameFromSignature(sig, parent, getTypeResolutionCache());
- }
- /**
- * setType - set our type here
- */
- public static String typeNameFromSignature(String sig, IType parent, Map typeCache) {
- String result;
- String componentSignature = Signature.getElementType(sig);
- int arrayDimensions = Signature.getArrayCount(sig);
- result = JDOMSearchHelper.getResolvedTypeName(signatureToString(componentSignature), parent, typeCache);
- for (int i = 0; i < arrayDimensions; i++) {
- result = result + "[]"; //$NON-NLS-1$
- }
- return result;
- }
- /**
- * @deprecated
- * @see org.eclipse.jem.internal.adapters.jdom.JDOMSearchHelper#findType(String, boolean, IJavaProject, JDOMAdaptor)
- */
- public IType getType(String qualifiedName) {
- return JDOMSearchHelper.findType(qualifiedName, false, getSourceProject(), this);
- }
-}
diff --git a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JDOMClassFinder.java b/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JDOMClassFinder.java
deleted file mode 100644
index 012f6995a..000000000
--- a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JDOMClassFinder.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*******************************************************************************
- * 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;
-/*
- * $RCSfile: JDOMClassFinder.java,v $
- * $Revision: 1.3 $ $Date: 2005/08/24 21:13:53 $
- */
-
-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) {
- try {
- IJavaElement found = getJavaElement(qualifiedName);
- return ((IClassFile) found).getType();
- } 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;
-}
-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) {
- try {
- 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);
- }
- } 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;
-}
-/**
- * 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;
-}
-}
diff --git a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JDOMSearchHelper.java b/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JDOMSearchHelper.java
deleted file mode 100644
index 7f75aa9ef..000000000
--- a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JDOMSearchHelper.java
+++ /dev/null
@@ -1,370 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 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;
-/*
- * $RCSfile: JDOMSearchHelper.java,v $
- * $Revision: 1.8 $ $Date: 2006/05/17 20:13:58 $
- */
-
-import java.io.File;
-import java.util.*;
-
-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: (9/26/2001 11:09:30 AM)
- * @author: Administrator
- */
-public class JDOMSearchHelper {
-
- private static final String RESOLVED_NAME = " :: RESOLVED_NAME :: "; //$NON-NLS-1$
- private static final String PERIOD = "."; //$NON-NLS-1$
- private static final String BOOLEAN = "boolean"; //$NON-NLS-1$
- private static final String BYTE = "byte"; //$NON-NLS-1$
- private static final String CHAR = "char"; //$NON-NLS-1$
- private static final String SHORT = "short"; //$NON-NLS-1$
- private static final String INT = "int"; //$NON-NLS-1$
- private static final String LONG = "long"; //$NON-NLS-1$
- private static final String FLOAT = "float"; //$NON-NLS-1$
- private static final String DOUBLE = "double"; //$NON-NLS-1$
- private static final String VOID = "void"; //$NON-NLS-1$
- /**
- * JDOMSearchHelper constructor comment.
- */
- public JDOMSearchHelper() {
- super();
- }
- /**
- * If the @simpleName is an inner class, we need to resolve only the declaring class.
- */
- private static String[][] getTypeNameInfo(IType type, String simpleName, boolean isForReflection) throws JavaModelException {
- String[][] result = null;
- String declaringName, typeName;
- typeName = simpleName;
- if (type != null) {
- if (isForReflection)
- typeName = typeName.replace('.', '$');
- int index = typeName.indexOf("$"); //$NON-NLS-1$
- if (index > 0) {
- declaringName = typeName.substring(0, index);
- result = type.resolveType(declaringName);
- if (result != null) {
- if (isForReflection)
- result[0][1] = result[0][1].replace('.', '$');
- result[0][1] += typeName.substring(index, typeName.length());
- }
- } else {
- index = typeName.indexOf("["); //$NON-NLS-1$
- if (index > 0) {
- declaringName = typeName.substring(0, index);
- result = type.resolveType(declaringName);
- if (result != null)
- result[0][1] = result[0][1] + typeName.substring(index);
- } else
- result = type.resolveType(typeName);
- }
- }
- return result;
- }
- /**
- * Returns true if the type is a primitive.
- */
- public final static boolean isPrimitive(String type) {
- return (BOOLEAN.equals(type) || INT.equals(type) || CHAR.equals(type) || SHORT.equals(type) || LONG.equals(type) || FLOAT.equals(type) || DOUBLE.equals(type) || BYTE.equals(type));
- }
- /**
- * Returns true if the type is a primitive.
- */
- public final static boolean isPrimitiveOrVoid(String type) {
- return isPrimitive(type) || isVoid(type);
- }
- /**
- * Returns true if the type is a primitive.
- */
- public final static boolean isVoid(String type) {
- return VOID.equals(type);
- }
- /**
- * Returns true if the two signatures match within the scope of the specified type.
- */
- public static boolean matchTypeSignatures(IType type, String signature1, String signature2) throws JavaModelException {
- return matchTypeSignatures(type, signature1, signature2, null);
- }
- /**
- * Returns true if the two signatures match within the scope of the specified type.
- */
- public static boolean matchTypeSignatures(IType type, String signature1, String signature2, Map resolvedNameCache) throws JavaModelException {
- boolean result = false;
- String sig1 = signature1;
- String sig2 = signature2;
- // First check array count.
- if (Signature.getArrayCount(sig1) == Signature.getArrayCount(sig2)) {
- // We have the same array count, get the element types for consideration.
- sig1 = Signature.getElementType(sig1);
- sig2 = Signature.getElementType(sig2);
-
- // There are three cases:
- // 1) Both are unqualified (both being primitive will fall into this),
- // 2) Both are qualified, and
- // 3) One is qualified and the other is not (one could be primitive).
-
- // For the first two cases a compare of the readable names will always do.
- if (!((sig1.indexOf('.') == -1) ^ (sig2.indexOf('.') == -1))) {
- result = Signature.toString(sig1).equals(Signature.toString(sig2));
- } else {
- // This is case 3.
- // First root out one being primitive.
- if (((sig1.charAt(0) == 'Q') || (sig1.charAt(0) == 'L')) && ((sig2.charAt(0) == 'Q') || (sig2.charAt(0) == 'L'))) {
- // Get the readable name of the qualified signature
- // and the simple name of the other.
- String qualifiedName = null;
- String simpleName = null;
- if (sig1.indexOf('.') == -1) {
- qualifiedName = Signature.toString(sig2);
- simpleName = Signature.toString(sig1);
- } else {
- qualifiedName = Signature.toString(sig1);
- simpleName = Signature.toString(sig2);
- }
-
- // If the simple name resolves to the qualified name, we have a match.
- result = qualifiedName.equals(resolveSimpleTypeName(type, simpleName, resolvedNameCache));
- }
- }
- }
-
- return result;
- }
- private static boolean needsToResolveName(IType type, String simpleName, boolean isForReflection) {
- return !(type.isBinary() || (!isForReflection && simpleName.indexOf(PERIOD) > -1) || isPrimitiveOrVoid(simpleName));
- }
- /**
- * Returns the qualified name for the simple name within the scope of the type.
- * Returns null if the name can not be resolved.
- */
- public static String resolveSimpleTypeName(IType type, String simpleName) throws JavaModelException {
- return resolveSimpleTypeName(type, simpleName, null);
- }
- /**
- * Returns the qualified name for the simple name within the scope of the type.
- * Returns null if the name can not be resolved.
- */
- public static String resolveSimpleTypeName(IType type, String simpleName, Map resolvedNameCache) throws JavaModelException {
- return resolveSimpleTypeName(type, simpleName, resolvedNameCache, false);
- }
-
- /**
- * Returns the qualified name for the simple name within the scope of the type.
- * Returns null if the name can not be resolved.
- */
- public static String resolveSimpleTypeName(IType type, String simpleName, Map resolvedNameCache, boolean isForReflection) throws JavaModelException {
- if (!needsToResolveName(type, simpleName, isForReflection))
- return simpleName;
- String key = null, qualifiedName = null;
- if (resolvedNameCache != null) {
- key = type.getFullyQualifiedName() + RESOLVED_NAME + simpleName;
- qualifiedName = (String) resolvedNameCache.get(key);
- }
- if (qualifiedName == null) {
- String[][] result = getTypeNameInfo(type, simpleName, isForReflection);
- if (result != null) {
- String packName = result[0][0];
- if (packName.length() == 0) {
- qualifiedName = result[0][1];
- if (isForReflection)
- qualifiedName = qualifiedName.replace('.', '$');
- } else {
- StringBuffer b = new StringBuffer();
- b.append(result[0][0]).append(PERIOD);
- String typeName = result[0][1];
- if (isForReflection)
- typeName = typeName.replace('.', '$');
- b.append(typeName);
- qualifiedName = b.toString();
- }
- } else {
- qualifiedName = simpleName;
- }
- if (resolvedNameCache != null)
- resolvedNameCache.put(key, qualifiedName);
- }
- return qualifiedName;
- }
- /**
- * Searches for a matching method and sets it in the
- * descriptor if found.
- */
- public static IMethod searchForMatchingMethod(IType type, String methodName, String[] parmSigs) throws JavaModelException {
- return searchForMatchingMethod(type, methodName, parmSigs, null);
- }
- /**
- * Searches for a matching method and sets it in the
- * descriptor if found.
- */
- public static IMethod searchForMatchingMethod(IType type, String methodName, String[] parmSigs, Map resolvedNameCache) throws JavaModelException {
-
- // First get all the methods by this name and with this many parms.
- IMethod[] allMethods = type.getMethods();
- List candidateMethods = new ArrayList();
- for (int i = 0; i < allMethods.length; i++) {
- int parmSigsLength = (parmSigs != null ? parmSigs.length : 0);
- if ((allMethods[i].getElementName().equals(methodName)) && (allMethods[i].getNumberOfParameters() == parmSigsLength))
- candidateMethods.add(allMethods[i]);
- }
-
- // For each candidate consider each parm for a match.
- // Take the first one that matches on all parms.
- IMethod next = null;
- String[] nextParmSigs = null;
- boolean found = false;
- Iterator candidateIter = candidateMethods.iterator();
- while (!found && (candidateIter.hasNext())) {
- next = (IMethod) candidateIter.next();
- nextParmSigs = next.getParameterTypes();
- found = true;
- for (int i = 0;(found && (i < nextParmSigs.length)); i++)
- found &= matchTypeSignatures(type, parmSigs[i], nextParmSigs[i], resolvedNameCache);
- }
- return found ? next : null;
- }
-
- /**
- * The returned Object[] will contain two entries. The
- * first will be the IJavaElement that was found and the
- * second will be the qualifiedName used to find it.
- */
- protected static Object[] findActualJavaElement(String qualifiedName, IJavaProject javaProject, JDOMAdaptor adaptor) {
- Object[] result = new Object[2];
- if (adaptor == null)
- result[1] = qualifiedName;
- else
- //Ensure the name is qualified
- result[1] = getResolvedTypeName(qualifiedName, adaptor.getType(), adaptor.getTypeResolutionCache());
-
- result[0] = findJavaElement((String) result[1], javaProject, adaptor);
- if (result[0] == null)
- findInnerJavaElement(result, javaProject, adaptor);
- return result;
- }
-
- /**
- * The returned Object[] will contain two entries. The
- * first will be the IJavaElement that was found and the
- * second will be the qualifiedName used to find it.
- */
- protected static void findInnerJavaElement(Object[] info, IJavaProject javaProject, JDOMAdaptor adaptor) {
- String qualifiedName, innerName;
- qualifiedName = (String) info[1];
- int index = qualifiedName.lastIndexOf("."); //$NON-NLS-1$
- if (index > 0) {
- innerName = qualifiedName.substring(0, index);
- innerName += "$"; //$NON-NLS-1$
- innerName += qualifiedName.substring(index + 1, qualifiedName.length());
- if (adaptor != null) {
- //Ensure the name is qualified which it may not be if an inner class
- innerName = getResolvedTypeName(innerName, adaptor.getType(), adaptor.getTypeResolutionCache());
- }
- info[1] = innerName;
- info[0] = findJavaElement(innerName, javaProject, adaptor);
- if (info[0] == null)
- findInnerJavaElement(info, javaProject, adaptor);
- }
- }
-
- protected static IJavaElement findJavaElement(String qualifiedName, IJavaProject javaProject, JDOMAdaptor adaptor) {
- try {
- if (javaProject != null) {
- return javaProject.findType(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 static IPath getPathFromQualifiedName(String qualifiedName) {
- return new Path(qualifiedName.replace('.', File.separatorChar) + ".java"); //$NON-NLS-1$
- }
- /*
- * Resolve a type name in the context of a Type.
- * (Borrowed from org.eclipse.jdt.ui.codemanipulation.StubUtility.getResolvedTypeName())
- * The input is a simple or qualified name, NOT a signature
- * The output will be a qualified name, NOT a signature
- */
- public static String getResolvedTypeName(String typeName, IType declaringType, Map typeCache) {
- String name = typeName;
- try {
- name = JDOMSearchHelper.resolveSimpleTypeName(declaringType, typeName, typeCache, true);
- } catch (JavaModelException e) {
- // ignore
- }
- return name;
- }
-
- public static IType findType(String qualifiedName, boolean useAdvancedForInners, IJavaProject javaProject, JDOMAdaptor adaptor) {
- try {
- IJavaElement found = null;
- String resolvedName = qualifiedName;
- if (useAdvancedForInners) {
- Object[] result = findActualJavaElement(qualifiedName, javaProject, adaptor);
- found = (IJavaElement) result[0];
- resolvedName = (String) result[1];
- } else
- found = findJavaElement(qualifiedName, javaProject, adaptor);
- 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);
- } else if (found instanceof IType) {
- IType type = ((IType) found);
- if (!type.getFullyQualifiedName('$').equals(resolvedName)) {
- // I don't know why this is here. Sometime in the past for an inner class, the
- // IType returned was for the outer class, so you would need to search again
- // for the inner class against the outer class. I don't know how this now can
- // happen. The code followed above is extremelly complicated, especially when
- // it is an inner class that isn't fully-qualified that is inside a source file.
- // It goes through some gyrations for that. I don't know what it would
- // return in that case. But just in case, the test is here to be safe.
- int index = resolvedName.lastIndexOf('$'); //$NON-NLS-1$
- if (index > -1)
- return type.getType(resolvedName.substring(index + 1, resolvedName.length()));
- else
- return type;
- } else
- return type;
- }
- } 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;
- }
-
- public static IType findType(String packageName, String qualifiedTypeName, IJavaProject javaProject) {
- try {
- if (javaProject != null) {
- return javaProject.findType(packageName, qualifiedTypeName.replace('$', '.'));
- }
- } catch (JavaModelException jme) {
- System.out.println(ResourceHandler.getString("Error_Looking_Up_Type_ERROR_", (new Object[] { packageName + "." + qualifiedTypeName, jme.getMessage()}))); //$NON-NLS-1$ //$NON-NLS-2$ = "Error looking up type: "
- }
- return null;
- }
-
-}
diff --git a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaClassJDOMAdaptor.java b/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaClassJDOMAdaptor.java
deleted file mode 100644
index 02ed38108..000000000
--- a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaClassJDOMAdaptor.java
+++ /dev/null
@@ -1,703 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 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;
-/*
- * $RCSfile: JavaClassJDOMAdaptor.java,v $
- * $Revision: 1.25 $ $Date: 2006/05/17 20:13:58 $
- */
-
-import java.util.*;
-import java.util.logging.Level;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.common.util.BasicEList;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.InternalEObject;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.ecore.xmi.XMIResource;
-import org.eclipse.jdt.core.*;
-
-
-import org.eclipse.jem.internal.java.adapters.*;
-import org.eclipse.jem.internal.java.adapters.nls.ResourceHandler;
-import org.eclipse.jem.internal.plugin.JavaPlugin;
-import org.eclipse.jem.java.*;
-import org.eclipse.jem.java.internal.impl.JavaClassImpl;
-import org.eclipse.jem.util.TimerTests;
-import org.eclipse.jem.util.UIContextDetermination;
-import org.eclipse.jem.util.logger.proxy.Logger;
-
-
-public class JavaClassJDOMAdaptor extends JDOMAdaptor implements IJavaClassAdaptor {
- private static final String OBJECT_TYPE_NAME = "java.lang.Object"; //$NON-NLS-1$
-
- /*
- * Step ids used for TimerTests of performance testing.
- */
- public static final String REFLECT_CLASS = "Reflect JDOM Class"; //$NON-NLS-1$
- public static final String REFLECT_METHODS = "Reflect all JDOM methods for a class"; //$NON-NLS-1$
- public static final String REFLECT_FIELDS = "Reflect all JDOM fields for a class"; //$NON-NLS-1$
-
-
- protected IType sourceType = null;
- protected JavaReflectionAdapterFactory adapterFactory;
- private Map typeResolutionCache = new HashMap(25);
- private boolean hasReflectedFields, isReflectingFields;
- private boolean hasReflectedMethods, isReflectingMethods;
-
- public JavaClassJDOMAdaptor(Notifier target, IJavaProject workingProject, JavaReflectionAdapterFactory inFactory) {
- super(target, workingProject);
- setAdapterFactory(inFactory);
- }
-
- private Map existingFields = new HashMap();
- /*
- * addFields - reflect our fields
- */
- protected boolean addFields() {
-
- // The algorithm we will use is:
- // 1) Pass through the IField's of this class
- // a) If it is in existingFields, then add to newExisting the entry from
- // oldExisting (deleting from oldExisting at the same time), and flush the field. This is so next we re-get any changed parts of it.
- // b) else not existing, then create new field and add to the new fields list.
- // 2) Remove from the fields list any still left in oldExisting. These are ones that no longer exist.
- // 3) Add all of the news ones to the fields.
- //
- IField[] fields = null;
- try {
- fields = getSourceType().getFields();
- } catch (JavaModelException e) {
- Logger.getLogger().log(e, Level.WARNING);
- return false;
- }
- XMIResource resource = (XMIResource) getJavaClassTarget().eResource();
- Field field = null;
- JavaFieldJDOMAdaptor adapter = null;
- Map newExisting = new HashMap(fields.length);
- List newFields = new ArrayList();
- for (int i = 0; i < fields.length; i++) {
- IField ifield = fields[i];
- field = (Field) existingFields.remove(ifield); // Get the existing field (which is the value) from the collection keyed by IField.
- if (field != null) {
- // It is an existing method. So just put over to newExisting. Then flush it.
- newExisting.put(ifield, field);
- // Since this is a new method, it is not attached to a resource, so we need to explicitly create the adapter.
- adapter = (JavaFieldJDOMAdaptor) EcoreUtil.getExistingAdapter(field, ReadAdaptor.TYPE_KEY);
- if (adapter == null)
- adapter = (JavaFieldJDOMAdaptor) getAdapterFactory().adaptNew(field, ReadAdaptor.TYPE_KEY);
- else
- adapter.flushReflectedValuesIfNecessaryNoNotification(true);
- adapter.setSourceField(ifield); // Give it this new IField
- } else {
- // It is a new method. Create the new method, add to newExisting, and add to newMethods list.
- field = createJavaField(ifield, resource);
- newExisting.put(ifield, field);
- newFields.add(field);
- adapter = (JavaFieldJDOMAdaptor) getAdapterFactory().adaptNew(field, ReadAdaptor.TYPE_KEY);
- if (adapter != null)
- adapter.setSourceField(ifield);
- }
- }
-
- BasicEList fieldsList = (BasicEList) getJavaClassTarget().getFieldsGen();
- if (!existingFields.isEmpty()) {
- // Now any still left in old existing are deleted. So we make them proxies and then remove them from fields list.
- URI baseURI = resource.getURI();
- Collection toDelete = existingFields.values();
- for (Iterator itr = toDelete.iterator(); itr.hasNext();) {
- InternalEObject m = (InternalEObject) itr.next();
- String id = resource.getID(m);
- if (id != null)
- m.eSetProxyURI(baseURI.appendFragment(id));
- }
- fieldsList.removeAll(toDelete);
- }
-
- if (!newFields.isEmpty()) {
- // Now add in the news ones
- fieldsList.addAllUnique(newFields);
- }
-
- // Finally set current existing to the new map we created.
- existingFields = newExisting;
- return true;
- }
-
- private Map existingMethods = new HashMap();
- /*
- * addMethods - reflect our methods. Merge in with the previous.
- */
- protected boolean addMethods() {
- // The algorithm we will use is:
- // 1) Pass through the IMethod's of this class
- // a) If it is in existingMethods, then add to newExisting the entry from
- // oldExisting (deleting from oldExisting at the same time), and flush the method. This is so next we re-get any changed parts of it.
- // b) else not existing, then create new method and add to the new methods list.
- // 2) Remove from the methods list any still left in oldExisting. These are ones that no longer exist.
- // 3) Add all of the news ones to the methods.
- //
- IMethod[] methods = null;
- try {
- methods = getSourceType().getMethods();
- } catch (JavaModelException e) {
- Logger.getLogger().log(e, Level.WARNING);
- return false;
- }
- XMIResource resource = (XMIResource) getJavaClassTarget().eResource();
- Method method = null;
- JavaMethodJDOMAdaptor adapter = null;
- Map newExisting = new HashMap(methods.length);
- List newMethods = new ArrayList();
- for (int i = 0; i < methods.length; i++) {
- IMethod im = methods[i];
- method = (Method) existingMethods.remove(im); // Get the existing method (which is the value) from the collection keyed by IMethod.
- if (method != null) {
- // It is an existing method. So just put over to newExisting. Then flush it.
- newExisting.put(im, method);
- adapter = (JavaMethodJDOMAdaptor) retrieveAdaptorFrom(method);
- if (adapter != null) {
- adapter.flushReflectedValuesIfNecessaryNoNotification(true);
- adapter.setSourceMethod(im); // Give it this new IMethod
- }
- } else {
- // It is a new method. Create the new method, add to newExisting, and add to newMethods list.
- method = createJavaMethod(im, resource);
- newExisting.put(im, method);
- newMethods.add(method);
- // Since this is a new method, it is not attached to a resource, so we need to explicitly create the adapter.
- adapter = (JavaMethodJDOMAdaptor) getAdapterFactory().adaptNew(method, ReadAdaptor.TYPE_KEY);
- if (adapter != null)
- adapter.setSourceMethod(methods[i]);
- }
- }
-
- BasicEList methodsList = (BasicEList) getJavaClassTarget().getMethodsGen();
- if (!existingMethods.isEmpty()) {
- // Now any still left in old existing are deleted. So we make them proxies and then remove them from methods list.
- URI baseURI = resource.getURI();
- Collection toDelete = existingMethods.values();
- for (Iterator itr = toDelete.iterator(); itr.hasNext();) {
- InternalEObject m = (InternalEObject) itr.next();
- String id = resource.getID(m);
- if (id != null)
- m.eSetProxyURI(baseURI.appendFragment(id));
- }
- methodsList.removeAll(toDelete);
- }
-
- if (!newMethods.isEmpty()) {
- // Now add in the news ones
- methodsList.addAllUnique(newMethods);
- }
-
- // Finally set current existing to the new map we created.
- existingMethods = newExisting;
- return true;
- }
- /**
- * Clear source Type ;
- */
- protected void clearSource() {
- sourceType = null;
- }
-
- /**
- * Clear the reflected fields list.
- */
- protected boolean flushFields() {
- // First turn them all into proxies so that any holders will re-resolve to maybe the new one if class comes back.
- existingFields.clear();
- XMIResource res = (XMIResource) getJavaClassTarget().eResource();
- URI baseURI = res.getURI();
- List fields = getJavaClassTarget().getFieldsGen();
- int msize = fields.size();
- for (int i = 0; i < msize; i++) {
- InternalEObject f = (InternalEObject) fields.get(i);
- String id = res.getID(f);
- if (id != null)
- f.eSetProxyURI(baseURI.appendFragment(id));
- }
- fields.clear(); // Now we can clear it.
- return true;
- }
- /**
- * Clear the implements list.
- */
- protected boolean flushImplements() {
- getJavaClassTarget().getImplementsInterfacesGen().clear();
- return true;
- }
- /**
- * Clear the reflected methods list.
- */
- protected boolean flushMethods() {
- // First turn them all into proxies so that any holders will re-resolve to maybe the new one if class comes back.
- existingMethods.clear();
- XMIResource res = (XMIResource) getJavaClassTarget().eResource();
- URI baseURI = res.getURI();
- List methods = getJavaClassTarget().getMethodsGen();
- int msize = methods.size();
- for (int i = 0; i < msize; i++) {
- InternalEObject m = (InternalEObject) methods.get(i);
- String id = res.getID(m);
- if (id != null)
- m.eSetProxyURI(baseURI.appendFragment(id));
- }
- methods.clear(); // Now we can clear it.
- return true;
- }
- protected boolean flushModifiers() {
- JavaClass javaClassTarget = (JavaClass) getTarget();
- javaClassTarget.setAbstract(false);
- javaClassTarget.setFinal(false);
- javaClassTarget.setPublic(false);
- javaClassTarget.setKind(TypeKind.UNDEFINED_LITERAL);
- return true;
- }
- protected boolean flushInnerClasses() {
- getJavaClassTarget().getDeclaredClassesGen().clear();
- return true;
- }
-
- protected boolean flushAndClearCachedModelObject;
-
- /**
- * Clear the reflected values.
- */
- protected boolean flushReflectedValues(boolean clearCachedModelObject) {
- flushAndClearCachedModelObject = clearCachedModelObject;
- return true;
- }
-
- /*
- * This is called before a reflect if a real flush is needed.
- */
- private void flushNow() {
- if (flushAndClearCachedModelObject)
- setSourceType(null);
- typeResolutionCache.clear();
- flushModifiers();
- flushSuper();
- flushImplements();
- if (flushAndClearCachedModelObject) {
- // Don't flush these yet. We will try to reuse them on the next reflush. If clear model too, then flush them. This usually means class has been deleted, so why keep them around.
- flushMethods();
- flushFields();
- }
- // Even if we didn't flush the fields/methods, we do need to mark as not reflected so on next usage we will merge in the changes.
- hasReflectedMethods = false;
- hasReflectedFields = false;
-
- flushInnerClasses();
- flushAndClearCachedModelObject = false;
- }
-
-
- /**
- * @see com.ibm.etools.java.adapters.JavaReflectionAdaptor#postFlushReflectedValuesIfNecessary()
- */
- protected void postFlushReflectedValuesIfNecessary(boolean isExisting) {
- getJavaClassTarget().setReflected(false);
- super.postFlushReflectedValuesIfNecessary(isExisting);
- }
-
- /**
- * Set the supertype to be null.
- */
- protected boolean flushSuper() {
- List targetSupers = getJavaClassTarget().primGetESuperTypes();
- targetSupers.clear();
- return true;
- }
- protected JavaReflectionAdapterFactory getAdapterFactory() {
- return adapterFactory;
- }
- /**
- * getBinaryType - return the IType which describes our existing Java class file
- */
- protected IType getBinaryType() {
- return this.getBinaryType(((JavaClass) getTarget()).getQualifiedName());
- }
- /**
- * Return the target typed to a JavaClass.
- */
- protected JavaClassImpl getJavaClassTarget() {
- return (JavaClassImpl) getTarget();
- }
- public Object getReflectionSource() {
- return getSourceType();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jem.internal.java.adapters.JavaReflectionAdaptor#hasReflectionSource()
- */
- public boolean hasCachedReflectionSource() {
- return sourceType != null;
- }
- /**
- * getSourceType - return the IType which describes our existing Java class or source file
- */
- public IType getSourceType() {
- if (sourceType == null) {
- JavaClassImpl javaClass = (JavaClassImpl) getTarget();
- sourceType = JDOMSearchHelper.findType(javaClass.getJavaPackage().getName(), javaClass.primGetName(), getSourceProject());
- }
- return sourceType;
- }
- /**
- * getSourceType - return the IType which describes our existing Java class or source file
- */
- protected IType getType() {
- return getSourceType();
- }
- protected Map getTypeResolutionCache() {
- return typeResolutionCache;
- }
- /**
- * getValueIn method comment.
- */
- public Object getValueIn(EObject object, EObject attribute) {
- // At this point, this adapter does not dynamically compute any values,
- // all values are pushed back into the target on the initial call.
- return super.getValueIn(object, attribute);
- }
- /**
- * Return true if the sourceType is null or if
- * it is a binary type.
- */
- public boolean isSourceTypeFromBinary() {
- if (getSourceType() == null)
- return false; //must be new?
- return getSourceType().isBinary();
- }
-
-
- protected JavaClass reflectJavaClass(String qualifiedName) {
- IType type = JDOMSearchHelper.findType(qualifiedName, true, getSourceProject(), this);
- if (type != null)
- return reflectJavaClass(type);
- else
- return createJavaClassRef(qualifiedName);
- }
- protected JavaClass reflectJavaClass(IType aType) {
- if (aType != null) {
- JavaClass javaClass = (JavaClass) JavaRefFactory.eINSTANCE.reflectType(aType.getFullyQualifiedName(), (EObject) getTarget());
- if (javaClass != null) {
- JavaClassJDOMAdaptor adaptor = (JavaClassJDOMAdaptor) EcoreUtil.getAdapter(javaClass.eAdapters(), ReadAdaptor.TYPE_KEY);
- if (adaptor != null)
- adaptor.setSourceType(aType);
- }
- return javaClass;
- }
- return null;
- }
- /**
- * reflectValues - template method, subclasses override to pump values into target.
- * on entry: name, containing package (and qualified name), and document must be set.
- * Return true always and the JavaReflectionSynchronizer will flush with the type can
- * be found again. In headless mode, return true only if the type is found. This is
- * needed becauce most headless tasks are done under one operation and the JavaReflectionSynchronizer
- * may not have a chance to flush a bad reflection before the real type needs to be found and can be found.
- * JavaClass adaptor:
- * - set modifiers
- * - set name
- * - set reference to super
- * - create methods
- * - create fields
- * - add imports
- */
- public boolean reflectValues() {
- if (hasFlushed) {
- // We flush sometime in the past since last reflect. So now do the actual flush.
- flushNow();
- }
- super.reflectValues();
- boolean isHeadless = UIContextDetermination.getCurrentContext() == UIContextDetermination.HEADLESS_CONTEXT;
- if (canReflect()) {
- TimerTests.basicTest.startCumulativeStep(REFLECT_CLASS);
- try {
- ICompilationUnit cu = getSourceType().getCompilationUnit();
- boolean isWC = cu != null ? cu.isWorkingCopy() : false;
- IResource res = isWC ? getSourceType().getResource() : null;
- // We are only interested in physical classes. If still just in working copy and not yet put out to
- // disk, we don't should treat as not exist. Anything else is considered existing because we got past
- // getSourceType.exists. This will return the truth for non-wc. But for wc types it will return true,
- // even though not physically on disk (such as just creating it and hadn't saved it yet). So for wc types
- // we need to test the actual resource.
- // Test is OK if not wc, or if wc, then there is a res. and it is accessible.
- if (!isWC || (res != null && res.isAccessible())) {
- setModifiers();
- setNaming();
- try {
- setSuper();
- } catch (InheritanceCycleException e) {
- JavaPlugin.getDefault().getLogger().log(e);
- }
- setImplements();
- reflectInnerClasses();
- setDeclaringClass();
- //addImports();
- if (isHeadless) {
- registerWithFactory();
- return true;
- }
- }
- } finally {
- TimerTests.basicTest.stopCumulativeStep(REFLECT_CLASS);
- }
- }
- if (isHeadless)
- return false;
- else {
- registerWithFactory();
- return true;
- }
- }
-
- protected void setDeclaringClass() {
- IType declaringType = getSourceType().getDeclaringType();
- if (declaringType != null) {
- // Need to get it and reflect it so that the declared type of this target is set correctly. We can just
- // set it ourselves directly because ECore would try to add it to the list of inner classes of the declaring type. This
- // would cause it to be added twice, once from the reflection caused by the inverse setting, and once from our doing
- // the inverse setting itself.
- ResourceSet set = getTargetResource().getResourceSet();
- String packageName = declaringType.getPackageFragment().getElementName();
- JavaClassImpl declaringClass = (JavaClassImpl) JavaRefFactory.eINSTANCE.reflectType(packageName, declaringType.getTypeQualifiedName(), set);
- declaringClass.getDeclaredClasses(); // This will cause it to put us into its list and also set our declaring class to this declaring type.
- }
- }
-
-
- /**
- * @return
- */
- private boolean canReflect() {
- return isResourceLoaded() && getSourceProject() != null && getSourceType() != null && getSourceType().exists();
- }
- public synchronized boolean reflectFieldsIfNecessary() {
- if (reflectValuesIfNecessary() && canReflect()) {
- if (!hasReflectedFields && !isReflectingFields) {
- isReflectingFields = true;
- try {
- TimerTests.basicTest.startCumulativeStep(REFLECT_FIELDS);
- addFields();
- hasReflectedFields = true;
- } catch (Throwable e) {
- hasReflectedFields = false;
- Logger logger = Logger.getLogger();
- if (logger.isLoggingLevel(Level.WARNING)) {
- logger.log(ResourceHandler.getString("Failed_reflecting_values_ERROR_"), Level.WARNING); //$NON-NLS-1$ = "Failed reflecting values!!!"
- logger.logWarning(e);
- }
- } finally {
- isReflectingFields = false;
- TimerTests.basicTest.stopCumulativeStep(REFLECT_FIELDS);
- }
- }
- return hasReflectedFields;
- } else
- return false; // Couldn't reflect the base values, so couldn't do fields either
- }
- public synchronized boolean reflectMethodsIfNecessary() {
- if (reflectValuesIfNecessary() && canReflect()) {
- if (!hasReflectedMethods && !isReflectingMethods) {
- isReflectingMethods = true;
- try {
- TimerTests.basicTest.startCumulativeStep(REFLECT_METHODS);
- hasReflectedMethods = addMethods();
- } catch (Throwable e) {
- hasReflectedMethods = false;
- Logger logger = Logger.getLogger();
- if (logger.isLoggingLevel(Level.WARNING)) {
- logger.log(ResourceHandler.getString("Failed_reflecting_values_ERROR_"), Level.WARNING); //$NON-NLS-1$ = "Failed reflecting values!!!"
- logger.logWarning(e);
- }
- } finally {
- isReflectingMethods = false;
- if (!hasReflected)
- flushMethods(); // Something bad happened, so we will do a complete flush to be on safe side.
- TimerTests.basicTest.stopCumulativeStep(REFLECT_METHODS);
- }
- }
- return hasReflectedMethods;
- } else
- return false; // Couldn't reflect the base values, so couldn't do fields either
- }
-
- private void registerWithFactory() {
- getAdapterFactory().registerReflection(getJavaClassTarget().getQualifiedNameForReflection(), this);
- }
-
- /**
- * @see com.ibm.etools.java.adapters.ReflectionAdaptor#notifyChanged(new ENotificationImpl((InternalEObject)Notifier, int,(EStructuralFeature) EObject, Object, Object, int))
- */
- public void notifyChanged(Notification notification) {
- if (notification.getEventType() == Notification.REMOVING_ADAPTER
- && notification.getOldValue() == this
- && notification.getNotifier() == getTarget())
- getAdapterFactory().unregisterReflection(getJavaClassTarget().getQualifiedNameForReflection());
-
- }
-
- protected void setAdapterFactory(JavaReflectionAdapterFactory inFactory) {
- adapterFactory = inFactory;
- }
- /**
- * setImplements - set our implemented/super interfaces here
- * For an interface, these are superclasses.
- * For a class, these are implemented interfaces.
- */
- protected void setImplements() {
- try {
- String[] interfaceNames = getSourceType().getSuperInterfaceNames();
- JavaClass ref;
- // needs work, the names above will be simple names if we are relfecting from a source file
- List list = getJavaClassTarget().getImplementsInterfacesGen();
- for (int i = 0; i < interfaceNames.length; i++) {
- ref = reflectJavaClass(interfaceNames[i]);
- list.add(ref);
- }
- } catch (JavaModelException npe) {
- // name stays null and we carry on
- }
- }
- /**
- * setModifiers - set the attribute values related to modifiers here
- */
- protected void setModifiers() {
- JavaClass javaClassTarget = (JavaClass) getTarget();
- try {
- javaClassTarget.setAbstract(Flags.isAbstract(getSourceType().getFlags()));
- javaClassTarget.setFinal(Flags.isFinal(getSourceType().getFlags()));
- javaClassTarget.setPublic(Flags.isPublic(getSourceType().getFlags()));
- // Set type to class or interface, not yet handling EXCEPTION
- if (getSourceType().isClass())
- javaClassTarget.setKind(TypeKind.CLASS_LITERAL);
- else
- javaClassTarget.setKind(TypeKind.INTERFACE_LITERAL);
- } catch (JavaModelException npe) {
- Logger logger = JavaPlugin.getDefault().getLogger();
- if (logger.isLoggingLevel(Level.WARNING))
- logger.log(ResourceHandler.getString("Error_Introspecting_Flags_ERROR_", new Object[] { javaClassTarget.getQualifiedName(), npe.getMessage()}), Level.WARNING); //$NON-NLS-1$ = "error introspecting flags on {0}"
- }
- }
- /**
- * setNaming - set the naming values here
- * - qualified name (package name + name) must be set first, that is the path to the real Java class
- * - ID - simple name, identity within a package document
- * - null UUID
- */
- protected void setNaming() {
- /* Naming has been provided by the JavaReflectionKey
- JavaClass javaClassTarget = (JavaClass) getTarget();
- String packageName = getSourceType().getPackageFragment().getElementName();
- javaClassTarget.refSetUUID((String)null);
- ((XMIResource)javaClassTarget.eResource()).setID(javaClassTarget,getSourceType().getElementName());
- */
- }
- protected void setSourceType(IType aType) {
- sourceType = aType;
- }
- /**
- * setSuper - set our supertype here, implemented interface are handled separately
- */
- protected void setSuper() throws InheritanceCycleException {
- String superName = null;
- IType superType = null;
- try {
- if (!getSourceType().isInterface()) {
- superName = getSourceType().getSuperclassName();
- // binary types will always have fully-qualified super names, so no need to do any searching.
- if (!getSourceType().isBinary() && superName != null && isTargetInner()) {
- IType declaringType = getSourceType().getDeclaringType();
- if (declaringType != null) {
- //Get all parent InnerTypes
- IType[] inners = declaringType.getTypes();
- for (int i = 0; i < inners.length; i++) {
- IType type = inners[i];
- if (superName.equals(type.getElementName())) {
- superName = declaringType.getElementName() + '.' + superName;
- reflectInnerClasses(declaringType);
- superType = type;
- break;
- }
- }
- }
- }
-
- //Source files return null if extends does not exist.
- if (superName == null && !getSourceType().getFullyQualifiedName().equals(OBJECT_TYPE_NAME))
- superName = OBJECT_TYPE_NAME;
- if (superName != null) {
- JavaClass javaClassTarget = (JavaClass) getTarget();
- if (superType != null)
- javaClassTarget.setSupertype(reflectJavaClass(superType));
- else
- javaClassTarget.setSupertype(reflectJavaClass(superName));
- }
- }
- } catch (JavaModelException npe) {
- }
- }
- private boolean isTargetInner() {
- JavaClassImpl javaClass = (JavaClassImpl) getTarget();
- return (javaClass.getName().indexOf('$') != -1);
- }
- /**
- * Return true if the sourceType can be found.
- */
- public boolean sourceTypeExists() {
- return getSourceType() != null;
- }
- protected void reflectInnerClasses() {
- IType[] innerClasses = null;
- try {
- innerClasses = getSourceType().getTypes();
- } catch (JavaModelException e) {
- }
- if (innerClasses != null && innerClasses.length != 0) {
- List declaredClasses = getJavaClassTarget().getDeclaredClassesGen();
- JavaClass inner;
- ResourceSet set = getTargetResource().getResourceSet();
- String packageName = getSourceType().getPackageFragment().getElementName();
- for (int i = 0; i < innerClasses.length; i++) {
- inner = (JavaClass) JavaRefFactory.eINSTANCE.reflectType(packageName, innerClasses[i].getTypeQualifiedName(), set);
- declaredClasses.add(inner);
- }
- }
- }
- protected void reflectInnerClasses(IType aType) {
- IType[] innerClasses = null;
- try {
- innerClasses = aType.getTypes();
- } catch (JavaModelException e) {
- }
- if (innerClasses != null && innerClasses.length != 0) {
- ResourceSet set = getTargetResource().getResourceSet();
- String packageName = aType.getPackageFragment().getElementName();
- JavaClassImpl parentType = (JavaClassImpl) JavaRefFactory.eINSTANCE.reflectType(packageName, aType.getTypeQualifiedName(), set);
- List declaredClasses = parentType.getDeclaredClassesGen();
- JavaClass inner;
-
-
- for (int i = 0; i < innerClasses.length; i++) {
- inner = (JavaClass) JavaRefFactory.eINSTANCE.reflectType(packageName, innerClasses[i].getTypeQualifiedName(), set);
- declaredClasses.add(inner);
- }
- }
- }
-}
diff --git a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaFieldJDOMAdaptor.java b/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaFieldJDOMAdaptor.java
deleted file mode 100644
index df005d6f1..000000000
--- a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaFieldJDOMAdaptor.java
+++ /dev/null
@@ -1,291 +0,0 @@
-/*******************************************************************************
- * 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;
-/*
- * $RCSfile: JavaFieldJDOMAdaptor.java,v $
- * $Revision: 1.13 $ $Date: 2005/10/18 14:58:18 $
- */
-import java.util.Map;
-
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.ecore.xmi.XMIResource;
-import org.eclipse.jdt.core.*;
-
-import org.eclipse.jem.internal.java.adapters.ReadAdaptor;
-import org.eclipse.jem.internal.java.adapters.nls.ResourceHandler;
-import org.eclipse.jem.java.*;
-import org.eclipse.jem.java.internal.impl.FieldImpl;
-/**
- * Insert the type's description here.
- * Creation date: (6/6/2000 4:42:50 PM)
- * @author: Administrator
- */
-public class JavaFieldJDOMAdaptor extends JDOMAdaptor {
- private static final String BEGIN_COMMENT = "/*"; //$NON-NLS-1$
- private static final String END_COMMENT = "*/"; //$NON-NLS-1$
- protected IField sourceField = null;
- protected IType parentType = null;
- public JavaFieldJDOMAdaptor(Notifier target, IJavaProject workingProject) {
- super(target, workingProject);
- }
- protected void clearSource() {
- sourceField = null;
- }
-
- protected boolean flushReflectedValues(boolean clearCachedModelObject) {
- if (clearCachedModelObject)
- clearSource();
- FieldImpl field = getTargetField();
- field.setInitializer(null);
- field.setFinal(false);
- field.setStatic(false);
- field.setTransient(false);
- field.setVolatile(false);
- field.setJavaVisibility(JavaVisibilityKind.PUBLIC_LITERAL);
- field.setEType(null);
- return true;
- }
-
- protected void postFlushReflectedValuesIfNecessary(boolean isExisting) {
- getTargetField().setReflected(false);
- super.postFlushReflectedValuesIfNecessary(isExisting);
- }
- /**
- * Return a String for the source starting after the field's name to the end of
- * the source range. This will be the source after the name which could include comments.
- */
- protected String getFieldInitializerSource() {
- IOpenable openable = getSourceField().getOpenable();
- try {
- ISourceRange nameRange, sourceRange;
- int start = -1, length = 0;
- IBuffer buffer = openable.getBuffer();
- if (buffer == null) {
- return ""; //$NON-NLS-1$
- }
- nameRange = getSourceField().getNameRange();
- start = nameRange.getOffset() + nameRange.getLength();
- if (start != -1) {
- sourceRange = getSourceField().getSourceRange();
- if (sourceRange.getOffset() != -1)
- length = sourceRange.getOffset() + sourceRange.getLength() - start;
- return buffer.getText(start, length);
- }
- return null;
- } catch (JavaModelException e) {
- return ""; //$NON-NLS-1$
- }
- }
- /**
- * Return the field source string without comments
- */
- protected String getFieldInitializerSourceWithoutComments() {
- String s = getFieldInitializerSource();
- int start = 0;
- int startComment = -1;
- int endComment = -1;
- while (start < s.length()) {
- startComment = s.indexOf(BEGIN_COMMENT, start);
- if (startComment > 0) {
- String newString;
- endComment = s.indexOf(END_COMMENT, start);
- newString = s.substring(start, startComment);
- s = newString + s.substring(endComment + END_COMMENT.length(), s.length());
- start = 0;
- startComment = -1;
- endComment = -1;
- } else {
- start = s.length();
- }
- }
- return s;
- }
- /**
- * getFieldInitializerString - parse the source for our source field
- * and return the initialization string.
- * Return null if no initialization string or constant value is present.
- * i.e. - public String foo = "foo default"; should return "foo default" (including quotes)
- */
- protected String getFieldInitializerString() {
- String result = null;
- try {
- if (!getParentType().isBinary()) {
- String source = getFieldInitializerSourceWithoutComments();
- if (source != null && source.length() != 0) {
- int equalsPos = source.indexOf('=');//$NON-NLS-1$
- int endPos = source.indexOf(',');//$NON-NLS-1$
- if (endPos == -1)
- endPos = source.length() - 1;
- if (equalsPos != -1) {
- // Copy from after "=" to before ";" or ","
- result = source.substring(equalsPos + 1, endPos);
- result = result.trim();
- }
- }
- } else {
- // Binary type, see if we can use the constant
- // it's not clear from the API's, but this is probably only
- // available for statics.
- Object constantValue = getSourceField().getConstant();
- // Need to convert the constant to a String
- if (constantValue != null) {
- result = constantValue.toString();
- if (constantValue instanceof String) {
- result = "\"" + result + "\""; //$NON-NLS-2$//$NON-NLS-1$
- }
- }
- }
- } catch (JavaModelException e) {
- // punt
- }
- return result;
- }
- /**
- * getParentType - return the IType which corresponds to our parent JavaClass
- * we're going to do this a lot, so cache it.
- */
- protected IType getParentType() {
- if (parentType == null) {
- Field targetField = (Field) getTarget();
- JavaClass parentJavaClass = targetField.getJavaClass();
- if (parentJavaClass != null) {
- JavaClassJDOMAdaptor pa = (JavaClassJDOMAdaptor) EcoreUtil.getAdapter(parentJavaClass.eAdapters(), ReadAdaptor.TYPE_KEY);
- if (pa != null)
- parentType = pa.getSourceType();
- }
- }
- return parentType;
- }
- public Object getReflectionSource() {
- return getSourceField();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jem.internal.java.adapters.JavaReflectionAdaptor#hasReflectionSource()
- */
- public boolean hasCachedReflectionSource() {
- return sourceField != null;
- }
-
- /*
- * Used by Java Class JDOM adapter to create and set with a source field
- */
- public void setSourceField(IField field) {
- sourceField = field;
- }
- /**
- * getSourceField - return the IField which describes our implementing field
- */
- protected IField getSourceField() {
- if (sourceField == null || !sourceField.exists()) {
- IType parent = this.getParentType();
- if (parent != null)
- sourceField = parent.getField(((Field) getTarget()).getName());
- }
- return sourceField;
- }
- public FieldImpl getTargetField() {
- return (FieldImpl) getTarget();
- }
- protected IType getType() {
- return getParentType();
- }
- protected Map getTypeResolutionCache() {
- Field field = getTargetField();
- if (field != null) {
- JavaClass javaClass = field.getJavaClass();
- if (javaClass != null) {
- JDOMAdaptor classAdaptor = (JDOMAdaptor) retrieveAdaptorFrom(javaClass);
- if (classAdaptor != null)
- return classAdaptor.getTypeResolutionCache();
- }
- }
- return null;
- }
- /**
- * getValueIn method comment.
- */
- public Object getValueIn(EObject object, EObject attribute) {
- // At this point, this adapter does not dynamically compute any values,
- // all values are pushed back into the target on the initial call.
- return super.getValueIn(object, attribute);
- }
- /**
- * reflectValues - template method, subclasses override to pump values into target.
- * on entry: name, containing package (and qualified name), and document must be set.
- * JavaClass adaptor:
- * - set modifiers
- * - set name
- * - set type
- */
- public boolean reflectValues() {
- super.reflectValues();
- if (isResourceLoaded() && getSourceProject() != null && getSourceField() != null) {
- setModifiers();
- // setNaming();
- setType();
- return true;
- }
- return false;
- }
- /**
- * setModifiers - set the attribute values related to modifiers here
- */
- protected void setModifiers() {
- Field javaFieldTarget = (Field) getTarget();
- try {
- String initializer = getFieldInitializerString();
- if (initializer != null)
- javaFieldTarget.setInitializer(createBlock(javaFieldTarget.getName(), initializer));
- int flags = getSourceField().getFlags();
- javaFieldTarget.setFinal(Flags.isFinal(flags));
- javaFieldTarget.setStatic(Flags.isStatic(flags));
- javaFieldTarget.setTransient(Flags.isTransient(flags));
- javaFieldTarget.setVolatile(Flags.isVolatile(flags));
- // Set visibility
- if (Flags.isPublic(flags))
- javaFieldTarget.setJavaVisibility(JavaVisibilityKind.PUBLIC_LITERAL);
- else if (Flags.isPrivate(flags))
- javaFieldTarget.setJavaVisibility(JavaVisibilityKind.PRIVATE_LITERAL);
- else if (Flags.isProtected(flags))
- javaFieldTarget.setJavaVisibility(JavaVisibilityKind.PROTECTED_LITERAL);
- else
- javaFieldTarget.setJavaVisibility(JavaVisibilityKind.PACKAGE_LITERAL);
- } catch (JavaModelException npe) {
- System.out.println(ResourceHandler.getString("Error_Introspecting_Flags_ERROR_", new Object[] {((XMIResource) javaFieldTarget.eResource()).getID(javaFieldTarget), npe.getMessage()})); //$NON-NLS-1$ = "error introspecting flags on {0}"
- }
- }
- /**
- * setNaming - set the naming values here
- * - qualified name must be set first, that is the path to the real Java class
- * - ID
- * - null UUID
- */
- protected void setNaming() {
- Field javaFieldTarget = (Field) getTarget();
- JavaClass parent = javaFieldTarget.getContainingJavaClass();
- ((XMIResource) javaFieldTarget.eResource()).setID(javaFieldTarget, parent.getName() + "_" + javaFieldTarget.getName()); //$NON-NLS-1$
- }
- /**
- * setType - set our type here
- */
- protected void setType() {
- String typeName = null;
- try {
- typeName = typeNameFromSignature(getSourceField().getTypeSignature());
- } catch (JavaModelException npe) {
- // name stays null and we carry on
- }
- setFieldType(getTargetField(), typeName);
- }
-}
diff --git a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaJDOMAdapterFactory.java b/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaJDOMAdapterFactory.java
deleted file mode 100644
index f0f7da014..000000000
--- a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaJDOMAdapterFactory.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/*******************************************************************************
- * 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;
-/*
- * $RCSfile: JavaJDOMAdapterFactory.java,v $
- * $Revision: 1.7 $ $Date: 2005/12/02 18:41:27 $
- */
-import java.util.*;
-
-import org.eclipse.emf.common.notify.*;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.jdt.core.*;
-import org.eclipse.jem.internal.java.adapters.*;
-import org.eclipse.jem.internal.java.adapters.JavaReflectionAdapterFactory;
-import org.eclipse.jem.internal.java.adapters.ReflectionAdaptor;
-/**
- * Insert the type's description here.
- * Creation date: (6/13/2000 1:20:31 PM)
- * @author: Administrator
- */
-public class JavaJDOMAdapterFactory extends JavaReflectionAdapterFactory {
-
- protected JavaReflectionSynchronizer synchronizer;
- protected IJavaProject javaProject;
-/**
- * JavaJDOMAdapterFactory constructor comment.
- */
-public JavaJDOMAdapterFactory() {
- super();
-}
-/**
- * JavaJDOMAdapterFactory constructor comment.
- */
-public JavaJDOMAdapterFactory(IJavaProject aJavaProject) {
- this();
- setJavaProject(aJavaProject);
-}
-protected ReflectionAdaptor createJavaClassAdaptor(Notifier target) {
- return new JavaClassJDOMAdaptor(target, getJavaProject(), this);
-}
-protected ReflectionAdaptor createJavaFieldAdaptor(Notifier target) {
- return new JavaFieldJDOMAdaptor(target, getJavaProject());
-}
-protected ReflectionAdaptor createJavaMethodAdaptor(Notifier target) {
- return new JavaMethodJDOMAdaptor(target, getJavaProject());
-}
-/**
- * Flush ALL adapters, worst case
- * We also want to ensure that the source types are also cleared
- * in this worst case scenario.
- */
-public void flushAll() {
- doFlush(reflected.values(),true, true);
-}
-
-public List flushAllNoNotification() {
- return doFlush(reflected.values(),true, false);
-}
-
-public void flushPackage(String packageName, boolean noFlushIfSourceFound) {
- List adaptors = getReflectedForPackage(packageName, noFlushIfSourceFound);
- doFlush(adaptors, true, true);
-}
-public List flushPackageNoNotification(String packageName, boolean noFlushIfSourceFound) {
- List adaptors = getReflectedForPackage(packageName, noFlushIfSourceFound);
- return doFlush(adaptors, true, false);
-}
-/**
- * Return a List of reflection adaptors that belong to
- * the packageName.
- * @param packageName
- * @return
- */
-private List getReflectedForPackage(String packageName, boolean filterFoundTypes) {
- if (packageName != null && !reflected.isEmpty()) {
- isBusyIteratingReflected = true;
- List result = null;
- try {
- Iterator it = reflected.entrySet().iterator();
- Map.Entry entry;
- String key;
- JavaClassJDOMAdaptor adaptor;
- while (it.hasNext()) {
- entry = (Map.Entry) it.next();
- adaptor = (JavaClassJDOMAdaptor) entry.getValue();
- if (filterFoundTypes && adaptor.sourceType != null)
- continue;
- key = (String) entry.getKey();
- if (key.startsWith(packageName) && key.indexOf('.', packageName.length() + 1) < 0) {
- if (result == null)
- result = new ArrayList();
- result.add(entry.getValue());
- }
- }
- } finally {
- finishedIteratingReflected();
- }
- if (result != null)
- return result;
- }
- return Collections.EMPTY_LIST;
-}
-private List doFlush(Collection adaptors, boolean clearSourceType, boolean doNotify) {
- if (!adaptors.isEmpty()) {
- isBusyIteratingReflected = true;
- List notifications = doNotify ? null : new ArrayList(adaptors.size());
- try {
- Notification notification;
- Iterator i = adaptors.iterator();
- JDOMAdaptor adaptor;
- while (i.hasNext()) {
- adaptor = (JDOMAdaptor) i.next();
- if (doNotify)
- adaptor.flushReflectedValuesIfNecessary(clearSourceType);
- else {
- notification = adaptor.flushReflectedValuesIfNecessaryNoNotification(clearSourceType);
- if (notification != null)
- notifications.add(notification);
- }
- }
- } finally {
- finishedIteratingReflected();
- }
- return notifications;
- }
- return Collections.EMPTY_LIST;
-}
-// Flush the adapter for a source object
-public void flushReflection(String source) {
- JDOMAdaptor a = (JDOMAdaptor) reflected.get(source);
- if (a != null)
- a.flushReflectedValuesIfNecessary();
-}
-public Notification flushReflectionNoNotification(String source) {
- JDOMAdaptor a = (JDOMAdaptor) reflected.get(source);
- if (a != null)
- return a.flushReflectedValuesIfNecessaryNoNotification(false);
- return null;
-}
-
-public Notification flushReflectionPlusInnerNoNotification(String source) {
- isBusyIteratingReflected = true;
- Notification notification = null;
- try {
- String innerName = source + '$';
- Iterator it = reflected.entrySet().iterator();
- Map.Entry entry;
- String key;
- JavaReflectionAdaptor adaptor;
- while (it.hasNext()) {
- entry = (Map.Entry) it.next();
- key = (String) entry.getKey();
- if (key.equals(source) || key.startsWith(innerName)) {
- adaptor = (JavaReflectionAdaptor) reflected.get(key);
- if (adaptor != null) {
- if (notification == null)
- notification = adaptor.flushReflectedValuesIfNecessaryNoNotification(false);
- else
- ((NotificationChain) notification).add(adaptor.flushReflectedValuesIfNecessaryNoNotification(false));
- }
- }
- }
- } finally {
- finishedIteratingReflected();
- }
- return notification;
-
-}
-/**
- * Insert the method's description here.
- * Creation date: (11/2/2000 3:02:31 PM)
- * @return org.eclipse.jdt.core.api.IJavaProject
- */
-public IJavaProject getJavaProject() {
- return javaProject;
-}
-/**
- * Create a Java Model listener which will flush invalidated adaptors.
- * This will cause those adapters to re-reflect their target object's contents.
- */
-protected void initializeSynchronizer() {
- synchronizer = new JavaReflectionSynchronizer(this);
-}
-/**
- * Notify all JDOMAdapters which use the same target ICompilationUnit
- * Creation date: (8/17/2001 4:45:43 PM)
- */
-public void notifyContentChanged(ICompilationUnit targetCU) {
-
- if (targetCU == null || reflected.values()==null) return ;
- isBusyIteratingReflected = true;
- try {
- Iterator i = reflected.values().iterator();
- while (i.hasNext()) {
- Object a = i.next() ;
- if (a instanceof JDOMAdaptor) {
- JDOMAdaptor adaptor = (JDOMAdaptor) a;
- IMember reflectionSource = (IMember) adaptor.getReflectionSource();
- ICompilationUnit adapterCU = null ;
- if (reflectionSource != null) {
- try {
- adapterCU = reflectionSource.getCompilationUnit();
- } catch (Throwable e) {}
- }
- if (adapterCU != null && targetCU.equals(adapterCU)) {
- adaptor.contentChanged();
- }
- }
- }
- } finally {
- finishedIteratingReflected();
- }
-}
-/**
- * Insert the method's description here.
- * Creation date: (11/2/2000 3:02:31 PM)
- * @param newJavaProject org.eclipse.jdt.core.IJavaProject
- */
-public void setJavaProject(IJavaProject newJavaProject) {
- javaProject = newJavaProject;
- if (newJavaProject != null && synchronizer == null)
- initializeSynchronizer();
-}
-}
diff --git a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaMethodJDOMAdaptor.java b/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaMethodJDOMAdaptor.java
deleted file mode 100644
index 5497877eb..000000000
--- a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaMethodJDOMAdaptor.java
+++ /dev/null
@@ -1,364 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-/*
- * $RCSfile: JavaMethodJDOMAdaptor.java,v $
- * $Revision: 1.14 $ $Date: 2005/10/18 14:58:18 $
- */
-package org.eclipse.jem.internal.adapters.jdom;
-
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.ecore.xmi.XMIResource;
-import org.eclipse.jdt.core.*;
-
-import org.eclipse.jem.internal.java.adapters.IJavaMethodAdapter;
-import org.eclipse.jem.internal.java.adapters.ReadAdaptor;
-import org.eclipse.jem.internal.java.adapters.nls.ResourceHandler;
-import org.eclipse.jem.java.*;
-import org.eclipse.jem.java.internal.impl.MethodImpl;
-import org.eclipse.jem.util.TimerTests;
-
-/**
- * Java Method Reflection Adapter for JDOM (i.e. JDT model)
- * Creation date: (6/6/2000 4:42:50 PM)
- * @author: Administrator
- */
-public class JavaMethodJDOMAdaptor extends JDOMAdaptor implements IJavaMethodAdapter {
-
- /*
- * Step ids used for TimerTests of performance testing.
- */
- public static final String REFLECT_METHOD = "Reflect JDOM Method"; //$NON-NLS-1$
-
- protected IMethod sourceMethod = null;
-
- protected IType parentType = null;
-
- public JavaMethodJDOMAdaptor(Notifier target, IJavaProject workingProject) {
- super(target, workingProject);
- }
-
-
- protected boolean flushReflectedValues(boolean clearCachedModelObject) {
- if (clearCachedModelObject)
- clearSource();
- MethodImpl method = (MethodImpl) getTarget();
- method.setIsGenerated(false);
- method.setFinal(false);
- method.setNative(false);
- method.setStatic(false);
- method.setSynchronized(false);
- method.setConstructor(false);
- method.setAbstract(false);
- method.setJavaVisibility(JavaVisibilityKind.PUBLIC_LITERAL);
- method.setEType(null);
- method.getParametersGen().clear();
- method.getJavaExceptionsGen().clear();
- parentType = null;
- return true;
- }
-
- protected void postFlushReflectedValuesIfNecessary(boolean isExisting) {
- ((MethodImpl) getTarget()).setReflected(false);
- super.postFlushReflectedValuesIfNecessary(isExisting);
- }
- /**
- * addExceptions - reflect our exception list
- */
- protected void addExceptions() {
- try {
- IMethod sourceMethod = getSourceMethod();
- String[] exceptionNames = sourceMethod.getExceptionTypes();
- List exceptions = ((MethodImpl) getTarget()).getJavaExceptionsGen();
- for (int i = 0; i < exceptionNames.length; i++) {
- exceptions.add(createJavaClassRef(typeNameFromSignature(exceptionNames[i])));
- }
- } catch (JavaModelException npe) {
- // name stays null and we carry on
- }
- }
-
-
- protected String[] getParameterNames() {
- String[] parmNames = new String[0], parmTypeNames = getSourceMethod().getParameterTypes();
- try {
- parmNames = getSourceMethod().getParameterNames();
- } catch (JavaModelException npe) {
- // name stays null and we carry on
- }
- // Temp hack to work around a JavaModel bug, above call on a Binary method may return null
- if (parmNames == null || parmNames.length == 0) {
- parmNames = new String[parmTypeNames.length];
- for (int i = 0; i < parmTypeNames.length; i++) {
- parmNames[i] = "arg" + i;//$NON-NLS-1$
- }
- }
- return parmNames;
- }
-
- /**
- * addParameters - reflect our parms
- */
- protected void addParameters() {
- String[] parmTypeNames = getSourceMethod().getParameterTypes();
- MethodImpl javaMethodTarget = (MethodImpl) getTarget();
- List params = javaMethodTarget.getParametersGen();
- for (int i = 0; i < parmTypeNames.length; i++) {
- params.add(createJavaParameter(javaMethodTarget, null, typeNameFromSignature(parmTypeNames[i])));
- }
- }
-
- protected void clearSource() {
- sourceMethod = null;
- }
-
- protected JavaClass getContainingJavaClass() {
- return ((Method) getTarget()).getContainingJavaClass();
- }
-
- /**
- * getParentType - return the IType which corresponds to our parent JavaClass we're going to do this a lot, so cache it.
- */
- protected IType getParentType() {
- if (parentType == null) {
- Method targetMethod = (Method) getTarget();
- JavaClass parentJavaClass = targetMethod.getContainingJavaClass();
- JavaClassJDOMAdaptor pa = (JavaClassJDOMAdaptor) EcoreUtil.getAdapter(parentJavaClass.eAdapters(), ReadAdaptor.TYPE_KEY);
- if (pa != null)
- parentType = pa.getSourceType();
- }
- return parentType;
- }
-
- /**
- * getParmTypeSignatures - return an array of Strings (in Signature format) for our parameter types For reflection purposes, we can only rely on
- * our UUID, since our parms may not yet be known. see org.eclipse.jdt.core.SourceMapper.convertTypeNamesToSigs()
- */
- protected String[] getParmTypeSignatures() {
- Method javaMethodTarget = (Method) getTarget();
- String[] typeNames = getTypeNamesFromMethodID(((XMIResource) javaMethodTarget.eResource()).getID(javaMethodTarget));
- if (typeNames == null)
- return emptyStringArray;
- int n = typeNames.length;
- if (n == 0)
- return emptyStringArray;
- String[] typeSigs = new String[n];
- try {
- for (int i = 0; i < n; ++i) {
- typeSigs[i] = Signature.createTypeSignature(new String(typeNames[i]), getParentType().isBinary());
- }
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- }
- return typeSigs;
- }
-
- public Object getReflectionSource() {
- return getSourceMethod();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jem.internal.java.adapters.JavaReflectionAdaptor#hasReflectionSource()
- */
- public boolean hasCachedReflectionSource() {
- return sourceMethod != null;
- }
-
- /*
- * Used by Java Class JDOM adapter to create and set with a source method/
- */
- public void primSetMethod(IMethod method) {
- sourceMethod = method;
- }
- /**
- * getsourceMethod - return the IMethod which describes our implementing method
- */
- public IMethod getSourceMethod() {
- if ((sourceMethod == null) || (!sourceMethod.exists())) {
- try {
- IType parent = this.getParentType();
- if (parent != null) {
- String[] parmNames = this.getParmTypeSignatures();
- sourceMethod = JDOMSearchHelper.searchForMatchingMethod(parent, ((Method) getTarget()).getName(), parmNames);
- }
- } catch (JavaModelException e) {
- //do nothing
- }
- }
- return sourceMethod;
- }
-
- protected IType getType() {
- return getParentType();
- }
-
- protected Map getTypeResolutionCache() {
- Method method = (Method) getTarget();
- if (method != null) {
- JavaClass javaClass = method.getJavaClass();
- if (javaClass != null) {
- JDOMAdaptor classAdaptor = (JDOMAdaptor) retrieveAdaptorFrom(javaClass);
- if (classAdaptor != null)
- return classAdaptor.getTypeResolutionCache();
- }
- }
- return null;
- }
-
- /**
- * getValueIn method comment.
- */
- public Object getValueIn(EObject object, EObject attribute) {
- // At this point, this adapter does not dynamically compute any values,
- // all values are pushed back into the target on the initial call.
- return super.getValueIn(object, attribute);
- }
-
- /**
- * reflectValues - template method, subclasses override to pump values into target. on entry: UUID, name, containing package (and qualified name),
- * and document must be set. Method adaptor: - set modifiers - set name - set return type - add parameters - add exceptions
- */
- public boolean reflectValues() {
- super.reflectValues();
- try {
- TimerTests.basicTest.startCumulativeStep(REFLECT_METHOD);
- if (isResourceLoaded() && getSourceProject() != null && getSourceMethod() != null && sourceMethod.exists()) {
- setModifiers();
- setNaming();
- setReturnType();
- addParameters();
- addExceptions();
- return true;
- }
- } finally {
- TimerTests.basicTest.stopCumulativeStep(REFLECT_METHOD);
- }
- return false;
- }
-
- /**
- * Set the generated flag if @generated is found in the source.
- */
- protected void setGeneratedFlag() {
- Method methodTarget = (Method) getTarget();
- try {
- String source = getSourceMethod().getSource();
- if (source != null) {
- int index = source.indexOf(Method.GENERATED_COMMENT_TAG);
- if (index > 0)
- methodTarget.setIsGenerated(true);
- }
- } catch (JavaModelException npe) {
- //System.out.println(ResourceHandler.getString("Error_Setting_GenFlag_ERROR_", new Object[]
- // {((XMIResource)methodTarget.eResource()).getID(methodTarget), npe.getMessage()})); //$NON-NLS-1$ = "error setting the generated flag on
- // {0}, exception: {1}"
- }
- }
-
-
- /* (non-Javadoc)
- * @see org.eclipse.jem.internal.java.adapters.IJavaMethodAdapter#reflectGeneratedIfNecessary()
- */
- public boolean reflectGeneratedIfNecessary() {
- if (reflectValuesIfNecessary()) {
- setGeneratedFlag();
- return true;
- }
- return false;
- }
-
- public boolean reflectParamNamesIfNecessary() {
- if (reflectValuesIfNecessary()) {
- String [] paramNames = getParameterNames();
- List param = ((MethodImpl)getTarget()).getParameters();
- for (int i = 0; i < paramNames.length; i++) {
- ((JavaParameter)param.get(i)).setName(paramNames[i]);
- }
- return true;
- }
- return false;
- }
- /**
- * setModifiers - set the attribute values related to modifiers here
- */
- protected void setModifiers() {
- Method methodTarget = (Method) getTarget();
- try {
- methodTarget.setFinal(Flags.isFinal(getSourceMethod().getFlags()));
- methodTarget.setNative(Flags.isNative(getSourceMethod().getFlags()));
- methodTarget.setStatic(Flags.isStatic(getSourceMethod().getFlags()));
- methodTarget.setSynchronized(Flags.isSynchronized(getSourceMethod().getFlags()));
- methodTarget.setConstructor(getSourceMethod().isConstructor());
-
- JavaClass javaClass = getContainingJavaClass();
- //Set abstract
- if (javaClass.getKind().getValue() == TypeKind.INTERFACE)
- methodTarget.setAbstract(true);
- else
- methodTarget.setAbstract(Flags.isAbstract(getSourceMethod().getFlags()));
- // Set visibility
- if (javaClass.getKind().getValue() == TypeKind.INTERFACE || Flags.isPublic(getSourceMethod().getFlags()))
- methodTarget.setJavaVisibility(JavaVisibilityKind.PUBLIC_LITERAL);
- else if (Flags.isPrivate(getSourceMethod().getFlags()))
- methodTarget.setJavaVisibility(JavaVisibilityKind.PRIVATE_LITERAL);
- else if (Flags.isProtected(getSourceMethod().getFlags()))
- methodTarget.setJavaVisibility(JavaVisibilityKind.PROTECTED_LITERAL);
- else
- //Visibility must be package
- methodTarget.setJavaVisibility(JavaVisibilityKind.PACKAGE_LITERAL);
- } catch (JavaModelException npe) {
- System.out
- .println(ResourceHandler
- .getString(
- "Error_Introspecting_Flags_ERROR_", (new Object[] { ((XMIResource) methodTarget.eResource()).getID(methodTarget), npe.getMessage()}))); //$NON-NLS-1$ = "error introspecting flags on {0}, exception: {1}"
- }
- }
-
- /**
- * setNaming - set the naming values here - qualified name must be set first, that is the path to the real Java class - ID - name-based UUID
- */
- protected void setNaming() {
- //
- // naming is currently a no-op since the name and UUID must be set prior to reflection
- // ...and ID is redundant with UUID.
- // javaFieldTarget.setID(parent.getQualifiedName() + "_" + javaFieldTarget.getName());
- }
-
- /**
- * setType - set our return type here
- */
- protected void setReturnType() {
- String typeName = null;
- try {
- typeName = typeNameFromSignature(getSourceMethod().getReturnType());
- } catch (JavaModelException npe) {
- // name stays null and we carry on
- }
- if (typeName != null) {
- Method javaMethodTarget = (Method) getTarget();
- javaMethodTarget.setEType(createJavaClassRef(typeName));
- }
- }
-
- /**
- * Insert the method's description here. Creation date: (10/3/2001 10:08:34 AM)
- *
- * @param newSourceMethod
- * org.eclipse.jdt.core.IMethod
- */
- public void setSourceMethod(org.eclipse.jdt.core.IMethod newSourceMethod) {
- sourceMethod = newSourceMethod;
- }
-}
diff --git a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaModelListener.java b/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaModelListener.java
deleted file mode 100644
index 9ab07af59..000000000
--- a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaModelListener.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 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;
-/*
- * $RCSfile: JavaModelListener.java,v $
- * $Revision: 1.11 $ $Date: 2006/05/17 20:13:58 $
- */
-
-
-/**
- * Insert the type's description here.
- * Creation date: (10/31/2000 1:13:12 PM)
- * @author: Administrator
- * @deprecated Use {@link org.eclipse.jem.workbench.utility.JavaModelListener} instead.
- */
-public abstract class JavaModelListener extends org.eclipse.jem.workbench.utility.JavaModelListener {
-
- /**
- *
- *
- * @since 1.2.0
- */
- public JavaModelListener() {
- super();
- }
-
- /**
- * @param eventsToListen
- *
- * @since 1.2.0
- */
- public JavaModelListener(int eventsToListen) {
- super(eventsToListen);
- }
-
-}
diff --git a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaReflectionSynchronizer.java b/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaReflectionSynchronizer.java
deleted file mode 100644
index 095250eba..000000000
--- a/plugins/org.eclipse.jem.workbench/workbench/org/eclipse/jem/internal/adapters/jdom/JavaReflectionSynchronizer.java
+++ /dev/null
@@ -1,349 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 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;
-/*
- * $RCSfile: JavaReflectionSynchronizer.java,v $
- * $Revision: 1.15 $ $Date: 2006/05/17 20:13:58 $
- */
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Level;
-
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.jdt.core.*;
-
-import org.eclipse.jem.internal.plugin.JavaPlugin;
-import org.eclipse.jem.util.logger.proxy.Logger;
-import org.eclipse.jem.workbench.utility.JavaModelListener;
-
-/**
- * Insert the type's description here.
- * Creation date: (11/1/2000 11:42:05 AM)
- * @author: Administrator
- */
-public class JavaReflectionSynchronizer extends JavaModelListener {
-
- protected JavaJDOMAdapterFactory fAdapterFactory;
-
- protected boolean flushedAll = false;
- protected List flushTypes = new ArrayList();
- protected List flushTypePlusInner = new ArrayList();
- protected List notifications = new ArrayList();
- /**
- * JavaReflectionSynchronizer constructor comment.
- */
- public JavaReflectionSynchronizer(JavaJDOMAdapterFactory synchronizee) {
- super();
- fAdapterFactory = synchronizee;
- }
- /* (non-Javadoc)
- * @see org.eclipse.jem.internal.adapters.jdom.JavaModelListener#getJavaProject()
- */
- protected IJavaProject getJavaProject() {
- return getAdapterFactory().getJavaProject();
- }
- /**
- * Tell the reflection factory to flush the passed IType
- */
- protected Notification doFlush(IType element) {
- return getAdapterFactory().flushReflectionNoNotification(element.getFullyQualifiedName());
- }
-
- /*
- * Flush the compilation unit and any inner classes since we don't if they may or may not of changed.
- */
- protected Notification doFlush(ICompilationUnit element) {
- return getAdapterFactory().flushReflectionPlusInnerNoNotification(getFullNameFromElement(element));
- }
-
- protected void flush(IType element) {
- if (!flushTypes.contains(element))
- flushTypes.add(element);
- }
- /*
- * flush the compilation unit. Since we don't know if inner classes may also
- * of been affected, they to will be flushed.
- */
- protected void flush(ICompilationUnit element) {
- if (!flushTypePlusInner.contains(element))
- flushTypePlusInner.add(element);
- }
- protected void flushPackage(String packageName, boolean noFlushIfSourceFound) {
- notifications.addAll(getAdapterFactory().flushPackageNoNotification(packageName, true));
- }
- protected JavaJDOMAdapterFactory getAdapterFactory() {
- return fAdapterFactory;
- }
-
- /**
- * Handle the change for a single element, children will be handled separately.
- *
- */
- protected void processJavaElementChanged(ICompilationUnit element, IJavaElementDelta delta) {
- switch (delta.getKind()) {
- case IJavaElementDelta.CHANGED : {
- // A file save had occurred. It doesn't matter if currently working copy or not.
- // It means something has changed to the file on disk, but don't know what.
- if ((delta.getFlags() & IJavaElementDelta.F_PRIMARY_RESOURCE) != 0) {
- flush(element); // Flush everything, including inner classes.
- } else if ((delta.getFlags() & IJavaElementDelta.F_CONTENT) == 0 &&
- (delta.getFlags() & IJavaElementDelta.F_CHILDREN) != 0) //A type may have been added or removed.
- processChildren(element, delta);
- break;
- }
- case IJavaElementDelta.REMOVED :
- case IJavaElementDelta.ADDED :
- if (!element.isWorkingCopy())
- disAssociateSourcePlusInner(getFullNameFromElement(element));
- break;
- }
- }
-
- /**
- * Handle the change for a single element, children will be handled separately.
- *
- */
- protected void processJavaElementChanged(IJavaProject element, IJavaElementDelta delta) {
- if (isInClasspath(element)) {
- if (delta.getKind() == IJavaElementDelta.REMOVED || (delta.getKind() == IJavaElementDelta.CHANGED && (delta.getFlags() & IJavaElementDelta.F_CLOSED) != 0)) {
- if (element.equals(getAdapterFactory().getJavaProject()))
- stopSynchronizer();
- else
- flushAll(); //another dependent project has changed so flush all to be safe
- return;
- } else if (delta.getKind() == IJavaElementDelta.ADDED || isClasspathResourceChange(delta)) {
- flushAll();
- return;
- }
- processChildren(element, delta);
- }
- }
- /**
- * Handle the change for a single element, children will be handled separately.
- */
- protected void processJavaElementChanged(IClassFile element, IJavaElementDelta delta) {
- int kind = delta.getKind();
- if (kind == IJavaElementDelta.REMOVED || kind == IJavaElementDelta.ADDED) {
- // It doesn't matter if totally removed or just moved somewhere else, we will clear out and remove the
- // adapter because there could be a rename which would be a different class.
- // Currently the element is already deleted and there is no way to find the types in the unit to remove.
- // So instead we ask factory to remove all it any that start with it plus for inner classes.
- disAssociateSourcePlusInner(getFullNameFromElement(element));
- return; // Since the classfile was removed we don't need to process the children (actually the children list will be empty
- }
- IJavaElementDelta[] children = delta.getAffectedChildren();
- for (int ii = 0; ii < children.length; ii++) {
- processDelta(children[ii]);
- }
- }
- /**
- * Handle the change for a single element, children will be handled separately.
- *
- */
- protected void processJavaElementChanged(IPackageFragmentRoot element, IJavaElementDelta delta) {
- if (flushedAll)
- return;
- if (isClassPathChange(delta))
- flushAll();
- else
- super.processJavaElementChanged(element, delta);
- }
-
- /*
- * We will force the flushing of all adaptors for the given package name.
- * This is necessary if a type was reflected prior to the package existing or
- * if the package is deleted.
- * @see org.eclipse.jem.internal.adapters.jdom.JavaModelListener#processJavaElementChanged(org.eclipse.jdt.core.IPackageFragment, org.eclipse.jdt.core.IJavaElementDelta)
- */
- protected void processJavaElementChanged(IPackageFragment element, IJavaElementDelta delta) {
- switch (delta.getKind()) {
- case IJavaElementDelta.ADDED : {
- if (delta.getAffectedChildren().length == 0)
- flushPackage(delta.getElement().getElementName(), true);
- break;
- }
- case IJavaElementDelta.REMOVED :{
- if (delta.getAffectedChildren().length == 0)
- getAdapterFactory().flushPackage(delta.getElement().getElementName(), false);
- break;
- }
- default :
- super.processJavaElementChanged(element, delta);
- }
- }
-
- /**
- * Handle the change for a single element, children will be handled separately.
- *
- */
- protected void processJavaElementChanged(IType element, IJavaElementDelta delta) {
- int kind = delta.getKind();
- if (kind == IJavaElementDelta.REMOVED || kind == IJavaElementDelta.ADDED) {
- disAssociateSourcePlusInner(element.getFullyQualifiedName());
- } else {
- flush(element);
- processChildren(element, delta);
- // Note, if a method element or a field was changed, there may be delta.getAffectedChildren()
- // that will have to be processed if we are to update the JavaMethod/JavaField JDOMAdaptor s.
- }
- }
- /**
- * Given that an IType does not exists anymore, assume
- * that the type's name is package.filename (without the .java)
- * If we are wrong (if, then a rare case), we will flush.
- * Next access will induce a reflection attempt.
- * @deprecated This doesn't look like it is ever called. It someone else calls it, please contact development to see if right method to be called.
- */
- protected void processRemoveOrAdd(ICompilationUnit element) {
- disAssociateSource(getFullNameFromElement(element));
- }
-
- protected String getFullNameFromElement(ICompilationUnit cu) {
- IType primary = cu.findPrimaryType();
- if (primary != null)
- return primary.getFullyQualifiedName();
- else {
- String filename = cu.getElementName();
- // Just strip off extension. There is actually a more complicated test for "java like extenstions" but JDT has that hidden\
- // so we will just guess and take off the extension.
- int idx = filename.lastIndexOf('.');
- if (idx != -1)
- filename = filename.substring(0, idx);
- return ((IPackageFragment) cu.getParent()).getElementName()+'.'+filename;
- }
- }
-
- protected String getFullNameFromElement(IClassFile cf) {
- try {
- return cf.getType().getFullyQualifiedName();
- } catch (JavaModelException e) {
- JavaPlugin.getDefault().getLogger().log(e, Level.WARNING);
- String cfName = cf.getElementName();
- return cfName.substring(0, cfName.length()-(".class".length()));
- }
- }
-
- protected String getFullNameFromElement(IJavaElement element) {
- String name = element.getElementName();
- if (element == null || name.length() <= 5 || !name.substring(name.length() - 5).equals(".java")) { //$NON-NLS-1$
- // Should not be here,
- Logger logger = JavaPlugin.getDefault().getLogger();
- if (logger.isLoggingLevel(Level.FINE))
- logger.log("Invalid .java file: " + name, Level.FINE); //$NON-NLS-1$
- // Make a guess, at worst case, nothing will come out of this.
- int index = name.lastIndexOf("."); //$NON-NLS-1$
- if (index >= 0)
- name = name.substring(0, index) + ".java"; // rename the extension to .java //$NON-NLS-1$
- else
- name = name + ".java"; //$NON-NLS-1$
- }
- if (element.getParent().getElementName() == null || element.getParent().getElementName().length() == 0)
- return name.substring(0, name.length() - 5);
- else
- return element.getParent().getElementName() + "." + name.substring(0, name.length() - 5); //$NON-NLS-1$
- }
- /**
- * Stop the synchronizer from listening to any more changes.
- */
- public void stopSynchronizer() {
- JavaCore.removeElementChangedListener(this);
- }
- /**
- * @see org.eclipse.jem.internal.adapters.jdom.JavaModelListener#elementChanged(ElementChangedEvent)
- */
- public void elementChanged(ElementChangedEvent event) {
- try {
- flushTypes.clear();
- flushTypePlusInner.clear();
- notifications.clear();
- super.elementChanged(event);
- flushTypes();
- processNotifications();
- } finally {
- flushedAll = false;
- flushTypes.clear();
- flushTypePlusInner.clear();
- notifications.clear();
- }
- }
- /**
- *
- */
- private void flushTypes() {
- if (!flushTypes.isEmpty()) {
- IType type = null;
- Notification not;
- for (int i = 0; i < flushTypes.size(); i++) {
- type = (IType) flushTypes.get(i);
- not = doFlush(type);
- if (not != null)
- notifications.add(not);
- }
- }
- if (!flushTypePlusInner.isEmpty()) {
- ICompilationUnit unit = null;
- Notification not;
- for (int i = 0; i < flushTypePlusInner.size(); i++) {
- unit = (ICompilationUnit) flushTypePlusInner.get(i);
- not = doFlush(unit);
- if (not != null)
- notifications.add(not);
- }
- }
- }
- /**
- * @param notifications
- */
- private void processNotifications() {
- Notifier notifier;
- Notification not;
- for (int i = 0; i < notifications.size(); i++) {
- not = (Notification) notifications.get(i);
- notifier = (Notifier) not.getNotifier();
- if (notifier != null)
- try {
- notifier.eNotify(not);
- } catch (Exception e) {
- JavaPlugin.getDefault().getLogger().log(e); //catch exceptions so all notifications are processed
- }
- }
- }
- protected void disAssociateSource(String qualifiedName) {
- Notification not = getAdapterFactory().disAssociateSource(qualifiedName, false);
- if (not != null)
- notifications.add(not);
- }
- protected void disAssociateSourcePlusInner(String qualifiedName) {
- Notification not = getAdapterFactory().disAssociateSourcePlusInner(qualifiedName, false);
- if (not != null)
- notifications.add(not);
- }
- protected void flushAll() {
- notifications.addAll(getAdapterFactory().flushAllNoNotification());
- flushedAll = true;
- }
- /**
- * @see org.eclipse.jem.internal.adapters.jdom.JavaModelListener#processChildren(IJavaElement, IJavaElementDelta)
- */
- protected void processChildren(IJavaElement element, IJavaElementDelta delta) {
- if (!flushedAll)
- super.processChildren(element, delta);
- }
- /**
- * @see org.eclipse.jem.internal.adapters.jdom.JavaModelListener#processDelta(IJavaElementDelta)
- */
- public void processDelta(IJavaElementDelta delta) {
- if (!flushedAll)
- super.processDelta(delta);
- }
-}

Back to the top