org.eclipse.jdt.core.dom.CharacterLiteral Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.CharacterLiteral. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SwitchControlCase.java    From JDeodorant with MIT License 6 votes vote down vote up
private String getLiteralValue(Expression expression)
{
	if (expression instanceof NumberLiteral)
	{
		return ((NumberLiteral)expression).getToken();
	}
	else if (expression instanceof CharacterLiteral)
	{
		return String.valueOf(((CharacterLiteral)expression).charValue());
	}
	else if (expression instanceof StringLiteral)
	{
		return ((StringLiteral)expression).getLiteralValue();
	}
	else
	{
		return null;
	}
}
 
Example #2
Source File: ASTNodeMatcher.java    From JDeodorant with MIT License 6 votes vote down vote up
protected boolean isTypeHolder(Object o) {
	if(o.getClass().equals(MethodInvocation.class) || o.getClass().equals(SuperMethodInvocation.class)			
			|| o.getClass().equals(NumberLiteral.class) || o.getClass().equals(StringLiteral.class)
			|| o.getClass().equals(CharacterLiteral.class) || o.getClass().equals(BooleanLiteral.class)
			|| o.getClass().equals(TypeLiteral.class) || o.getClass().equals(NullLiteral.class)
			|| o.getClass().equals(ArrayCreation.class)
			|| o.getClass().equals(ClassInstanceCreation.class)
			|| o.getClass().equals(ArrayAccess.class) || o.getClass().equals(FieldAccess.class)
			|| o.getClass().equals(SuperFieldAccess.class) || o.getClass().equals(ParenthesizedExpression.class)
			|| o.getClass().equals(SimpleName.class) || o.getClass().equals(QualifiedName.class)
			|| o.getClass().equals(CastExpression.class) || o.getClass().equals(InfixExpression.class)
			|| o.getClass().equals(PrefixExpression.class) || o.getClass().equals(InstanceofExpression.class)
			|| o.getClass().equals(ThisExpression.class) || o.getClass().equals(ConditionalExpression.class))
		return true;
	return false;
}
 
Example #3
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final CharacterLiteral node) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("Character.valueOf(");
  String _escapedValue = node.getEscapedValue();
  _builder.append(_escapedValue);
  _builder.append(").charValue");
  this.appendToBuffer(_builder.toString());
  return false;
}
 
Example #4
Source File: RenamedElementAstMatcher.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@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);
}
 
Example #5
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean visit(CharacterLiteral expr) {
	/*
	 * Character literal nodes
	 */
	StyledStringStyler styler = determineDiffStyle(expr, new StyledStringStyler(stringStyle));
	styledString.append(expr.getEscapedValue(), styler);
	return false;
}
 
Example #6
Source File: ExtractMethodFragmentRefactoring.java    From JDeodorant with MIT License 5 votes vote down vote up
protected Expression generateDefaultValue(ASTRewrite sourceRewriter, AST ast, ITypeBinding returnTypeBinding) {
	Expression returnedExpression = null;
	if(returnTypeBinding.isPrimitive()) {
		if(returnTypeBinding.getQualifiedName().equals("boolean")) {
			returnedExpression = ast.newBooleanLiteral(false);
		}
		else if(returnTypeBinding.getQualifiedName().equals("char")) {
			CharacterLiteral characterLiteral = ast.newCharacterLiteral();
			sourceRewriter.set(characterLiteral, CharacterLiteral.ESCAPED_VALUE_PROPERTY, "\u0000", null);
			returnedExpression = characterLiteral;
		}
		else if(returnTypeBinding.getQualifiedName().equals("int") ||
				returnTypeBinding.getQualifiedName().equals("short") ||
				returnTypeBinding.getQualifiedName().equals("byte")) {
			returnedExpression = ast.newNumberLiteral("0");
		}
		else if(returnTypeBinding.getQualifiedName().equals("long")) {
			returnedExpression = ast.newNumberLiteral("0L");
		}
		else if(returnTypeBinding.getQualifiedName().equals("float")) {
			returnedExpression = ast.newNumberLiteral("0.0f");
		}
		else if(returnTypeBinding.getQualifiedName().equals("double")) {
			returnedExpression = ast.newNumberLiteral("0.0d");
		}
		else if(returnTypeBinding.getQualifiedName().equals("void")) {
			returnedExpression = null;
		}
	}
	else {
		returnedExpression = ast.newNullLiteral();
	}
	return returnedExpression;
}
 
Example #7
Source File: PolymorphismRefactoring.java    From JDeodorant with MIT License 5 votes vote down vote up
protected Expression generateDefaultValue(ASTRewrite sourceRewriter, AST ast, ITypeBinding returnTypeBinding) {
	Expression returnedExpression = null;
	if(returnTypeBinding.isPrimitive()) {
		if(returnTypeBinding.getQualifiedName().equals("boolean")) {
			returnedExpression = ast.newBooleanLiteral(false);
		}
		else if(returnTypeBinding.getQualifiedName().equals("char")) {
			CharacterLiteral characterLiteral = ast.newCharacterLiteral();
			sourceRewriter.set(characterLiteral, CharacterLiteral.ESCAPED_VALUE_PROPERTY, "\u0000", null);
			returnedExpression = characterLiteral;
		}
		else if(returnTypeBinding.getQualifiedName().equals("int") ||
				returnTypeBinding.getQualifiedName().equals("short") ||
				returnTypeBinding.getQualifiedName().equals("byte")) {
			returnedExpression = ast.newNumberLiteral("0");
		}
		else if(returnTypeBinding.getQualifiedName().equals("long")) {
			returnedExpression = ast.newNumberLiteral("0L");
		}
		else if(returnTypeBinding.getQualifiedName().equals("float")) {
			returnedExpression = ast.newNumberLiteral("0.0f");
		}
		else if(returnTypeBinding.getQualifiedName().equals("double")) {
			returnedExpression = ast.newNumberLiteral("0.0d");
		}
		else if(returnTypeBinding.getQualifiedName().equals("void")) {
			returnedExpression = null;
		}
	}
	else {
		returnedExpression = ast.newNullLiteral();
	}
	return returnedExpression;
}
 
Example #8
Source File: CodeBlock.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
private CharLiteral visit(CharacterLiteral node) {
	int startLine = _cunit.getLineNumber(node.getStartPosition());
	int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength());
	CharLiteral charLiteral = new CharLiteral(startLine, endLine, node);
	
	charLiteral.setValue(node.charValue());
	
	AST ast = AST.newAST(AST.JLS8);
	Type type = ast.newPrimitiveType(PrimitiveType.CHAR);
	charLiteral.setType(type);
	
	return charLiteral;
}
 
Example #9
Source File: InstanceOfLiteral.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean instanceOf(Expression expression) {
	if(expression instanceof BooleanLiteral || expression instanceof CharacterLiteral || expression instanceof StringLiteral ||
			expression instanceof NullLiteral || expression instanceof NumberLiteral || expression instanceof TypeLiteral)
		return true;
	else
		return false;
}
 
Example #10
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(CharacterLiteral node) {
	return visitNode(node);
}
 
Example #11
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 4 votes vote down vote up
private void handleExpression(Expression expression) {
	if (expression instanceof ArrayAccess) {
		visit((ArrayAccess) expression);
	} else if (expression instanceof ArrayCreation) {
		visit((ArrayCreation) expression);
	} else if (expression instanceof ArrayInitializer) {
		visit((ArrayInitializer) expression);
	} else if (expression instanceof Assignment) {
		visit((Assignment) expression);
	} else if (expression instanceof BooleanLiteral) {
		visit((BooleanLiteral) expression);
	} else if (expression instanceof CastExpression) {
		visit((CastExpression) expression);
	} else if (expression instanceof CharacterLiteral) {
		visit((CharacterLiteral) expression);
	} else if (expression instanceof ClassInstanceCreation) {
		visit((ClassInstanceCreation) expression);
	} else if (expression instanceof ConditionalExpression) {
		visit((ConditionalExpression) expression);
	} else if (expression instanceof FieldAccess) {
		visit((FieldAccess) expression);
	} else if (expression instanceof InfixExpression) {
		visit((InfixExpression) expression);
	} else if (expression instanceof InstanceofExpression) {
		visit((InstanceofExpression) expression);
	} else if (expression instanceof MethodInvocation) {
		visit((MethodInvocation) expression);
	} else if (expression instanceof NullLiteral) {
		visit((NullLiteral) expression);
	} else if (expression instanceof NumberLiteral) {
		visit((NumberLiteral) expression);
	} else if (expression instanceof ParenthesizedExpression) {
		visit((ParenthesizedExpression) expression);
	} else if (expression instanceof PostfixExpression) {
		visit((PostfixExpression) expression);
	} else if (expression instanceof PrefixExpression) {
		visit((PrefixExpression) expression);
	} else if ((expression instanceof QualifiedName)) {
		visit((QualifiedName) expression);
	} else if (expression instanceof SimpleName) {
		visit((SimpleName) expression);
	} else if (expression instanceof StringLiteral) {
		visit((StringLiteral) expression);
	} else if (expression instanceof SuperFieldAccess) {
		visit((SuperFieldAccess) expression);
	} else if (expression instanceof SuperMethodInvocation) {
		visit((SuperMethodInvocation) expression);
	} else if (expression instanceof ThisExpression) {
		visit((ThisExpression) expression);
	} else if (expression instanceof TypeLiteral) {
		visit((TypeLiteral) expression);
	} else if (expression instanceof VariableDeclarationExpression) {
		visit((VariableDeclarationExpression) expression);
	}
}
 
Example #12
Source File: BindingSignatureVisitor.java    From JDeodorant with MIT License 4 votes vote down vote up
private void handleExpression(Expression expression) {
	if (expression instanceof ArrayAccess) {
		visit((ArrayAccess) expression);
	} else if (expression instanceof ArrayCreation) {
		visit((ArrayCreation) expression);
	} else if (expression instanceof ArrayInitializer) {
		visit((ArrayInitializer) expression);
	} else if (expression instanceof Assignment) {
		visit((Assignment) expression);
	} else if (expression instanceof BooleanLiteral) {
		visit((BooleanLiteral) expression);
	} else if (expression instanceof CastExpression) {
		visit((CastExpression) expression);
	} else if (expression instanceof CharacterLiteral) {
		visit((CharacterLiteral) expression);
	} else if (expression instanceof ClassInstanceCreation) {
		visit((ClassInstanceCreation) expression);
	} else if (expression instanceof ConditionalExpression) {
		visit((ConditionalExpression) expression);
	} else if (expression instanceof FieldAccess) {
		visit((FieldAccess) expression);
	} else if (expression instanceof InfixExpression) {
		visit((InfixExpression) expression);
	} else if (expression instanceof InstanceofExpression) {
		visit((InstanceofExpression) expression);
	} else if (expression instanceof MethodInvocation) {
		visit((MethodInvocation) expression);
	} else if (expression instanceof NullLiteral) {
		visit((NullLiteral) expression);
	} else if (expression instanceof NumberLiteral) {
		visit((NumberLiteral) expression);
	} else if (expression instanceof ParenthesizedExpression) {
		visit((ParenthesizedExpression) expression);
	} else if (expression instanceof PostfixExpression) {
		visit((PostfixExpression) expression);
	} else if (expression instanceof PrefixExpression) {
		visit((PrefixExpression) expression);
	} else if ((expression instanceof QualifiedName)) {
		visit((QualifiedName) expression);
	} else if (expression instanceof SimpleName) {
		visit((SimpleName) expression);
	} else if (expression instanceof StringLiteral) {
		visit((StringLiteral) expression);
	} else if (expression instanceof SuperFieldAccess) {
		visit((SuperFieldAccess) expression);
	} else if (expression instanceof SuperMethodInvocation) {
		visit((SuperMethodInvocation) expression);
	} else if (expression instanceof ThisExpression) {
		visit((ThisExpression) expression);
	} else if (expression instanceof TypeLiteral) {
		visit((TypeLiteral) expression);
	} else if (expression instanceof VariableDeclarationExpression) {
		visit((VariableDeclarationExpression) expression);
	}
}
 
Example #13
Source File: BindingSignatureVisitor.java    From JDeodorant with MIT License 4 votes vote down vote up
public boolean visit(CharacterLiteral expr) {
	bindingKeys.add(expr.getEscapedValue());
	return false;
}
 
Example #14
Source File: LiteralObject.java    From JDeodorant with MIT License 4 votes vote down vote up
public LiteralObject(Expression expression) {
	if(expression instanceof StringLiteral) {
		StringLiteral stringLiteral = (StringLiteral)expression;
		literalType = LiteralType.STRING;
		value = stringLiteral.getLiteralValue();
		type = TypeObject.extractTypeObject(stringLiteral.resolveTypeBinding().getQualifiedName());
	}
	else if(expression instanceof NullLiteral) {
		NullLiteral nullLiteral = (NullLiteral)expression;
		literalType = LiteralType.NULL;
		value = "null";
		if(nullLiteral.resolveTypeBinding() != null) {
			type = TypeObject.extractTypeObject(nullLiteral.resolveTypeBinding().getQualifiedName());
		}
	}
	else if(expression instanceof NumberLiteral) {
		NumberLiteral numberLiteral = (NumberLiteral)expression;
		literalType = LiteralType.NUMBER;
		value = numberLiteral.getToken();
		type = TypeObject.extractTypeObject(numberLiteral.resolveTypeBinding().getQualifiedName());
	}
	else if(expression instanceof BooleanLiteral) {
		BooleanLiteral booleanLiteral = (BooleanLiteral)expression;
		literalType = LiteralType.BOOLEAN;
		value = Boolean.toString(booleanLiteral.booleanValue());
		type = TypeObject.extractTypeObject(booleanLiteral.resolveTypeBinding().getQualifiedName());
	}
	else if(expression instanceof CharacterLiteral) {
		CharacterLiteral characterLiteral = (CharacterLiteral)expression;
		literalType = LiteralType.CHARACTER;
		value = Character.toString(characterLiteral.charValue());
		type = TypeObject.extractTypeObject(characterLiteral.resolveTypeBinding().getQualifiedName());
	}
	else if(expression instanceof TypeLiteral) {
		TypeLiteral typeLiteral = (TypeLiteral)expression;
		literalType = LiteralType.TYPE;
		value = typeLiteral.getType().toString();
		type = TypeObject.extractTypeObject(typeLiteral.resolveTypeBinding().getQualifiedName());
	}
	this.literal = ASTInformationGenerator.generateASTInformation(expression);
}
 
Example #15
Source File: SemanticHighlightingReconciler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(CharacterLiteral node) {
	return visitLiteral(node);
}
 
Example #16
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endVisit(CharacterLiteral node) {
	endVisitNode(node);
}
 
Example #17
Source File: ConstraintCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(CharacterLiteral node) {
	add(fCreator.create(node));
	return true;
}
 
Example #18
Source File: AstMatchingNodeFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(CharacterLiteral node) {
	if (node.subtreeMatch(fMatcher, fNodeToMatch))
		return matches(node);
	return super.visit(node);
}
 
Example #19
Source File: FlowAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endVisit(CharacterLiteral node) {
	// Leaf node.
}
 
Example #20
Source File: InferTypeArgumentsConstraintCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endVisit(CharacterLiteral node) {
	ITypeBinding typeBinding= node.resolveTypeBinding();
	ImmutableTypeVariable2 cv= fTCModel.makeImmutableTypeVariable(typeBinding, node);
	setConstraintVariable(node, cv);
}
 
Example #21
Source File: FlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void endVisit(CharacterLiteral node) {
	// Leaf node.
}
 
Example #22
Source File: ASTNodes.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * 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();
}
 
Example #23
Source File: ConstraintCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * @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;
}