for (Annotation current : scopeFileAnnotationList)
{
if (current instanceof ScopeAnnotation)
{
ScopeAnnotation scope = (ScopeAnnotation)current;
int scopeId = scope.getScopeId();
scopeIdMap.put(scopeId, scope);
} else if (current instanceof CueAnnotation)
{
CueAnnotation cue = (CueAnnotation)current;
int scopeIdForThisCue = cue.getScopeIdReference();
cueForScopeIdMap.put(scopeIdForThisCue, cue);
}
}
for (Entry<Integer, ScopeAnnotation> current : scopeIdMap.entrySet())
{
int currentId = current.getKey();
ScopeAnnotation scope = current.getValue();
CueAnnotation cue = cueForScopeIdMap.get(currentId);
scope.setCueForScope(cue);
}
//For testing -Alex Yeh
// logger.info(String.format("CUES for SCOPES in FILE %s%n", textFilename);
// logger.info(String.format(" MAP size: %s.%n", scopeIdMap.entrySet().size());
// for (Entry<Integer, ScopeAnnotation> current : scopeIdMap.entrySet())
// {
// ScopeAnnotation scope = current.getValue();
// logger.info(String.format(" Scope: %s%n => Cue: %s%n", scope.toString(), scope.getCueForScope().toString());
// }
//Find enclosing scopes for each assertion annotation
//List<Annotation> assertionFileAnnotationList = annotationsByType.get(AnnotationType.ASSERTION);
List<Annotation> assertionFileAnnotationList = assertionList;
// logger.info(String.format("ASSERTIONS for FILE %s%n", textFilename); //For testing
for (Annotation current : assertionFileAnnotationList)
{
Location annotationBegin = current.getBegin();
int beginLine = annotationBegin.getLine();
int beginTokenOffset = annotationBegin.getTokenOffset();
Location annotationEnd = current.getEnd();
// Assume that 'annotationEnd.getLine()' will return the same line number as 'beginLine'
int endTokenOffset = annotationEnd.getTokenOffset();
List<Annotation> annotationsForFirstToken = indexer.findAnnotationsForPosition(beginLine, beginTokenOffset);
List<ScopeAnnotation> enclosingScopesFound = new ArrayList<ScopeAnnotation>();
AssertionAnnotation assertion = (AssertionAnnotation)current;
// logger.info(String.format(" ASRT: %s => %s annotations for 1st token%n", assertion.toString(), annotationsForFirstToken.size()); //for testing
for (Annotation annotationForFirstToken : annotationsForFirstToken)
{
if ((annotationForFirstToken instanceof ScopeAnnotation) &&
(endTokenOffset <= annotationForFirstToken.getEnd().getTokenOffset()))
{
//This annotation containing the first token of the current assertion annotation
// is a ScopeAnnotation that contains all the tokens of the current assertion annotation.
//Add it to the list of enclosing scopes.
ScopeAnnotation scope = (ScopeAnnotation)annotationForFirstToken;
enclosingScopesFound.add(scope);
}
}
assertion.setEnclosingScopes(enclosingScopesFound);
}