1 19 20 package org.netbeans.modules.java.bridge; 21 22 import java.util.WeakHashMap ; 23 import javax.jmi.reflect.RefObject; 24 import org.netbeans.modules.java.JavaDataObject; 25 import org.netbeans.modules.java.JavaEditor; 26 import org.netbeans.modules.javacore.internalapi.JavaMetamodel; 27 import org.openide.cookies.OpenCookie; 28 import org.openide.nodes.CookieSet; 29 import org.openide.nodes.Node; 30 import org.openide.src.*; 31 import org.openide.text.PositionBounds; 32 33 39 public class LangEnvImpl implements LangModel.Env { 40 WeakHashMap cookieMap; 41 BindingFactory binding; 42 WrapperFactory wrapper; 43 LangModel model; 44 JavaDataObject jdo; 45 46 public LangEnvImpl(JavaDataObject jdo) { 47 this.jdo = jdo; 48 this.binding = new MDRBindingFactory (); 49 this.wrapper = DefaultWrapper.getInstance(); 50 cookieMap = new WeakHashMap (57); 51 } 52 53 public void setModel(LangModel model) { 54 this.model = model; 55 } 56 57 public BindingFactory getBindingFactory() { 58 return binding; 59 } 60 61 public WrapperFactory getWrapperFactory() { 62 return wrapper; 63 } 64 65 68 public void complete(Element scope, int informationKind) { 69 } 70 71 77 public Type resolveType(Element context, Type original) { 78 if (original.isPrimitive()) 79 return original; 80 Type t = original; 81 int depth = 0; 82 while (t.isArray()) { 83 t = t.getElementType(); 84 depth++; 85 } 86 if (t.isPrimitive()) 87 return original; 88 89 Identifier id = t.getTypeIdentifier(); 90 Identifier resolved = resolveTypeIdent(context, id); 91 if (resolved == id) 92 return original; 93 94 t = Type.createClass(resolved); 96 while (depth > 0) { 97 t = Type.createArray(t); 98 depth--; 99 } 100 return t; 101 } 102 103 110 public Identifier resolveTypeIdent(Element context, Identifier original) { 111 117 return original; 119 } 120 121 public Node.Cookie findCookie(Element el, Class requested) { 122 Node.Cookie lookup = null; 123 124 if (el instanceof SourceElement) 125 return jdo.getCookie(requested); 128 if (requested == OpenCookie.class) { 129 lookup = lookupCookie(el, requested); 130 if (lookup != null) 131 return lookup; 132 lookup = createOpenCookie(el); 133 } else { 134 return jdo.getCookie(requested); 135 } 136 return lookup; 137 } 138 139 protected OpenCookie createOpenCookie(Element el) { 140 ElementImpl impl = (ElementImpl)el.getCookie(ElementImpl.class); 141 OpenCookie ck = new OpenCookieImpl(impl); 142 return ck; 143 } 144 145 private Node.Cookie lookupCookie(Element el, Class clazz) { 146 synchronized (cookieMap) { 147 Object o = cookieMap.get(el); 148 if (o == null) 149 return null; 150 151 if (o instanceof CookieSet) 152 return ((CookieSet)o).getCookie(clazz); 153 154 if (o.getClass().isAssignableFrom(clazz)) 155 return (Node.Cookie)o; 156 return null; 157 } 158 } 159 160 162 private class OpenCookieImpl implements OpenCookie, Runnable { 163 164 RefObject refObject; 165 166 OpenCookieImpl(ElementImpl impl) { 167 refObject = impl.getJavaElement (); 168 } 169 170 public void open() { 171 org.openide.util.Mutex.EVENT.postReadRequest(this); 174 } 175 176 public void run() { 177 try { 178 PositionBounds bounds = JavaMetamodel.getManager().getElementPosition((org.netbeans.jmi.javamodel.Element) refObject); 179 if (bounds == null) 180 return; 181 ((JavaEditor) jdo.getCookie(JavaEditor.class)).openAt(bounds.getBegin()); 182 } catch (javax.jmi.reflect.InvalidObjectException e) { 183 } 184 } 185 } 186 187 } 188 | Popular Tags |