Lines 83-91
Link Here
|
83 |
// below to the AjState for a compilation and recover it if switching |
83 |
// below to the AjState for a compilation and recover it if switching |
84 |
// between projects. |
84 |
// between projects. |
85 |
protected IHierarchy hierarchy; |
85 |
protected IHierarchy hierarchy; |
86 |
|
86 |
|
87 |
/* Map from String > String - it maps absolute paths for |
87 |
/* |
88 |
* inpath dirs/jars to workspace relative paths suitable for handle inclusion */ |
88 |
* Map from String > String - it maps absolute paths for inpath dirs/jars to workspace relative paths suitable for handle |
|
|
89 |
* inclusion |
90 |
*/ |
89 |
protected Map inpathMap; |
91 |
protected Map inpathMap; |
90 |
private IRelationshipMap mapper; |
92 |
private IRelationshipMap mapper; |
91 |
private IElementHandleProvider handleProvider; |
93 |
private IElementHandleProvider handleProvider; |
Lines 654-669
Link Here
|
654 |
|
656 |
|
655 |
} |
657 |
} |
656 |
|
658 |
|
657 |
private String getTypeNameFromHandle(String handle,Map cache) { |
659 |
private String getTypeNameFromHandle(String handle, Map cache) { |
658 |
String typename = (String)cache.get(handle); |
660 |
String typename = (String) cache.get(handle); |
659 |
if (typename!=null) { |
661 |
if (typename != null) { |
660 |
return typename; |
662 |
return typename; |
661 |
} |
663 |
} |
662 |
// inpath handle - but for which type? |
664 |
// inpath handle - but for which type? |
663 |
// let's do it the slow way, we can optimize this with a cache perhaps |
665 |
// let's do it the slow way, we can optimize this with a cache perhaps |
664 |
int hasPackage = handle.indexOf('<'); |
666 |
int hasPackage = handle.indexOf('<'); |
665 |
int typeLocation = handle.indexOf('['); |
667 |
int typeLocation = handle.indexOf('['); |
666 |
if (typeLocation==-1) { |
668 |
if (typeLocation == -1) { |
667 |
typeLocation = handle.indexOf('}'); |
669 |
typeLocation = handle.indexOf('}'); |
668 |
} |
670 |
} |
669 |
if (typeLocation == -1) { |
671 |
if (typeLocation == -1) { |
Lines 671-685
Link Here
|
671 |
return ""; |
673 |
return ""; |
672 |
} |
674 |
} |
673 |
StringBuffer qualifiedTypeNameFromHandle = new StringBuffer(); |
675 |
StringBuffer qualifiedTypeNameFromHandle = new StringBuffer(); |
674 |
if (hasPackage!=-1) { |
676 |
if (hasPackage != -1) { |
675 |
qualifiedTypeNameFromHandle.append(handle.substring(hasPackage+1,handle.indexOf('(',hasPackage))); |
677 |
qualifiedTypeNameFromHandle.append(handle.substring(hasPackage + 1, handle.indexOf('(', hasPackage))); |
676 |
qualifiedTypeNameFromHandle.append('.'); |
678 |
qualifiedTypeNameFromHandle.append('.'); |
677 |
} |
679 |
} |
678 |
qualifiedTypeNameFromHandle.append(handle.substring(typeLocation+1)); |
680 |
qualifiedTypeNameFromHandle.append(handle.substring(typeLocation + 1)); |
679 |
typename = qualifiedTypeNameFromHandle.toString(); |
681 |
typename = qualifiedTypeNameFromHandle.toString(); |
680 |
cache.put(handle,typename); |
682 |
cache.put(handle, typename); |
681 |
return typename; |
683 |
return typename; |
682 |
} |
684 |
} |
|
|
685 |
|
683 |
/** |
686 |
/** |
684 |
* two kinds of relationships |
687 |
* two kinds of relationships |
685 |
* |
688 |
* |
Lines 726-732
Link Here
|
726 |
if (isPhantomHandle(hid)) { |
729 |
if (isPhantomHandle(hid)) { |
727 |
// inpath handle - but for which type? |
730 |
// inpath handle - but for which type? |
728 |
// TODO promote cache for reuse during one whole model update |
731 |
// TODO promote cache for reuse during one whole model update |
729 |
if (!getTypeNameFromHandle(hid,handleToTypenameCache).equals(typename)) { |
732 |
if (!getTypeNameFromHandle(hid, handleToTypenameCache).equals(typename)) { |
730 |
continue; |
733 |
continue; |
731 |
} |
734 |
} |
732 |
} |
735 |
} |
Lines 805-811
Link Here
|
805 |
// they need removing |
808 |
// they need removing |
806 |
for (Iterator targetsIter = targets.iterator(); targetsIter.hasNext();) { |
809 |
for (Iterator targetsIter = targets.iterator(); targetsIter.hasNext();) { |
807 |
String targethid = (String) targetsIter.next(); |
810 |
String targethid = (String) targetsIter.next(); |
808 |
if (isPhantomHandle(hid) && !getTypeNameFromHandle(hid,handleToTypenameCache).equals(typename)) { |
811 |
if (isPhantomHandle(hid) && !getTypeNameFromHandle(hid, handleToTypenameCache).equals(typename)) { |
809 |
continue; |
812 |
continue; |
810 |
} |
813 |
} |
811 |
// Does this point to the same type? |
814 |
// Does this point to the same type? |
Lines 910-922
Link Here
|
910 |
} |
913 |
} |
911 |
return (type.equals(containingType)); |
914 |
return (type.equals(containingType)); |
912 |
} |
915 |
} |
913 |
|
916 |
|
914 |
/** |
917 |
/** |
915 |
* @param handle a JDT like handle, following the form described in AsmRelationshipProvider.findOrFakeUpNode |
918 |
* @param handle a JDT like handle, following the form described in AsmRelationshipProvider.findOrFakeUpNode |
916 |
* @return true if the handle contains ';' - the char indicating that it is a phantom handle |
919 |
* @return true if the handle contains ';' - the char indicating that it is a phantom handle |
917 |
*/ |
920 |
*/ |
918 |
private boolean isPhantomHandle(String handle) { |
921 |
private boolean isPhantomHandle(String handle) { |
919 |
return handle.indexOf(HandleProviderDelimiter.PHANTOM.getDelimiter())!=-1; |
922 |
return handle.indexOf(HandleProviderDelimiter.PHANTOM.getDelimiter()) != -1; |
920 |
} |
923 |
} |
921 |
|
924 |
|
922 |
/** |
925 |
/** |
Lines 1307-1313
Link Here
|
1307 |
} |
1310 |
} |
1308 |
|
1311 |
|
1309 |
public String getHandleElementForInpath(String binaryPath) { |
1312 |
public String getHandleElementForInpath(String binaryPath) { |
1310 |
return (String)inpathMap.get(new File(binaryPath)); |
1313 |
return (String) inpathMap.get(new File(binaryPath)); |
|
|
1314 |
} |
1315 |
|
1316 |
private List pieces = new ArrayList(); |
1317 |
|
1318 |
private Object intern(String substring) { |
1319 |
int lastIdx = -1; |
1320 |
if ((lastIdx = substring.lastIndexOf('/')) != -1) { |
1321 |
String pkg = substring.substring(0, lastIdx); |
1322 |
String type = substring.substring(lastIdx + 1); |
1323 |
pkg = internOneThing(pkg); |
1324 |
type = internOneThing(type); |
1325 |
return new String[] { pkg, type }; |
1326 |
} else { |
1327 |
return internOneThing(substring); |
1328 |
} |
1311 |
} |
1329 |
} |
1312 |
|
1330 |
|
|
|
1331 |
private String internOneThing(String substring) { |
1332 |
// simple name |
1333 |
for (int p = 0, max = pieces.size(); p < max; p++) { |
1334 |
String s = (String) pieces.get(p); |
1335 |
if (s.equals(substring)) { |
1336 |
return s; |
1337 |
} |
1338 |
} |
1339 |
pieces.add(substring); |
1340 |
return substring; |
1341 |
} |
1342 |
|
1343 |
/** |
1344 |
* What we can rely on: <br> |
1345 |
* - it is a method signature of the form (La/B;Lc/D;)LFoo;<br> |
1346 |
* - there are no generics<br> |
1347 |
* |
1348 |
* What we must allow for: - may use primitive refs (single chars rather than L) |
1349 |
*/ |
1350 |
/* |
1351 |
public List compress(String s) { |
1352 |
int openParen = 0; |
1353 |
int closeParen = s.indexOf(')'); |
1354 |
int pos = 1; |
1355 |
List compressed = new ArrayList(); |
1356 |
// do the parens |
1357 |
while (pos < closeParen) { |
1358 |
char ch = s.charAt(pos); |
1359 |
if (ch == 'L') { |
1360 |
int idx = s.indexOf(';', pos); |
1361 |
compressed.add(intern(s.substring(pos + 1, idx))); |
1362 |
pos = idx + 1; |
1363 |
} else if (ch == '[') { |
1364 |
int x = pos; |
1365 |
while (s.charAt(++pos) == '[') |
1366 |
; |
1367 |
// now pos will point at something not an array |
1368 |
compressed.add(intern(s.substring(x, pos))); // intern the [[[[[[ |
1369 |
char ch2 = s.charAt(pos); |
1370 |
if (ch2 == 'L') { |
1371 |
int idx = s.indexOf(';', pos); |
1372 |
compressed.add(intern(s.substring(pos + 1, idx))); |
1373 |
pos = idx + 1; |
1374 |
} else if (ch2 == 'T') { |
1375 |
int idx = s.indexOf(';'); |
1376 |
compressed.add(intern(s.substring(pos, idx + 1))); // should be TT; |
1377 |
pos = idx + 1; |
1378 |
} else { |
1379 |
compressed.add(toCharacter(s.charAt(pos))); |
1380 |
pos++; |
1381 |
} |
1382 |
} else { |
1383 |
// it is a primitive ref (SVBCZJ) |
1384 |
compressed.add(toCharacter(ch)); |
1385 |
pos++; |
1386 |
} |
1387 |
} |
1388 |
// do the return type |
1389 |
pos++; |
1390 |
char ch = s.charAt(pos); |
1391 |
if (ch == 'L') { |
1392 |
int idx = s.indexOf(';', pos); |
1393 |
compressed.add(intern(s.substring(pos, idx))); |
1394 |
} else if (ch == '[') { |
1395 |
int x = pos; |
1396 |
while (s.charAt(++pos) == '[') |
1397 |
; |
1398 |
// now pos will point at something not an array |
1399 |
compressed.add(intern(s.substring(x, pos))); // intern the [[[[[[ |
1400 |
char ch2 = s.charAt(pos); |
1401 |
if (ch2 == 'L') { |
1402 |
int idx = s.indexOf(';', pos); |
1403 |
compressed.add(intern(s.substring(pos + 1, idx))); |
1404 |
pos = idx + 1; |
1405 |
} else if (ch2 == 'T') { |
1406 |
int idx = s.indexOf(';'); |
1407 |
compressed.add(intern(s.substring(pos, idx + 1))); // should be TT; |
1408 |
pos = idx + 2; |
1409 |
} else { |
1410 |
compressed.add(toCharacter(s.charAt(pos))); |
1411 |
pos++; |
1412 |
} |
1413 |
} else { |
1414 |
// it is a primitive ref (SVBCZJ) |
1415 |
compressed.add(new Character(ch)); |
1416 |
} |
1417 |
return compressed; |
1418 |
|
1419 |
// char delimiter = '/'; |
1420 |
// int pos = -1; |
1421 |
// List compressed = new ArrayList(); |
1422 |
// int start = 0; |
1423 |
// while ((pos = s.indexOf(delimiter, start)) != -1) { |
1424 |
// String part = s.substring(start, pos); |
1425 |
// int alreadyRecorded = pieces.indexOf(part); |
1426 |
// if (alreadyRecorded != -1) { |
1427 |
// compressed.add(new Integer(alreadyRecorded)); |
1428 |
// } else { |
1429 |
// compressed.add(new Integer(pieces.size())); |
1430 |
// pieces.add(part); |
1431 |
// } |
1432 |
// start = pos + 1; |
1433 |
// } |
1434 |
// // last piece |
1435 |
// String part = s.substring(start, s.length()); |
1436 |
// int alreadyRecorded = pieces.indexOf(part); |
1437 |
// if (alreadyRecorded != -1) { |
1438 |
// compressed.add(youkirtyounew Integer(alreadyRecorded)); |
1439 |
// } else { |
1440 |
// compressed.add(new Integer(pieces.size())); |
1441 |
// pieces.add(part); |
1442 |
// } |
1443 |
// return compressed; |
1444 |
} |
1445 |
|
1446 |
static final Character charB = new Character('B'); |
1447 |
static final Character charS = new Character('S'); |
1448 |
static final Character charI = new Character('I'); |
1449 |
static final Character charF = new Character('F'); |
1450 |
static final Character charD = new Character('D'); |
1451 |
static final Character charJ = new Character('J'); |
1452 |
static final Character charC = new Character('C'); |
1453 |
static final Character charV = new Character('V'); |
1454 |
static final Character charZ = new Character('Z'); |
1455 |
|
1456 |
private Character toCharacter(char ch) { |
1457 |
switch (ch) { |
1458 |
case 'B': |
1459 |
return charB; |
1460 |
case 'S': |
1461 |
return charS; |
1462 |
case 'I': |
1463 |
return charI; |
1464 |
case 'F': |
1465 |
return charF; |
1466 |
case 'D': |
1467 |
return charD; |
1468 |
case 'J': |
1469 |
return charJ; |
1470 |
case 'C': |
1471 |
return charC; |
1472 |
case 'V': |
1473 |
return charV; |
1474 |
case 'Z': |
1475 |
return charZ; |
1476 |
default: |
1477 |
throw new IllegalStateException(new Character(ch).toString()); |
1478 |
} |
1479 |
} |
1480 |
|
1481 |
public String decompress(List refs, char delimiter) { |
1482 |
StringBuilder result = new StringBuilder(); |
1483 |
result.append("("); |
1484 |
for (int i = 0, max = refs.size() - 1; i < max; i++) { |
1485 |
result.append(unintern(refs.get(i))); |
1486 |
} |
1487 |
result.append(")"); |
1488 |
result.append(unintern(refs.get(refs.size() - 1))); |
1489 |
return result.toString(); |
1490 |
} |
1491 |
|
1492 |
private String unintern(Object o) { |
1493 |
if (o instanceof Character) { |
1494 |
return ((Character) o).toString(); |
1495 |
} else if (o instanceof String[]) { |
1496 |
String[] strings = (String[]) o; |
1497 |
StringBuilder sb = new StringBuilder(); |
1498 |
sb.append('L'); |
1499 |
sb.append(strings[0]).append('/').append(strings[1]); |
1500 |
sb.append(';'); |
1501 |
return sb.toString(); |
1502 |
} else { // String |
1503 |
String so = (String) o; |
1504 |
if (so.endsWith(";")) { |
1505 |
// will be TT; |
1506 |
return so; |
1507 |
} else { |
1508 |
StringBuilder sb = new StringBuilder(); |
1509 |
sb.append('L'); |
1510 |
sb.append(so); |
1511 |
sb.append(';'); |
1512 |
return sb.toString(); |
1513 |
} |
1514 |
} |
1515 |
} |
1516 |
*/ |
1313 |
} |
1517 |
} |