Skip to main content
summaryrefslogtreecommitdiffstats
blob: 60c62814aead0aac1d5a9593fe4c5241dea4f99e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*******************************************************************************
 * Copyright (c) 2004, 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: JavaArrayTypeReflectionAdapter.java,v $
 *  $Revision: 1.8 $  $Date: 2005/09/14 23:30:35 $ 
 */
package org.eclipse.jem.internal.java.adapters;

import java.util.List;

import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jem.java.ArrayType;
import org.eclipse.jem.java.InheritanceCycleException;
import org.eclipse.jem.java.JavaClass;
import org.eclipse.jem.java.JavaHelpers;
import org.eclipse.jem.java.JavaRefFactory;
import org.eclipse.jem.java.internal.impl.ArrayTypeImpl;

/**
 * Array type reflection adapter. Since arrays are very constant we don't need any fancy reflection to the source type (class object). It really
 * doesn't do anything. It is just here so that it exists. Everything is constant or depends on the final component type.
 * 
 * @since 1.0.0
 */
public class JavaArrayTypeReflectionAdapter extends JavaReflectionAdaptor implements IJavaClassAdaptor {

	public JavaArrayTypeReflectionAdapter(Notifier target) {
		super(target);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jem.internal.java.adapters.JavaReflectionAdaptor#getReflectionSource()
	 */
	public Object getReflectionSource() {
		return null; // There isn't any for arrays.
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jem.internal.java.adapters.JavaReflectionAdaptor#hasReflectionSource()
	 */
	public boolean hasReflectionSource() {
		// This method is used to determine if valid, so we pass on to use the final component.
		ArrayType jh = (ArrayType) getTarget();
		JavaHelpers fc = jh.getFinalComponentType();
		return (fc.isPrimitive() || ((JavaClass) fc).isExistingType());
	}
	
	public boolean hasCachedReflectionSource() {
		ArrayType jh = (ArrayType) getTarget();
		JavaHelpers fc = jh.getFinalComponentType();
		if(fc.isPrimitive())
		    return true;
		else {
		    JavaReflectionAdaptor reflectionAdaptor = (JavaReflectionAdaptor) EcoreUtil.getExistingAdapter(fc, ReflectionAdaptor.TYPE_KEY);
		    return (reflectionAdaptor != null) ? reflectionAdaptor.hasCachedReflectionSource() : false;		    
		} 
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jem.internal.java.adapters.ReflectionAdaptor#reflectValues()
	 */
	public boolean reflectValues() {
		ArrayTypeImpl at = (ArrayTypeImpl) getTarget();

		// Arrays are always:
		//		final
		//		Supertype of java.lang.Object
		//		implements java.lang.Cloneable, java.io.Serializable
		at.setFinal(true);
		try {
			at.setSupertype((JavaClass) JavaRefFactory.eINSTANCE.reflectType("java.lang.Object", (EObject) getTarget())); //$NON-NLS-1$
		} catch (InheritanceCycleException e) {
		}
		List list = at.getImplementsInterfacesGen();
		list.add(JavaRefFactory.eINSTANCE.createClassRef("java.lang.Cloneable")); //$NON-NLS-1$
		list.add(JavaRefFactory.eINSTANCE.createClassRef("java.io.Serializable")); //$NON-NLS-1$
		return super.reflectValues();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jem.internal.java.adapters.JavaReflectionAdaptor#flushReflectedValues(boolean)
	 */
	protected boolean flushReflectedValues(boolean clearCachedModelObject) {
		ArrayTypeImpl at = (ArrayTypeImpl) getTarget();
		at.getImplementsInterfacesGen().clear();
		return true;
	}

	/*
	 *  (non-Javadoc)
	 * @see org.eclipse.jem.internal.java.adapters.IJavaClassAdaptor#isSourceTypeFromBinary()
	 */
	public boolean isSourceTypeFromBinary() {
		return false;
	}

	/*
	 *  (non-Javadoc)
	 * @see org.eclipse.jem.internal.java.adapters.IJavaClassAdaptor#reflectFieldsIfNecessary()
	 */
	public synchronized boolean reflectFieldsIfNecessary() {
		return reflectValuesIfNecessary();
	}

	/*
	 *  (non-Javadoc)
	 * @see org.eclipse.jem.internal.java.adapters.IJavaClassAdaptor#reflectMethodsIfNecessary()
	 */
	public synchronized boolean reflectMethodsIfNecessary() {
		return reflectValuesIfNecessary();
	}

	/*
	 *  (non-Javadoc)
	 * @see org.eclipse.jem.internal.java.adapters.IJavaClassAdaptor#sourceTypeExists()
	 */
	public boolean sourceTypeExists() {
		return hasReflectionSource();
	}
}

Back to the top