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

The following examples show how to use org.eclipse.jdt.core.dom.NullLiteral. 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: PreconditionExaminer.java    From JDeodorant with MIT License 6 votes vote down vote up
private void extractReturnTypeBinding(PDGNode pdgNode, List<ITypeBinding> returnedTypeBindings) {
	if(pdgNode instanceof PDGExitNode) {
		PDGExitNode exitNode = (PDGExitNode)pdgNode;
		ReturnStatement returnStatement = (ReturnStatement)exitNode.getASTStatement();
		Expression returnedExpression = returnStatement.getExpression();
		if(returnedExpression != null && !(returnedExpression instanceof NullLiteral)) {
			ITypeBinding typeBinding = returnedExpression.resolveTypeBinding();
			if(typeBinding != null) {
				boolean alreadyContained = false;
				for(ITypeBinding binding : returnedTypeBindings) {
					if(binding.isEqualTo(typeBinding)) {
						alreadyContained = true;
						break;
					}
				}
				if(!alreadyContained)
					returnedTypeBindings.add(typeBinding);
			}
		}
	}
}
 
Example #2
Source File: ExtractConstantRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus checkExpression() throws JavaModelException {
	RefactoringStatus result= new RefactoringStatus();
	result.merge(checkExpressionBinding());
	if(result.hasFatalError())
		return result;
	checkAllStaticFinal();

	IExpressionFragment selectedExpression= getSelectedExpression();
	Expression associatedExpression= selectedExpression.getAssociatedExpression();
	if (associatedExpression instanceof NullLiteral)
		result.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractConstantRefactoring_null_literals));
	else if (!ConstantChecks.isLoadTimeConstant(selectedExpression))
		result.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractConstantRefactoring_not_load_time_constant));
	else if (associatedExpression instanceof SimpleName) {
		if (associatedExpression.getParent() instanceof QualifiedName && associatedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY
				|| associatedExpression.getParent() instanceof FieldAccess && associatedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY)
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractConstantRefactoring_select_expression);
	}

	return result;
}
 
Example #3
Source File: ExtractTempRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus checkExpression() throws JavaModelException {
	Expression selectedExpression= getSelectedExpression().getAssociatedExpression();
	if (selectedExpression != null) {
		final ASTNode parent= selectedExpression.getParent();
		if (selectedExpression instanceof NullLiteral) {
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals);
		} else if (selectedExpression instanceof ArrayInitializer) {
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer);
		} else if (selectedExpression instanceof Assignment) {
			if (parent instanceof Expression && !(parent instanceof ParenthesizedExpression))
				return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment);
			else
				return null;
		} else if (selectedExpression instanceof SimpleName) {
			if ((((SimpleName) selectedExpression)).isDeclaration())
				return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations);
			if (parent instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY || parent instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY)
				return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression);
		} else if (selectedExpression instanceof VariableDeclarationExpression && parent instanceof TryStatement) {
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_resource_in_try_with_resources);
		}
	}

	return null;
}
 
Example #4
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 #5
Source File: ExtractClassRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean replaceMarker(final ASTRewrite rewrite, final Expression qualifier, Expression assignedValue, final NullLiteral marker) {
	class MarkerReplacer extends ASTVisitor {

		private boolean fReplaced= false;

		@Override
		public boolean visit(NullLiteral node) {
			if (node == marker) {
				rewrite.replace(node, rewrite.createCopyTarget(qualifier), null);
				fReplaced= true;
				return false;
			}
			return true;
		}
	}
	if (assignedValue != null && qualifier != null) {
		MarkerReplacer visitor= new MarkerReplacer();
		assignedValue.accept(visitor);
		return visitor.fReplaced;
	}
	return false;
}
 
Example #6
Source File: ExtractClassRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Expression getAssignedValue(ParameterObjectFactory pof, String parameterName, IJavaProject javaProject, RefactoringStatus status, ASTRewrite rewrite, ParameterInfo pi, boolean useSuper, ITypeBinding typeBinding, Expression qualifier, ASTNode replaceNode, ITypeRoot typeRoot) {
	AST ast= rewrite.getAST();
	boolean is50OrHigher= JavaModelUtil.is50OrHigher(javaProject);
	Expression assignedValue= handleSimpleNameAssignment(replaceNode, pof, parameterName, ast, javaProject, useSuper);
	if (assignedValue == null) {
		NullLiteral marker= qualifier == null ? null : ast.newNullLiteral();
		Expression fieldReadAccess= pof.createFieldReadAccess(pi, parameterName, ast, javaProject, useSuper, marker);
		assignedValue= GetterSetterUtil.getAssignedValue(replaceNode, rewrite, fieldReadAccess, typeBinding, is50OrHigher);
		boolean markerReplaced= replaceMarker(rewrite, qualifier, assignedValue, marker);
		if (markerReplaced) {
			switch (qualifier.getNodeType()) {
				case ASTNode.METHOD_INVOCATION:
				case ASTNode.CLASS_INSTANCE_CREATION:
				case ASTNode.SUPER_METHOD_INVOCATION:
				case ASTNode.PARENTHESIZED_EXPRESSION:
					status.addWarning(RefactoringCoreMessages.ExtractClassRefactoring_warning_semantic_change, JavaStatusContext.create(typeRoot, replaceNode));
					break;
			}
		}
	}
	return assignedValue;
}
 
Example #7
Source File: ExtractConstantRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private RefactoringStatus checkExpression() throws JavaModelException {
	RefactoringStatus result = new RefactoringStatus();
	result.merge(checkExpressionBinding());
	if (result.hasFatalError()) {
		return result;
	}
	checkAllStaticFinal();

	IExpressionFragment selectedExpression = getSelectedExpression();
	Expression associatedExpression = selectedExpression.getAssociatedExpression();
	if (associatedExpression instanceof NullLiteral) {
		result.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractConstantRefactoring_null_literals));
	} else if (!ConstantChecks.isLoadTimeConstant(selectedExpression)) {
		result.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractConstantRefactoring_not_load_time_constant));
	} else if (associatedExpression instanceof SimpleName) {
		if (associatedExpression.getParent() instanceof QualifiedName && associatedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY
				|| associatedExpression.getParent() instanceof FieldAccess && associatedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY) {
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractConstantRefactoring_select_expression);
		}
	}

	return result;
}
 
Example #8
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 #9
Source File: Visitor.java    From RefactoringMiner with MIT License 5 votes vote down vote up
public boolean visit(NullLiteral node) {
	nullLiterals.add(node.toString());
	if(current.getUserObject() != null) {
		AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject();
		anonymous.getNullLiterals().add(node.toString());
	}
	return super.visit(node);
}
 
Example #10
Source File: ExtractFieldRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private RefactoringStatus checkExpression() throws JavaModelException {
	Expression selectedExpression = getSelectedExpression().getAssociatedExpression();
	if (selectedExpression != null) {
		final ASTNode parent = selectedExpression.getParent();
		if (selectedExpression instanceof NullLiteral) {
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals);
		} else if (selectedExpression instanceof ArrayInitializer) {
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer);
		} else if (selectedExpression instanceof Assignment) {
			if (parent instanceof Expression && !(parent instanceof ParenthesizedExpression)) {
				return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment);
			} else {
				return null;
			}
		} else if (selectedExpression instanceof SimpleName) {
			if ((((SimpleName) selectedExpression)).isDeclaration()) {
				return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations);
			}
			if (parent instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY || parent instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY) {
				return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression);
			}
		} else if (selectedExpression instanceof VariableDeclarationExpression && parent instanceof TryStatement) {
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_resource_in_try_with_resources);
		}
	}

	return null;
}
 
Example #11
Source File: ASTNodeMatcher.java    From JDeodorant with MIT License 5 votes vote down vote up
private boolean hasEmptyInitializer(VariableDeclaration variableDeclaration) {
	if(variableDeclaration.getInitializer() == null) {
		return true;
	}
	else {
		Expression initializer = variableDeclaration.getInitializer();
		if(initializer instanceof NullLiteral) {
			return true;
		}
	}
	return false;
}
 
Example #12
Source File: IntroduceParameterRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private RefactoringStatus checkExpression() {
	//TODO: adjust error messages (or generalize for all refactorings on expression-selections?)
	Expression selectedExpression= fSelectedExpression;

	if (selectedExpression instanceof Name && selectedExpression.getParent() instanceof ClassInstanceCreation)
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_name_in_new);
		//TODO: let's just take the CIC automatically (no ambiguity -> no problem -> no dialog ;-)

	if (selectedExpression instanceof NullLiteral) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals);
	} else if (selectedExpression instanceof ArrayInitializer) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer);
	} else if (selectedExpression instanceof Assignment) {
		if (selectedExpression.getParent() instanceof Expression)
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment);
		else
			return null;

	} else if (selectedExpression instanceof SimpleName){
		if ((((SimpleName)selectedExpression)).isDeclaration())
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations);
		if (selectedExpression.getParent() instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY
				|| selectedExpression.getParent() instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY)
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression);
	}

	return null;
}
 
Example #13
Source File: ExtractTempRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private RefactoringStatus checkExpression() throws JavaModelException {
	Expression selectedExpression = getSelectedExpression().getAssociatedExpression();
	if (selectedExpression != null) {
		final ASTNode parent = selectedExpression.getParent();
		if (selectedExpression instanceof NullLiteral) {
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals);
		} else if (selectedExpression instanceof ArrayInitializer) {
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer);
		} else if (selectedExpression instanceof Assignment) {
			if (parent instanceof Expression && !(parent instanceof ParenthesizedExpression)) {
				return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment);
			} else {
				return null;
			}
		} else if (selectedExpression instanceof SimpleName) {
			if ((((SimpleName) selectedExpression)).isDeclaration()) {
				return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations);
			}
			if (parent instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY || parent instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY) {
				return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression);
			}
		} else if (selectedExpression instanceof VariableDeclarationExpression && parent instanceof TryStatement) {
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_resource_in_try_with_resources);
		}
	}

	return null;
}
 
Example #14
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean visit(NullLiteral expr) {
	/*
	 * null
	 */
	styledString.append("null", determineDiffStyle(expr, new StyledStringStyler(keywordStyle)));
	return false;
}
 
Example #15
Source File: LapseView.java    From lapse-plus with GNU General Public License v3.0 5 votes vote down vote up
private int getExpressionType(Expression expr, CompilationUnit cu, IResource resource) {
	if(isStringContant(expr, cu, resource)) {
		return HistoryDefinitionLocation.STRING_CONSTANT;
	}else if(expr instanceof NullLiteral){
		return HistoryDefinitionLocation.NULL;
	}
	else {
		return HistoryDefinitionLocation.UNDEFINED;
	}
}
 
Example #16
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 #17
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(NullLiteral node) {
	if (node.subtreeMatch(fMatcher, fNodeToMatch))
		return matches(node);
	return super.visit(node);
}
 
Example #18
Source File: BindingSignatureVisitor.java    From JDeodorant with MIT License 4 votes vote down vote up
public boolean visit(NullLiteral expr) {
	bindingKeys.add(expr.toString());
	return false;
}
 
Example #19
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 #20
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 #21
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(NullLiteral node) {
	return visitNode(node);
}
 
Example #22
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(NullLiteral node) {
	endVisitNode(node);
}
 
Example #23
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(NullLiteral node) {
	add(fCreator.create(node));
	return true;
}
 
Example #24
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(NullLiteral node) {
	// Leaf node.
}
 
Example #25
Source File: SuperTypeConstraintsCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public final void endVisit(final NullLiteral node) {
	node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, fModel.createImmutableTypeVariable(node.resolveTypeBinding()));
}
 
Example #26
Source File: ExtractClassRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private RefactoringStatus replaceReferences(ParameterObjectFactory pof, SearchResultGroup group, CompilationUnitRewrite cuRewrite) {
	TextEditGroup writeGroup= cuRewrite.createGroupDescription(RefactoringCoreMessages.ExtractClassRefactoring_group_replace_write);
	TextEditGroup readGroup= cuRewrite.createGroupDescription(RefactoringCoreMessages.ExtractClassRefactoring_group_replace_read);
	ITypeRoot typeRoot= cuRewrite.getCu();
	IJavaProject javaProject= typeRoot.getJavaProject();
	AST ast= cuRewrite.getAST();

	RefactoringStatus status= new RefactoringStatus();
	String parameterName= fDescriptor.getFieldName();

	SearchMatch[] searchResults= group.getSearchResults();
	for (int j= 0; j < searchResults.length; j++) {
		SearchMatch searchMatch= searchResults[j];
		ASTNode node= NodeFinder.perform(cuRewrite.getRoot(), searchMatch.getOffset(), searchMatch.getLength());
		ASTNode parent= node.getParent();
		boolean isDeclaration= parent instanceof VariableDeclaration && ((VariableDeclaration)parent).getInitializer() != node;
		if (!isDeclaration && node instanceof SimpleName) {
			ASTRewrite rewrite= cuRewrite.getASTRewrite();
			if (parent.getNodeType() == ASTNode.SWITCH_CASE)
				status.addError(RefactoringCoreMessages.ExtractClassRefactoring_error_switch, JavaStatusContext.create(typeRoot, node));

			SimpleName name= (SimpleName) node;
			ParameterInfo pi= getFieldInfo(name.getIdentifier()).pi;
			boolean writeAccess= ASTResolving.isWriteAccess(name);
			if (writeAccess && fDescriptor.isCreateGetterSetter()) {
				boolean useSuper= parent.getNodeType() == ASTNode.SUPER_FIELD_ACCESS;
				Expression qualifier= getQualifier(parent);
				ASTNode replaceNode= getReplacementNode(parent, useSuper, qualifier);
				Expression assignedValue= getAssignedValue(pof, parameterName, javaProject, status, rewrite, pi, useSuper, name.resolveTypeBinding(), qualifier, replaceNode, typeRoot);
				if (assignedValue == null) {
					status.addError(RefactoringCoreMessages.ExtractClassRefactoring_error_unable_to_convert_node, JavaStatusContext.create(typeRoot, replaceNode));
				} else {
					NullLiteral marker= qualifier == null ? null : ast.newNullLiteral();
					Expression access= pof.createFieldWriteAccess(pi, parameterName, ast, javaProject, assignedValue, useSuper, marker);
					replaceMarker(rewrite, qualifier, access, marker);
					rewrite.replace(replaceNode, access, writeGroup);
				}
			} else {
				Expression fieldReadAccess= pof.createFieldReadAccess(pi, parameterName, ast, javaProject, false, null); //qualifier is already there
				rewrite.replace(name, fieldReadAccess, readGroup);
			}
		}
	}
	return status;
}
 
Example #27
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean visit(final NullLiteral it) {
  this.appendToBuffer("null");
  return false;
}
 
Example #28
Source File: FlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void endVisit(NullLiteral node) {
	// Leaf node.
}
 
Example #29
Source File: CodeBlock.java    From SimFix with GNU General Public License v2.0 4 votes vote down vote up
private NillLiteral visit(NullLiteral node) {
	int startLine = _cunit.getLineNumber(node.getStartPosition());
	int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength());
	NillLiteral nillLiteral = new NillLiteral(startLine, endLine, node);
	return nillLiteral;
}
 
Example #30
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.NullLiteral)
 */
public ITypeConstraint[] create(NullLiteral node) {
	return EMPTY_ARRAY;
}