Changeset 3288
- Timestamp:
- 01/05/09 10:11:11 (10 months ago)
- Location:
- trunk/ProjectFortress/src/com/sun/fortress
- Files:
-
- 3 modified
-
nodes_util/NodeComparator.java (modified) (1 diff)
-
repository/ForeignJava.java (modified) (5 diffs)
-
repository/GraphRepository.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeComparator.java
r3286 r3288 1 1 /******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. -
trunk/ProjectFortress/src/com/sun/fortress/repository/ForeignJava.java
r3284 r3288 46 46 import com.sun.fortress.nodes.Param; 47 47 import com.sun.fortress.nodes.StaticParam; 48 import com.sun.fortress.nodes.TraitDecl; 48 49 import com.sun.fortress.nodes.TraitObjectDecl; 49 50 import com.sun.fortress.nodes.TraitTypeWhere; … … 63 64 public class ForeignJava { 64 65 65 /** given an API Name, what Java class does it import? (Name of existing66 /** given an API Name, what Java classes does it import? (Name of existing 66 67 * Java class, not its wrapper.) 67 68 */ 68 69 MultiMap<APIName, Class> javaImplementedAPIs = new MultiMap<APIName, Class>(); 70 71 /** 72 * Given a foreign API Name, what other (foreign) APIs does it import? 73 */ 69 74 MultiMap<APIName, APIName> generatedImports = new MultiMap<APIName, APIName>(); 70 75 … … 84 89 MultiMap<Class, String> itemsFromClasses = new MultiMap<Class, String>(); 85 90 91 Map<APIName, ApiIndex> cachedFakeApis = new HashMap<APIName, ApiIndex>(); 92 93 /** 94 * Stores the FnDecl for a particular method -- also acts as an is-visited 95 * marker. 96 */ 86 97 Bijection<Method, FnDecl> methodToDecl = new HashBijection<Method, FnDecl>(); 87 Bijection<Class, TraitObjectDecl> classToTraitDecl = new HashBijection<Class, TraitObjectDecl>(); 98 99 /** 100 * Stores the TraitDecl for a trait. 101 */ 102 Bijection<Class, TraitDecl> classToTraitDecl = new HashBijection<Class, TraitDecl>(); 88 103 89 104 /* Special cases … … 275 290 List<BaseType> excludesC = Collections.emptyList(); 276 291 Option<List<BaseType>> comprisesC = Option.none(); 277 Trait ObjectDecl tod = NodeFactory.makeTraitDecl (span, mods, name, sparams, extendsC, whereC, decls, excludesC, comprisesC);292 TraitDecl td = NodeFactory.makeTraitDecl (span, mods, name, sparams, extendsC, whereC, decls, excludesC, comprisesC); 278 293 // Need to fake up an API for this class, too. 279 classToTraitDecl.put(imported_class, t od);280 apiToStaticDecls.putItem(api_name, t od);294 classToTraitDecl.put(imported_class, td); 295 apiToStaticDecls.putItem(api_name, td); 281 296 javaImplementedAPIs.putItem(api_name, imported_class); 297 298 /* Invalidate any old entry. 299 * Let's hope this does not cause problems down the line. 300 */ 301 cachedFakeApis.remove(api_name); 282 302 } 283 303 … … 366 386 367 387 public ApiIndex fakeApi(APIName name) { 368 Set<Class> classes = javaImplementedAPIs.get(name); 369 // Need to generate wrappers for all these classes, 370 // if they do not already exist. 371 372 List<Import> imports = new ArrayList<Import>(); 373 for (APIName a : generatedImports.get(name)) { 374 AliasedAPIName aan = NodeFactory.makeAliasedAPIName(a); 375 /* 376 * Hoping to lie, slightly, to static analysis. 377 * This is technically speaking a "foreign" import, 378 * but the import is already known to the ForeignJava 379 * data structures, and this allows use of fully qualified 380 * (hence unambiguous) references to classes from other packages 381 * in the generated API. 382 * 383 * So, one lie -- no foreign annotation. 384 */ 385 ImportApi iapi = NodeFactory.makeImportApi(span, Option.<String>none(), Useful.list(aan)); 386 imports.add(iapi); 388 ApiIndex result = cachedFakeApis.get(name); 389 if (result == null) { 390 391 Set<Class> classes = javaImplementedAPIs.get(name); 392 // Need to generate wrappers for all these classes, 393 // if they do not already exist. 394 395 List<Import> imports = new ArrayList<Import>(); 396 Set<APIName> gi = generatedImports.get(name); 397 if (gi != null) 398 for (APIName a : gi) { 399 AliasedAPIName aan = NodeFactory.makeAliasedAPIName(a); 400 /* 401 * Hoping to lie, slightly, to static analysis. This is 402 * technically speaking a "foreign" import, but the import is 403 * already known to the ForeignJava data structures, and this 404 * allows use of fully qualified (hence unambiguous) references 405 * to classes from other packages in the generated API. 406 * 407 * So, one lie -- no foreign annotation. 408 */ 409 ImportApi iapi = NodeFactory.makeImportApi(span, Option 410 .<String> none(), Useful.list(aan)); 411 imports.add(iapi); 412 } 413 414 List<Decl> decls = new ArrayList<Decl>(); 415 for (Decl d : apiToStaticDecls.get(name)) { 416 decls.add(d); 417 } 418 Api a = NodeFactory.makeApi(span, name, imports, decls); 419 420 result = IndexBuilder.builder.buildApiIndex(a, Long.MIN_VALUE + 2); 421 cachedFakeApis.put(name, result); 387 422 } 388 389 List<Decl> decls = new ArrayList<Decl>(); 390 for (Decl d : apiToStaticDecls.get(name)) { 391 decls.add(d); 423 return result; 424 425 } 426 427 public Map<APIName, ApiIndex> augmentApiMap(Map<APIName, ApiIndex> map) { 428 for (APIName a : javaImplementedAPIs.keySet()) { 429 map.put(a, fakeApi(a)); 392 430 } 393 Api a = NodeFactory.makeApi( span, name, 394 imports, 395 decls); 396 397 return IndexBuilder.builder.buildApiIndex(a, Long.MIN_VALUE+2); 398 431 return map; 399 432 } 400 433 -
trunk/ProjectFortress/src/com/sun/fortress/repository/GraphRepository.java
r3283 r3288 158 158 @Override 159 159 public Map<APIName, ApiIndex> apis() { 160 return cache.apis();160 return foreignJava.augmentApiMap(cache.apis.copy()); 161 161 } 162 162

