@Override protected void repairBug(ASTRewrite rewrite, CompilationUnit workingUnit, BugInstance bug) throws BugResolutionException { ASTNode node = getASTNode(workingUnit, bug.getPrimarySourceLineAnnotation()); node = TraversalUtil.backtrackToBlock(node); StringToCharVisitor visitor = new StringToCharVisitor(); node.accept(visitor); AST ast = rewrite.getAST(); if (useStringBuilder) { MethodInvocation toString = buildChainedToString(rewrite, visitor, ast); rewrite.replace(visitor.infixExpression, toString, null); } else { handleSimpleConcat(rewrite, visitor, ast); } // replaces all non-concatenation StringLiterals for (Map.Entry<StringLiteral, Character> entry : visitor.replacements.entrySet()) { CharacterLiteral charLiteral = ast.newCharacterLiteral(); charLiteral.setCharValue(entry.getValue()); rewrite.replace(entry.getKey(), charLiteral, null); } }
@Override public boolean match(CharacterLiteral node, Object other) { if (!(other instanceof CharacterLiteral)) { return false; } CharacterLiteral o = (CharacterLiteral) other; return safeRenamedEquals(node.getEscapedValue(), o.getEscapedValue(), oldName, newName); }
private VariableReference retrieveVariableReference(CharacterLiteral characterLiteral) { char character = characterLiteral.charValue(); PrimitiveStatement<Character> charAssignment = new CharPrimitiveStatement( testCase.getReference(), character); testCase.addStatement(charAssignment); return charAssignment.getReturnValue(); }
private static Expression fixSingleLengthString(Expression expr, AST ast) { if (expr instanceof StringLiteral) { String literalValue = ((StringLiteral) expr).getLiteralValue(); if (literalValue.length() == 1) { CharacterLiteral charLiteral = ast.newCharacterLiteral(); charLiteral.setCharValue(literalValue.charAt(0)); return charLiteral; } } return expr; }
@Override public boolean visit(CharacterLiteral node) { String chr = node.getEscapedValue(); // It would seem a lot of the text manipulation stuff // in java uses invalid unicode characters, so we use // this hack to get around it. if (chr.startsWith("'\\u")) { chr = "0x" + chr.substring(3, chr.length() - 1); } print(chr); return false; }
@Override public void endVisit(CharacterLiteral node) { // Leaf node. }
@Override public void endVisit(CharacterLiteral node) { ITypeBinding typeBinding = node.resolveTypeBinding(); ImmutableTypeVariable2 cv = fTCModel.makeImmutableTypeVariable(typeBinding, node); setConstraintVariable(node, cv); }
@Override public boolean visit(CharacterLiteral node) { return visitLiteral(node); }
private static String getEscapedCharacterLiteral(char ch) { CharacterLiteral characterLiteral= AST.newAST(AST.JLS8).newCharacterLiteral(); characterLiteral.setCharValue(ch); return characterLiteral.getEscapedValue(); }
/** {@inheritDoc} */ @Override public void endVisit(CharacterLiteral node) { logger.warn("Method endVisitCharacterLiteral for " + node + " for " + node + " not implemented!"); super.endVisit(node); }
/** {@inheritDoc} */ @Override public boolean visit(CharacterLiteral node) { logger.warn("Method visitCharacterLiteral for " + node + " for " + node + " not implemented!"); return super.visit(node); }
@Override public boolean visit(final CharacterLiteral node) { return false; }
@Override public boolean visit(final CharacterLiteral node) { // not instrumentable, contains no instrumentable nodes return false; }
@Override public void endVisit(CharacterLiteral node) { ITypeBinding typeBinding= node.resolveTypeBinding(); ImmutableTypeVariable2 cv= fTCModel.makeImmutableTypeVariable(typeBinding, node); setConstraintVariable(node, cv); }
@Override public boolean visit(CharacterLiteral node) { if (node.subtreeMatch(fMatcher, fNodeToMatch)) return matches(node); return super.visit(node); }
@Override public boolean visit(CharacterLiteral node) { add(fCreator.create(node)); return true; }
@Override public void endVisit(CharacterLiteral node) { endVisitNode(node); }
@Override public boolean visit(CharacterLiteral node) { return visitNode(node); }
@Override public boolean visit(MethodInvocation node) { IMethodBinding iMethod = (IMethodBinding) node.resolveMethodBinding(); IMethodBinding methodDeclarationCandidate = iMethod.getMethodDeclaration(); if (check(methodDeclarationCandidate)) { // Delete node with expression (i.e.: ClassName.methodname()) if (null != node.getExpression()) { node.getParent().delete(); } else { if (null != replacement) { if (node.getParent().getNodeType() == ASTNode.VARIABLE_DECLARATION_FRAGMENT) { VariableDeclarationFragment fragment = (VariableDeclarationFragment) node.getParent(); Expression expression = null; Type type = methodDeclaration.getReturnType2(); int exprType = determineType(type); switch (exprType) { case Expression.NUMBER_LITERAL: expression = fragment.getAST().newNumberLiteral(String.valueOf(replacement)); break; case Expression.STRING_LITERAL: expression = fragment.getAST().newStringLiteral(); ((StringLiteral) expression).setLiteralValue(String.valueOf(replacement)); break; case Expression.BOOLEAN_LITERAL: expression = fragment.getAST().newBooleanLiteral(Boolean.valueOf(replacement.toString())); break; case Expression.CHARACTER_LITERAL: expression = fragment.getAST().newCharacterLiteral(); String string = String.valueOf(replacement); if (string.length() != 1) { logger.warn(string + " contains more then one character. Cutting the string of at " + string.charAt(0)); } char c = string.charAt(0); ((CharacterLiteral) expression).setCharValue(Character.valueOf(c)); break; case Expression.NULL_LITERAL: expression = fragment.getAST().newNullLiteral(); break; case Expression.TYPE_LITERAL: expression = fragment.getAST().newTypeLiteral(); break; default: logger.error("Type '" + type + "' not supported yet..."); break; } if (expression != null) { fragment.setInitializer(expression); } } } else { node.delete(); } } hasBeenDeleted = true; } return false; }
@Override public boolean visit(CharacterLiteral node) { return visit((Expression)node); }
@Override public void endVisit(CharacterLiteral node) { endVisit((Expression)node); }
@Override public boolean visit(CharacterLiteral node) { this.fBuffer.append(node.getEscapedValue()); return false; }
public boolean visit(CharacterLiteral node) { this.buffer.append(node.getEscapedValue()); return false; }
@Override public boolean visit(final CharacterLiteral node) { return this.internalVisit(node); }
/** * Escapes a character value to a literal that can be used in Java source. * * @param ch the character value * @return the escaped string * @see org.eclipse.jdt.core.dom.CharacterLiteral#getEscapedValue() */ public static String getEscapedCharacterLiteral(char ch) { CharacterLiteral characterLiteral = AST.newAST(ASTProvider.SHARED_AST_LEVEL).newCharacterLiteral(); characterLiteral.setCharValue(ch); return characterLiteral.getEscapedValue(); }
/** * Escapes a character value to a literal that can be used in Java source. * * @param ch the character value * @return the escaped string * @see CharacterLiteral#getEscapedValue() */ public static String getEscapedCharacterLiteral(char ch) { CharacterLiteral characterLiteral= AST.newAST(IASTSharedValues.SHARED_AST_LEVEL).newCharacterLiteral(); characterLiteral.setCharValue(ch); return characterLiteral.getEscapedValue(); }
/** * @param node the AST node * @return array of type constraints, may be empty * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.CharacterLiteral) */ public ITypeConstraint[] create(CharacterLiteral node) { return EMPTY_ARRAY; }
/** * Escapes a character value to a literal that can be used in Java source. * * @param ch the character value * @return the escaped string * @see CharacterLiteral#getEscapedValue() */ public static String getEscapedCharacterLiteral(char ch) { CharacterLiteral characterLiteral= AST.newAST(ASTProvider.SHARED_AST_LEVEL).newCharacterLiteral(); characterLiteral.setCharValue(ch); return characterLiteral.getEscapedValue(); }