private void cleanBundle(String bundle) { String scriptText = getText(); Lexer lexer = getLexer(); Iterable<Token> tokens = lexer.getTokens(scriptText); List<String> usedImages = new ArrayList<String>(); boolean inString = false; String current; for (Token t : tokens) { current = t.getValue(); if (t.getType() == TokenType.Comment) { cleanBundleCheckComments(lexer, t.getValue().substring(1), usedImages); continue; } if (t.getType() == TokenType.String_Doc) { cleanBundleCheckComments( lexer, t.getValue().substring(3, t.getValue().length() - 3), usedImages); continue; } if (!inString) { if (!current.isEmpty() && "'\"".contains(current)) { inString = true; } continue; } if (!current.isEmpty() && "'\"".contains(current)) { inString = false; continue; } cleanBundleIsImageUsed(current, usedImages); } if (usedImages.isEmpty()) { return; } FileManager.deleteNotUsedImages(bundle, usedImages); }