if (project == null)
project = getWalker().getProject();
FlexJSProject flexProject = (FlexJSProject) project;
ASProjectScope projectScope = (ASProjectScope) flexProject.getScope();
ICompilationUnit cu = projectScope
.getCompilationUnitForDefinition(type);
ArrayList<String> requiresList = flexProject.getRequires(cu);
ArrayList<String> interfacesList = flexProject.getInterfaces(cu);
String cname = type.getQualifiedName();
ArrayList<String> writtenInstances = new ArrayList<String>();
writtenInstances.add(cname); // make sure we don't add ourselves
boolean emitsRequires = false;
if (requiresList != null)
{
for (String imp : requiresList)
{
if (imp.indexOf(JSGoogEmitterTokens.AS3.getToken()) != -1)
continue;
if (imp.equals(cname))
continue;
if (NativeUtils.isNative(imp))
continue;
if (writtenInstances.indexOf(imp) == -1)
{
/* goog.require('x');\n */
write(JSGoogEmitterTokens.GOOG_REQUIRE);
write(ASEmitterTokens.PAREN_OPEN);
write(ASEmitterTokens.SINGLE_QUOTE);
write(imp);
write(ASEmitterTokens.SINGLE_QUOTE);
write(ASEmitterTokens.PAREN_CLOSE);
writeNewline(ASEmitterTokens.SEMICOLON);
writtenInstances.add(imp);
emitsRequires = true;
}
}
}
boolean emitsInterfaces = false;
if (interfacesList != null)
{
for (String imp : interfacesList)
{
write(JSGoogEmitterTokens.GOOG_REQUIRE);
write(ASEmitterTokens.PAREN_OPEN);
write(ASEmitterTokens.SINGLE_QUOTE);
write(imp);
write(ASEmitterTokens.SINGLE_QUOTE);
write(ASEmitterTokens.PAREN_CLOSE);
writeNewline(ASEmitterTokens.SEMICOLON);
emitsInterfaces = true;
}
}
// erikdebruin: Add missing language feature support, with e.g. 'is' and
// 'as' operators. We don't need to worry about requiring
// this in every project: ADVANCED_OPTIMISATIONS will NOT
// include any of the code if it is not used in the project.
boolean isMainCU = flexProject.mainCU != null &&
cu.getName().equals(flexProject.mainCU.getName());
if (isMainCU)
{
write(JSGoogEmitterTokens.GOOG_REQUIRE);
write(ASEmitterTokens.PAREN_OPEN);
write(ASEmitterTokens.SINGLE_QUOTE);