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

The following examples show how to use org.eclipse.jdt.core.dom.ConstructorInvocation. 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: StatementObject.java    From JDeodorant with MIT License 6 votes vote down vote up
public StatementObject(Statement statement, StatementType type, AbstractMethodFragment parent) {
	super(statement, type, parent);
	
	ExpressionExtractor expressionExtractor = new ExpressionExtractor();
       List<Expression> assignments = expressionExtractor.getAssignments(statement);
       List<Expression> postfixExpressions = expressionExtractor.getPostfixExpressions(statement);
       List<Expression> prefixExpressions = expressionExtractor.getPrefixExpressions(statement);
       processVariables(expressionExtractor.getVariableInstructions(statement), assignments, postfixExpressions, prefixExpressions);
	processMethodInvocations(expressionExtractor.getMethodInvocations(statement));
	processClassInstanceCreations(expressionExtractor.getClassInstanceCreations(statement));
	processArrayCreations(expressionExtractor.getArrayCreations(statement));
	//processArrayAccesses(expressionExtractor.getArrayAccesses(statement));
	processLiterals(expressionExtractor.getLiterals(statement));
	if(statement instanceof ThrowStatement) {
		processThrowStatement((ThrowStatement)statement);
	}
	if(statement instanceof ConstructorInvocation) {
		processConstructorInvocation((ConstructorInvocation)statement);
	}
}
 
Example #2
Source File: Invocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static List<Expression> getArguments(ASTNode invocation) {
	switch (invocation.getNodeType()) {
		case ASTNode.METHOD_INVOCATION:
			return ((MethodInvocation)invocation).arguments();
		case ASTNode.SUPER_METHOD_INVOCATION:
			return ((SuperMethodInvocation)invocation).arguments();
			
		case ASTNode.CONSTRUCTOR_INVOCATION:
			return ((ConstructorInvocation)invocation).arguments();
		case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
			return ((SuperConstructorInvocation)invocation).arguments();
			
		case ASTNode.CLASS_INSTANCE_CREATION:
			return ((ClassInstanceCreation)invocation).arguments();
		case ASTNode.ENUM_CONSTANT_DECLARATION:
			return ((EnumConstantDeclaration)invocation).arguments();
			
		default:
			throw new IllegalArgumentException(invocation.toString());
	}
}
 
Example #3
Source File: Invocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static ChildListPropertyDescriptor getArgumentsProperty(ASTNode invocation) {
	switch (invocation.getNodeType()) {
		case ASTNode.METHOD_INVOCATION:
			return MethodInvocation.ARGUMENTS_PROPERTY;
		case ASTNode.SUPER_METHOD_INVOCATION:
			return SuperMethodInvocation.ARGUMENTS_PROPERTY;
			
		case ASTNode.CONSTRUCTOR_INVOCATION:
			return ConstructorInvocation.ARGUMENTS_PROPERTY;
		case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
			return SuperConstructorInvocation.ARGUMENTS_PROPERTY;
			
		case ASTNode.CLASS_INSTANCE_CREATION:
			return ClassInstanceCreation.ARGUMENTS_PROPERTY;
		case ASTNode.ENUM_CONSTANT_DECLARATION:
			return EnumConstantDeclaration.ARGUMENTS_PROPERTY;
			
		default:
			throw new IllegalArgumentException(invocation.toString());
	}
}
 
Example #4
Source File: Invocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static IMethodBinding resolveBinding(ASTNode invocation) {
	switch (invocation.getNodeType()) {
		case ASTNode.METHOD_INVOCATION:
			return ((MethodInvocation)invocation).resolveMethodBinding();
		case ASTNode.SUPER_METHOD_INVOCATION:
			return ((SuperMethodInvocation)invocation).resolveMethodBinding();
			
		case ASTNode.CONSTRUCTOR_INVOCATION:
			return ((ConstructorInvocation)invocation).resolveConstructorBinding();
		case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
			return ((SuperConstructorInvocation)invocation).resolveConstructorBinding();
			
		case ASTNode.CLASS_INSTANCE_CREATION:
			return ((ClassInstanceCreation)invocation).resolveConstructorBinding();
		case ASTNode.ENUM_CONSTANT_DECLARATION:
			return ((EnumConstantDeclaration)invocation).resolveConstructorBinding();
			
		default:
			throw new IllegalArgumentException(invocation.toString());
	}
}
 
Example #5
Source File: JavadocHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static IBinding resolveBinding(ASTNode node) {
	if (node instanceof SimpleName) {
		SimpleName simpleName= (SimpleName) node;
		// workaround for https://bugs.eclipse.org/62605 (constructor name resolves to type, not method)
		ASTNode normalized= ASTNodes.getNormalizedNode(simpleName);
		if (normalized.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) {
			ClassInstanceCreation cic= (ClassInstanceCreation) normalized.getParent();
			IMethodBinding constructorBinding= cic.resolveConstructorBinding();
			if (constructorBinding == null)
				return null;
			ITypeBinding declaringClass= constructorBinding.getDeclaringClass();
			if (!declaringClass.isAnonymous())
				return constructorBinding;
			ITypeBinding superTypeDeclaration= declaringClass.getSuperclass().getTypeDeclaration();
			return resolveSuperclassConstructor(superTypeDeclaration, constructorBinding);
		}
		return simpleName.resolveBinding();
		
	} else if (node instanceof SuperConstructorInvocation) {
		return ((SuperConstructorInvocation) node).resolveConstructorBinding();
	} else if (node instanceof ConstructorInvocation) {
		return ((ConstructorInvocation) node).resolveConstructorBinding();
	} else {
		return null;
	}
}
 
Example #6
Source File: InlineMethodRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a new inline method refactoring
 * @param unit the compilation unit or class file
 * @param node the compilation unit node
 * @param selectionStart start
 * @param selectionLength length
 * @return returns the refactoring
 */
public static InlineMethodRefactoring create(ITypeRoot unit, CompilationUnit node, int selectionStart, int selectionLength) {
	ASTNode target= RefactoringAvailabilityTester.getInlineableMethodNode(unit, node, selectionStart, selectionLength);
	if (target == null)
		return null;
	if (target.getNodeType() == ASTNode.METHOD_DECLARATION) {

		return new InlineMethodRefactoring(unit, (MethodDeclaration)target, selectionStart, selectionLength);
	} else {
		ICompilationUnit cu= (ICompilationUnit) unit;
		if (target.getNodeType() == ASTNode.METHOD_INVOCATION) {
			return new InlineMethodRefactoring(cu, (MethodInvocation)target, selectionStart, selectionLength);
		} else if (target.getNodeType() == ASTNode.SUPER_METHOD_INVOCATION) {
			return new InlineMethodRefactoring(cu, (SuperMethodInvocation)target, selectionStart, selectionLength);
		} else if (target.getNodeType() == ASTNode.CONSTRUCTOR_INVOCATION) {
			return new InlineMethodRefactoring(cu, (ConstructorInvocation)target, selectionStart, selectionLength);
		}
	}
	return null;
}
 
Example #7
Source File: InlineMethodRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public RefactoringStatus setCurrentMode(Mode mode) throws JavaModelException {
	if (fCurrentMode == mode)
		return new RefactoringStatus();
	Assert.isTrue(getInitialMode() == Mode.INLINE_SINGLE);
	fCurrentMode= mode;
	if (mode == Mode.INLINE_SINGLE) {
		if (fInitialNode instanceof MethodInvocation)
			fTargetProvider= TargetProvider.create((ICompilationUnit) fInitialTypeRoot, (MethodInvocation)fInitialNode);
		else if (fInitialNode instanceof SuperMethodInvocation)
			fTargetProvider= TargetProvider.create((ICompilationUnit) fInitialTypeRoot, (SuperMethodInvocation)fInitialNode);
		else if (fInitialNode instanceof ConstructorInvocation)
			fTargetProvider= TargetProvider.create((ICompilationUnit) fInitialTypeRoot, (ConstructorInvocation)fInitialNode);
		else
			throw new IllegalStateException(String.valueOf(fInitialNode));
	} else {
		fTargetProvider= TargetProvider.create(fSourceProvider.getDeclaration());
	}
	return fTargetProvider.checkActivation();
}
 
Example #8
Source File: VariableDeclarationFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean callsWritingConstructor(MethodDeclaration methodDeclaration, HashSet<IMethodBinding> writingConstructorBindings, Set<MethodDeclaration> visitedMethodDeclarations) {
	Block body= methodDeclaration.getBody();
	if (body == null)
		return false;

	List<Statement> statements= body.statements();
	if (statements.size() == 0)
		return false;

	Statement statement= statements.get(0);
	if (!(statement instanceof ConstructorInvocation))
		return false;

	ConstructorInvocation invocation= (ConstructorInvocation)statement;
	IMethodBinding constructorBinding= invocation.resolveConstructorBinding();
	if (constructorBinding == null)
		return false;

	if (writingConstructorBindings.contains(constructorBinding)) {
		return true;
	} else {
		ASTNode declaration= ASTNodes.findDeclaration(constructorBinding, methodDeclaration.getParent());
		if (!(declaration instanceof MethodDeclaration))
			return false;

		if (visitedMethodDeclarations.contains(declaration)) {
			return false;
		}
		visitedMethodDeclarations.add(methodDeclaration);
		return callsWritingConstructor((MethodDeclaration)declaration, writingConstructorBindings, visitedMethodDeclarations);
	}
}
 
Example #9
Source File: ExtractTempRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isUsedInExplicitConstructorCall() throws JavaModelException {
	Expression selectedExpression= getSelectedExpression().getAssociatedExpression();
	if (ASTNodes.getParent(selectedExpression, ConstructorInvocation.class) != null)
		return true;
	if (ASTNodes.getParent(selectedExpression, SuperConstructorInvocation.class) != null)
		return true;
	return false;
}
 
Example #10
Source File: FullConstraintCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public ITypeConstraint[] create(ConstructorInvocation invocation){
	List<Expression> arguments= invocation.arguments();
	List<ITypeConstraint> result= new ArrayList<ITypeConstraint>(arguments.size());
	IMethodBinding methodBinding= invocation.resolveConstructorBinding();
	result.addAll(Arrays.asList(getArgumentConstraints(arguments, methodBinding)));
	return result.toArray(new ITypeConstraint[result.size()]);
}
 
Example #11
Source File: SurroundWithAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void endVisit(ConstructorInvocation node) {
	if (getSelection().getEndVisitSelectionMode(node) == Selection.SELECTED) {
		invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_cannotHandleThis, JavaStatusContext.create(fCUnit, node));
	}
	super.endVisit(node);
}
 
Example #12
Source File: CalleeAnalyzerVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
    * Find all constructor invocations (<code>this(...)</code>) from the called method.
    * Since we only traverse into the AST on the wanted method declaration, this method
    * should not hit on more constructor invocations than those in the wanted method.
    *
    * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ConstructorInvocation)
    */
   @Override
public boolean visit(ConstructorInvocation node) {
       progressMonitorWorked(1);
       if (!isFurtherTraversalNecessary(node)) {
           return false;
       }

       if (isNodeWithinMethod(node)) {
           addMethodCall(node.resolveConstructorBinding(), node);
       }

       return true;
   }
 
Example #13
Source File: CodeStyleFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean isMethodArgument(Expression expression) {
	ASTNode parent= expression;
	while (parent instanceof Expression) {

		if (parent.getLocationInParent() == MethodInvocation.ARGUMENTS_PROPERTY)
			return true;

		if (parent.getLocationInParent() == ConstructorInvocation.ARGUMENTS_PROPERTY)
			return true;

		parent= ((Expression) parent).getParent();
	}

	return false;
}
 
Example #14
Source File: CodeBlock.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
private ConstructorInv visit(ConstructorInvocation node) {
	int startLine = _cunit.getLineNumber(node.getStartPosition());
	int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength());
	ConstructorInv constructorInv = new ConstructorInv(startLine, endLine, node);
	List<Expr> arguments = new ArrayList<>();
	for(Object object : node.arguments()){
		Expr expr = (Expr) process((ASTNode) object);
		expr.setParent(constructorInv);
		arguments.add(expr);
	}
	constructorInv.setArguments(arguments);
	return constructorInv;
}
 
Example #15
Source File: ExceptionOccurrencesFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(ConstructorInvocation node) {
	if (matches(node.resolveConstructorBinding())) {
		// mark 'this'
		fResult.add(new OccurrenceLocation(node.getStartPosition(), 4, 0, fDescription));
	}
	return super.visit(node);
}
 
Example #16
Source File: MethodExitsFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(ConstructorInvocation node) {
	if (isExitPoint(node.resolveConstructorBinding())) {
		// mark 'this'
		fResult.add(new OccurrenceLocation(node.getStartPosition(), 4, 0, fExitDescription));
	}
	return true;
}
 
Example #17
Source File: SemanticHighlightingReconciler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(ConstructorInvocation node) {
	// XXX Hack for performance reasons (should loop over fJobSemanticHighlightings can call consumes(*))
	if (fJobDeprecatedMemberHighlighting != null) {
		IMethodBinding constructorBinding= node.resolveConstructorBinding();
		if (constructorBinding != null && constructorBinding.isDeprecated()) {
			int offset= node.getStartPosition();
			int length= 4;
			if (offset > -1 && length > 0)
				addPosition(offset, length, fJobDeprecatedMemberHighlighting);
		}
	}
	return true;
}
 
Example #18
Source File: ASTResolving.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isInsideConstructorInvocation(MethodDeclaration methodDeclaration, ASTNode node) {
	if (methodDeclaration.isConstructor()) {
		Statement statement= ASTResolving.findParentStatement(node);
		if (statement instanceof ConstructorInvocation || statement instanceof SuperConstructorInvocation) {
			return true; // argument in a this or super call
		}
	}
	return false;
}
 
Example #19
Source File: AdvancedQuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static Expression getBooleanExpression(ASTNode node) {
	if (!(node instanceof Expression)) {
		return null;
	}

	// check if the node is a location where it can be negated
	StructuralPropertyDescriptor locationInParent= node.getLocationInParent();
	if (locationInParent == QualifiedName.NAME_PROPERTY) {
		node= node.getParent();
		locationInParent= node.getLocationInParent();
	}
	while (locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
		node= node.getParent();
		locationInParent= node.getLocationInParent();
	}
	Expression expression= (Expression) node;
	if (!isBoolean(expression)) {
		return null;
	}
	if (expression.getParent() instanceof InfixExpression) {
		return expression;
	}
	if (locationInParent == Assignment.RIGHT_HAND_SIDE_PROPERTY || locationInParent == IfStatement.EXPRESSION_PROPERTY
			|| locationInParent == WhileStatement.EXPRESSION_PROPERTY || locationInParent == DoStatement.EXPRESSION_PROPERTY
			|| locationInParent == ReturnStatement.EXPRESSION_PROPERTY || locationInParent == ForStatement.EXPRESSION_PROPERTY
			|| locationInParent == AssertStatement.EXPRESSION_PROPERTY || locationInParent == MethodInvocation.ARGUMENTS_PROPERTY
			|| locationInParent == ConstructorInvocation.ARGUMENTS_PROPERTY || locationInParent == SuperMethodInvocation.ARGUMENTS_PROPERTY
			|| locationInParent == EnumConstantDeclaration.ARGUMENTS_PROPERTY || locationInParent == SuperConstructorInvocation.ARGUMENTS_PROPERTY
			|| locationInParent == ClassInstanceCreation.ARGUMENTS_PROPERTY || locationInParent == ConditionalExpression.EXPRESSION_PROPERTY
			|| locationInParent == PrefixExpression.OPERAND_PROPERTY) {
		return expression;
	}
	return null;
}
 
Example #20
Source File: AbstractMethodFragment.java    From JDeodorant with MIT License 5 votes vote down vote up
protected void processConstructorInvocation(ConstructorInvocation constructorInvocation) {
	IMethodBinding methodBinding = constructorInvocation.resolveConstructorBinding();
	String originClassName = methodBinding.getDeclaringClass().getQualifiedName();
	TypeObject originClassTypeObject = TypeObject.extractTypeObject(originClassName);
	String methodInvocationName = methodBinding.getName();
	String qualifiedName = methodBinding.getReturnType().getQualifiedName();
	TypeObject returnType = TypeObject.extractTypeObject(qualifiedName);
	ConstructorInvocationObject constructorInvocationObject = new ConstructorInvocationObject(originClassTypeObject, methodInvocationName, returnType);
	constructorInvocationObject.setConstructorInvocation(constructorInvocation);
	ITypeBinding[] parameterTypes = methodBinding.getParameterTypes();
	for(ITypeBinding parameterType : parameterTypes) {
		String qualifiedParameterName = parameterType.getQualifiedName();
		TypeObject typeObject = TypeObject.extractTypeObject(qualifiedParameterName);
		constructorInvocationObject.addParameter(typeObject);
	}
	ITypeBinding[] thrownExceptionTypes = methodBinding.getExceptionTypes();
	for(ITypeBinding thrownExceptionType : thrownExceptionTypes) {
		constructorInvocationObject.addThrownException(thrownExceptionType.getQualifiedName());
	}
	if((methodBinding.getModifiers() & Modifier.STATIC) != 0)
		constructorInvocationObject.setStatic(true);
	addConstructorInvocation(constructorInvocationObject);
	List<Expression> arguments = constructorInvocation.arguments();
	for(Expression argument : arguments) {
		if(argument instanceof SimpleName) {
			SimpleName argumentName = (SimpleName)argument;
			IBinding binding = argumentName.resolveBinding();
			if(binding != null && binding.getKind() == IBinding.VARIABLE) {
				IVariableBinding variableBinding = (IVariableBinding)binding;
				if(variableBinding.isParameter()) {
					PlainVariable variable = new PlainVariable(variableBinding);
					addParameterPassedAsArgumentInConstructorInvocation(variable, constructorInvocationObject);
				}
			}
		}
	}
}
 
Example #21
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean visit(ConstructorInvocation stmnt){
	/*
	 *  [ < Type { , Type } > ]
                     this ( [ Expression { , Expression } ] ) ;
	 */
	handleTypeArguments(stmnt.typeArguments());
	styledString.append("this", new StyledStringStyler(keywordStyle));
	handleParameters(stmnt.arguments());
	appendSemicolon();
	return false;
}
 
Example #22
Source File: CodeSearch.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
public boolean visit(ConstructorInvocation node) {
	int start = _unit.getLineNumber(node.getStartPosition());
	if(start == _extendedLine){
		_extendedStatement = node;
		return false;
	}
	return true;
}
 
Example #23
Source File: ExtractFieldRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isUsedInExplicitConstructorCall() throws JavaModelException {
	Expression selectedExpression = getSelectedExpression().getAssociatedExpression();
	if (ASTNodes.getParent(selectedExpression, ConstructorInvocation.class) != null) {
		return true;
	}
	if (ASTNodes.getParent(selectedExpression, SuperConstructorInvocation.class) != null) {
		return true;
	}
	return false;
}
 
Example #24
Source File: ExtractFieldRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static boolean shouldInsertTempInitialization(MethodDeclaration constructor) {
	Assert.isTrue(constructor.isConstructor());
	if (constructor.getBody() == null) {
		return false;
	}
	List<Statement> statements = constructor.getBody().statements();
	if (statements == null) {
		return false;
	}
	if (statements.size() > 0 && statements.get(0) instanceof ConstructorInvocation) {
		return false;
	}
	return true;
}
 
Example #25
Source File: ExceptionAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(ConstructorInvocation node) {
	if (!isSelected(node)) {
		return false;
	}
	return handleExceptions(node.resolveConstructorBinding(), node);
}
 
Example #26
Source File: InvertBooleanUtility.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static Expression getBooleanExpression(ASTNode node) {
	if (!(node instanceof Expression)) {
		return null;
	}

	// check if the node is a location where it can be negated
	StructuralPropertyDescriptor locationInParent = node.getLocationInParent();
	if (locationInParent == QualifiedName.NAME_PROPERTY) {
		node = node.getParent();
		locationInParent = node.getLocationInParent();
	}
	while (locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
		node = node.getParent();
		locationInParent = node.getLocationInParent();
	}
	Expression expression = (Expression) node;
	if (!isBoolean(expression)) {
		return null;
	}
	if (expression.getParent() instanceof InfixExpression) {
		return expression;
	}
	if (locationInParent == Assignment.RIGHT_HAND_SIDE_PROPERTY || locationInParent == IfStatement.EXPRESSION_PROPERTY || locationInParent == WhileStatement.EXPRESSION_PROPERTY || locationInParent == DoStatement.EXPRESSION_PROPERTY
			|| locationInParent == ReturnStatement.EXPRESSION_PROPERTY || locationInParent == ForStatement.EXPRESSION_PROPERTY || locationInParent == AssertStatement.EXPRESSION_PROPERTY
			|| locationInParent == MethodInvocation.ARGUMENTS_PROPERTY || locationInParent == ConstructorInvocation.ARGUMENTS_PROPERTY || locationInParent == SuperMethodInvocation.ARGUMENTS_PROPERTY
			|| locationInParent == EnumConstantDeclaration.ARGUMENTS_PROPERTY || locationInParent == SuperConstructorInvocation.ARGUMENTS_PROPERTY || locationInParent == ClassInstanceCreation.ARGUMENTS_PROPERTY
			|| locationInParent == ConditionalExpression.EXPRESSION_PROPERTY || locationInParent == PrefixExpression.OPERAND_PROPERTY) {
		return expression;
	}
	return null;
}
 
Example #27
Source File: ExtractTempRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isUsedInExplicitConstructorCall() throws JavaModelException {
	Expression selectedExpression = getSelectedExpression().getAssociatedExpression();
	if (ASTNodes.getParent(selectedExpression, ConstructorInvocation.class) != null) {
		return true;
	}
	if (ASTNodes.getParent(selectedExpression, SuperConstructorInvocation.class) != null) {
		return true;
	}
	return false;
}
 
Example #28
Source File: TargetProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(ConstructorInvocation node) {
	if (matches(node.resolveConstructorBinding()) && fCurrent != null) {
		fCurrent.addInvocation(node);
	}
	return true;
}
 
Example #29
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final ConstructorInvocation node) {
  boolean _isEmpty = node.typeArguments().isEmpty();
  boolean _not = (!_isEmpty);
  if (_not) {
    this.appendTypeParameters(node.typeArguments());
  }
  this.appendToBuffer("this(");
  this.visitAllSeparatedByComma(node.arguments());
  this.appendToBuffer(")");
  return false;
}
 
Example #30
Source File: OperationInvocation.java    From RefactoringMiner with MIT License 5 votes vote down vote up
public OperationInvocation(CompilationUnit cu, String filePath, ConstructorInvocation invocation) {
	this.locationInfo = new LocationInfo(cu, filePath, invocation, CodeElementType.CONSTRUCTOR_INVOCATION);
	this.methodName = "this";
	this.typeArguments = invocation.arguments().size();
	this.arguments = new ArrayList<String>();
	List<Expression> args = invocation.arguments();
	for(Expression argument : args) {
		this.arguments.add(argument.toString());
	}
}