1 11 package org.eclipse.core.internal.expressions; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.core.runtime.CoreException; 15 16 import org.eclipse.core.expressions.IPropertyTester; 17 import org.eclipse.core.expressions.PropertyTester; 18 19 public class TypeExtension { 20 21 private static final TypeExtension[] EMPTY_TYPE_EXTENSION_ARRAY= new TypeExtension[0]; 22 23 24 static final IPropertyTester CONTINUE= new IPropertyTester() { 25 public boolean handles(String namespace, String method) { 26 return false; 27 } 28 public boolean isInstantiated() { 29 return true; 30 } 31 public boolean isDeclaringPluginActive() { 32 return true; 33 } 34 public IPropertyTester instantiate() { 35 return this; 36 } 37 public boolean test(Object receiver, String method, Object [] args, Object expectedValue) { 38 return false; 39 } 40 }; 41 42 43 private static final TypeExtension END_POINT= new TypeExtension() { 44 IPropertyTester findTypeExtender(TypeExtensionManager manager, String namespace, String name, boolean staticMethod, boolean forcePluginActivation) throws CoreException { 45 return CONTINUE; 46 } 47 }; 48 49 50 private Class fType; 51 52 private IPropertyTester[] fExtenders; 53 54 55 private TypeExtension fExtends; 56 57 private TypeExtension[] fImplements; 58 59 private TypeExtension() { 60 } 62 63 TypeExtension(Class type) { 64 Assert.isNotNull(type); 65 fType= type; 66 } 67 68 IPropertyTester findTypeExtender(TypeExtensionManager manager, String namespace, String method, boolean staticMethod, boolean forcePluginActivation) throws CoreException { 69 if (fExtenders == null) { 70 fExtenders= manager.loadTesters(fType); 71 } 72 IPropertyTester result; 73 74 for (int i= 0; i < fExtenders.length; i++) { 76 IPropertyTester extender= fExtenders[i]; 77 if (extender == null || !extender.handles(namespace, method)) 78 continue; 79 if (extender.isInstantiated()) { 80 return extender; 87 } else { 88 if (extender.isDeclaringPluginActive() || forcePluginActivation) { 89 try { 90 PropertyTesterDescriptor descriptor= (PropertyTesterDescriptor)extender; 91 IPropertyTester inst= descriptor.instantiate(); 92 ((PropertyTester)inst).internalInitialize(descriptor); 93 fExtenders[i]= extender= inst; 94 return extender; 95 } catch (CoreException e) { 96 fExtenders[i]= null; 97 throw e; 98 } catch (ClassCastException e) { 99 fExtenders[i]= null; 100 throw new CoreException(new ExpressionStatus( 101 ExpressionStatus.TYPE_EXTENDER_INCORRECT_TYPE, 102 ExpressionMessages.TypeExtender_incorrectType, 103 e)); 104 } 105 } else { 106 return extender; 107 } 108 } 109 } 110 111 if (staticMethod) 113 return CONTINUE; 114 115 if (fExtends == null) { 117 Class superClass= fType.getSuperclass(); 118 if (superClass != null) { 119 fExtends= manager.get(superClass); 120 } else { 121 fExtends= END_POINT; 122 } 123 } 124 result= fExtends.findTypeExtender(manager, namespace, method, staticMethod, forcePluginActivation); 125 if (result != CONTINUE) 126 return result; 127 128 if (fImplements == null) { 130 Class [] interfaces= fType.getInterfaces(); 131 if (interfaces.length == 0) { 132 fImplements= EMPTY_TYPE_EXTENSION_ARRAY; 133 } else { 134 fImplements= new TypeExtension[interfaces.length]; 135 for (int i= 0; i < interfaces.length; i++) { 136 fImplements[i]= manager.get(interfaces[i]); 137 } 138 } 139 } 140 for (int i= 0; i < fImplements.length; i++) { 141 result= fImplements[i].findTypeExtender(manager, namespace, method, staticMethod, forcePluginActivation); 142 if (result != CONTINUE) 143 return result; 144 } 145 return CONTINUE; 146 } 147 } 148 | Popular Tags |