Java Code Examples for org.eclipse.jdt.core.dom.MethodInvocation#arguments()
The following examples show how to use
org.eclipse.jdt.core.dom.MethodInvocation#arguments() .
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: MoveMethodRefactoring.java From JDeodorant with MIT License | 6 votes |
private void replaceThisExpressionWithSourceClassParameterInMethodInvocationArguments(MethodDeclaration newMethodDeclaration, ASTRewrite targetRewriter) { ExpressionExtractor extractor = new ExpressionExtractor(); List<Expression> methodInvocations = extractor.getMethodInvocations(newMethodDeclaration.getBody()); for(Expression invocation : methodInvocations) { if(invocation instanceof MethodInvocation) { MethodInvocation methodInvocation = (MethodInvocation)invocation; List<Expression> arguments = methodInvocation.arguments(); for(Expression argument : arguments) { if(argument instanceof ThisExpression) { SimpleName parameterName = null; if(!additionalArgumentsAddedToMovedMethod.contains("this")) { parameterName = addSourceClassParameterToMovedMethod(newMethodDeclaration, targetRewriter); } else { AST ast = newMethodDeclaration.getAST(); String sourceTypeName = sourceTypeDeclaration.getName().getIdentifier(); parameterName = ast.newSimpleName(sourceTypeName.replaceFirst(Character.toString(sourceTypeName.charAt(0)), Character.toString(Character.toLowerCase(sourceTypeName.charAt(0))))); } ListRewrite argumentRewrite = targetRewriter.getListRewrite(methodInvocation, MethodInvocation.ARGUMENTS_PROPERTY); argumentRewrite.replace(argument, parameterName, null); } } } } }
Example 2
Source File: MoveInnerToTopRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public boolean visit(MethodInvocation node) { Expression expression= node.getExpression(); if (expression == null) { IMethodBinding binding= node.resolveMethodBinding(); if (binding != null) { if (isAccessToOuter(binding.getDeclaringClass())) { fMethodAccesses.add(node); } } } else { expression.accept(this); } List<Expression> arguments= node.arguments(); for (int i= 0; i < arguments.size(); i++) { arguments.get(i).accept(this); } return false; }
Example 3
Source File: ParFragmentExporter.java From txtUML with Eclipse Public License 1.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public boolean preNext(MethodInvocation curElement) { List<LambdaExpression> params = (List<LambdaExpression>) curElement.arguments(); compiler.println("par"); boolean isFirst = true; for (LambdaExpression interaction : params) { if (isFirst) { isFirst = false; } else { compiler.println("else"); } interaction.getBody().accept(compiler); } return false; }
Example 4
Source File: UseValueOfResolution.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
protected MethodInvocation createValueOfInvocation(ASTRewrite rewrite, CompilationUnit compilationUnit, ClassInstanceCreation primitiveTypeCreation) { Assert.isNotNull(rewrite); Assert.isNotNull(primitiveTypeCreation); final AST ast = rewrite.getAST(); MethodInvocation valueOfInvocation = ast.newMethodInvocation(); valueOfInvocation.setName(ast.newSimpleName(VALUE_OF_METHOD_NAME)); ITypeBinding binding = primitiveTypeCreation.getType().resolveBinding(); if (isStaticImport()) { addStaticImports(rewrite, compilationUnit, binding.getQualifiedName() + "." + VALUE_OF_METHOD_NAME); } else { valueOfInvocation.setExpression(ast.newSimpleName(binding.getName())); } List<?> arguments = primitiveTypeCreation.arguments(); List<Expression> newArguments = valueOfInvocation.arguments(); for (Object argument : arguments) { Expression expression = (Expression) rewrite.createCopyTarget((ASTNode) argument); newArguments.add(expression); } return valueOfInvocation; }
Example 5
Source File: MethodInvocationResolver.java From KodeBeagle with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") @Override public boolean visit(MethodInvocation node) { SimpleName methodName = node.getName(); List args = node.arguments(); Expression expression = node.getExpression(); Map<String, Integer> scopeBindings = getNodeScopes().get(node); String target = getTarget(expression); String targetType = translateTargetToType(target, scopeBindings); // Add only if you could guess the type of target, else ignore. // TODO: In case of a method in super type, this will still infer it as in "this". if (!targetType.isEmpty()) { List<String> argTypes = translateArgsToTypes(args, scopeBindings); if (!methodStack.empty()) { MethodDeclaration currentMethod = methodStack.peek(); MethodDecl methodDecl = getMethodDecl(currentMethod); List<MethodInvokRef> invoks = methodInvoks.get(methodDecl); if (invoks == null) { invoks = new ArrayList<>(); methodInvoks.put(methodDecl, invoks); } MethodInvokRef methodInvokRef = new MethodInvokRef(methodName.toString(), targetType, target, args .size(), node.getName().getStartPosition(), argTypes, methodName.getLength(), false, getReturnType(node)); invoks.add(methodInvokRef); } } return true; }
Example 6
Source File: AbstractLoopUtilities.java From JDeodorant with MIT License | 5 votes |
private static boolean isExpressionAnArgument(Expression expression, MethodInvocation methodInvocation) { List<Expression> arguments = methodInvocation.arguments(); for (Expression currentArgument : arguments) { Expression unparenthesizedArgument = AbstractControlStructureUtilities.unparenthesize(currentArgument); if (currentArgument.equals(expression) || unparenthesizedArgument.equals(expression)) { return true; } } return false; }
Example 7
Source File: PolymorphismRefactoring.java From JDeodorant with MIT License | 5 votes |
protected void replaceThisExpressionWithContextParameterInMethodInvocationArguments(List<Expression> newMethodInvocations, AST subclassAST, ASTRewrite subclassRewriter) { for(Expression expression : newMethodInvocations) { if(expression instanceof MethodInvocation) { MethodInvocation newMethodInvocation = (MethodInvocation)expression; List<Expression> arguments = newMethodInvocation.arguments(); for(Expression argument : arguments) { if(argument instanceof ThisExpression) { String parameterName = sourceTypeDeclaration.getName().getIdentifier(); parameterName = parameterName.substring(0,1).toLowerCase() + parameterName.substring(1,parameterName.length()); ListRewrite argumentsRewrite = subclassRewriter.getListRewrite(newMethodInvocation, MethodInvocation.ARGUMENTS_PROPERTY); argumentsRewrite.replace(argument, subclassAST.newSimpleName(parameterName), null); } } } } }
Example 8
Source File: OperationInvocation.java From RefactoringMiner with MIT License | 5 votes |
public OperationInvocation(CompilationUnit cu, String filePath, MethodInvocation invocation) { this.locationInfo = new LocationInfo(cu, filePath, invocation, CodeElementType.METHOD_INVOCATION); this.methodName = invocation.getName().getIdentifier(); this.typeArguments = invocation.arguments().size(); this.arguments = new ArrayList<String>(); List<Expression> args = invocation.arguments(); for(Expression argument : args) { this.arguments.add(argument.toString()); } if(invocation.getExpression() != null) { this.expression = invocation.getExpression().toString(); processExpression(invocation.getExpression(), this.subExpressions); } }
Example 9
Source File: Visitor.java From RefactoringMiner with MIT License | 5 votes |
public static String processMethodInvocation(MethodInvocation node) { StringBuilder sb = new StringBuilder(); sb.append(node.getName().getIdentifier()); sb.append("("); List<Expression> arguments = node.arguments(); if(arguments.size() > 0) { for(int i=0; i<arguments.size()-1; i++) sb.append(arguments.get(i).toString()).append(", "); sb.append(arguments.get(arguments.size()-1).toString()); } sb.append(")"); return sb.toString(); }
Example 10
Source File: JavaDebugElementCodeMiningASTVisitor.java From jdt-codemining with Eclipse Public License 1.0 | 5 votes |
@Override public boolean visit(MethodInvocation node) { if (inFrame) { List arguments = node.arguments(); if (arguments.size() > 0) { for (int i = 0; i < arguments.size(); i++) { Expression exp = (Expression) arguments.get(i); if (exp instanceof SimpleName) { AbstractDebugVariableCodeMining<IJavaStackFrame> m = new JavaDebugElementCodeMining( (SimpleName) exp, fFrame, viewer, provider); minings.add(m); } } } } return super.visit(node); }
Example 11
Source File: BaseTranslator.java From junion with BSD 3-Clause "New" or "Revised" License | 5 votes |
public MethodInvocation methodTmpRef(ASTNode StackExpression, Expression AddressIdentifier, Entry TypeBind, StructCache.FieldEntry f, String varData, String var) { MethodInvocation m = ast.newMethodInvocation(); m.setExpression(name(MEM0)); m.setName(name("tmpref")); List args = m.arguments(); args.add((Expression)copySubtreeIfHasParent(StackExpression)); args.add((Expression)copySubtreeIfHasParent(AddressIdentifier)); args.add(returnInt(0)); m.setProperty(TYPEBIND_PROP, TypeBind); m.setProperty(TYPEBIND_METHOD_TMP, new MethodTmp(TypebindMethodTmp.Ref, TypeBind, f, varData, var)); return m; }
Example 12
Source File: BaseTranslator.java From junion with BSD 3-Clause "New" or "Revised" License | 5 votes |
public MethodInvocation methodTmpStackVar(ASTNode StackExpression, Expression AddressIdentifier, Entry TypeBind) { MethodInvocation m = ast.newMethodInvocation(); m.setExpression(name(MEM0)); m.setName(name("tmpstack")); List args = m.arguments(); args.add((Expression)copySubtreeIfHasParent(StackExpression)); args.add((Expression)copySubtreeIfHasParent(AddressIdentifier)); args.add(returnInt(0)); m.setProperty(TYPEBIND_PROP, TypeBind); m.setProperty(TYPEBIND_METHOD_TMP, new MethodTmp(TypebindMethodTmp.StackVar, TypeBind)); return m; }
Example 13
Source File: AbstractControlStructureUtilities.java From JDeodorant with MIT License | 5 votes |
private static Integer getTernaryArgumentIndex(MethodInvocation ternaryMethodInvocation, ConditionalExpression conditionalExpression) { List<Expression> arguments = ternaryMethodInvocation.arguments(); for (int i = 0; i < arguments.size(); i++) { if (arguments.get(i).equals(conditionalExpression)) { return i; } } return null; }
Example 14
Source File: AccessAnalyzer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Override public boolean visit(Assignment node) { Expression leftHandSide = node.getLeftHandSide(); if (!considerBinding(resolveBinding(leftHandSide), leftHandSide)) { return true; } checkParent(node); Expression rightHandSide = node.getRightHandSide(); if (!fIsFieldFinal) { // Write access. AST ast = node.getAST(); MethodInvocation invocation = ast.newMethodInvocation(); invocation.setName(ast.newSimpleName(fSetter)); fReferencingSetter = true; Expression receiver = getReceiver(leftHandSide); if (receiver != null) { invocation.setExpression((Expression) fRewriter.createCopyTarget(receiver)); } List<Expression> arguments = invocation.arguments(); if (node.getOperator() == Assignment.Operator.ASSIGN) { arguments.add((Expression) fRewriter.createCopyTarget(rightHandSide)); } else { // This is the compound assignment case: field+= 10; InfixExpression exp = ast.newInfixExpression(); exp.setOperator(ASTNodes.convertToInfixOperator(node.getOperator())); MethodInvocation getter = ast.newMethodInvocation(); getter.setName(ast.newSimpleName(fGetter)); fReferencingGetter = true; if (receiver != null) { getter.setExpression((Expression) fRewriter.createCopyTarget(receiver)); } exp.setLeftOperand(getter); Expression rhs = (Expression) fRewriter.createCopyTarget(rightHandSide); if (NecessaryParenthesesChecker.needsParenthesesForRightOperand(rightHandSide, exp, leftHandSide.resolveTypeBinding())) { ParenthesizedExpression p = ast.newParenthesizedExpression(); p.setExpression(rhs); rhs = p; } exp.setRightOperand(rhs); arguments.add(exp); } fRewriter.replace(node, invocation, createGroupDescription(WRITE_ACCESS)); } rightHandSide.accept(this); return false; }
Example 15
Source File: ExtractMethodRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private ASTNode[] createCallNodes(SnippetFinder.Match duplicate, int modifiers) { List<ASTNode> result = new ArrayList<>(2); IVariableBinding[] locals = fAnalyzer.getCallerLocals(); for (int i = 0; i < locals.length; i++) { result.add(createDeclaration(locals[i], null)); } MethodInvocation invocation = fAST.newMethodInvocation(); invocation.setName(fAST.newSimpleName(fMethodName)); ASTNode typeNode = ASTResolving.findParentType(fAnalyzer.getEnclosingBodyDeclaration()); RefactoringStatus status = new RefactoringStatus(); while (fDestination != typeNode) { fAnalyzer.checkInput(status, fMethodName, typeNode); if (!status.isOK()) { SimpleName destinationTypeName = fAST.newSimpleName(ASTNodes.getEnclosingType(fDestination).getName()); if ((modifiers & Modifier.STATIC) == 0) { ThisExpression thisExpression = fAST.newThisExpression(); thisExpression.setQualifier(destinationTypeName); invocation.setExpression(thisExpression); } else { invocation.setExpression(destinationTypeName); } break; } typeNode = typeNode.getParent(); } List<Expression> arguments = invocation.arguments(); for (int i = 0; i < fParameterInfos.size(); i++) { ParameterInfo parameter = fParameterInfos.get(i); arguments.add(ASTNodeFactory.newName(fAST, getMappedName(duplicate, parameter))); } if (fLinkedProposalModel != null) { LinkedProposalPositionGroupCore nameGroup = fLinkedProposalModel.getPositionGroup(KEY_NAME, true); nameGroup.addPosition(fRewriter.track(invocation.getName()), true); } ASTNode call; int returnKind = fAnalyzer.getReturnKind(); switch (returnKind) { case ExtractMethodAnalyzer.ACCESS_TO_LOCAL: IVariableBinding binding = fAnalyzer.getReturnLocal(); if (binding != null) { VariableDeclarationStatement decl = createDeclaration(getMappedBinding(duplicate, binding), invocation); call = decl; } else { Assignment assignment = fAST.newAssignment(); assignment.setLeftHandSide(ASTNodeFactory.newName(fAST, getMappedBinding(duplicate, fAnalyzer.getReturnValue()).getName())); assignment.setRightHandSide(invocation); call = assignment; } break; case ExtractMethodAnalyzer.RETURN_STATEMENT_VALUE: ReturnStatement rs = fAST.newReturnStatement(); rs.setExpression(invocation); call = rs; break; default: call = invocation; } if (call instanceof Expression && !fAnalyzer.isExpressionSelected()) { call = fAST.newExpressionStatement((Expression) call); } result.add(call); // We have a void return statement. The code looks like // extracted(); // return; if (returnKind == ExtractMethodAnalyzer.RETURN_STATEMENT_VOID && !fAnalyzer.isLastStatementSelected()) { result.add(fAST.newReturnStatement()); } return result.toArray(new ASTNode[result.size()]); }
Example 16
Source File: AbstractControlStructureUtilities.java From JDeodorant with MIT License | 4 votes |
private static void matchExpressionStatementExpressions(Expression thenExpression, Expression elseExpression, Expression ternaryExpression, TernaryControlStructure ternaryStructure, List<Pair<Expression>> matchList) { // if all three expressions are Assignments if (thenExpression instanceof Assignment && elseExpression instanceof Assignment && ternaryExpression instanceof Assignment) { Assignment thenAssignment = (Assignment) thenExpression; Assignment elseAssignment = (Assignment) elseExpression; Assignment ternaryAssignment = (Assignment) ternaryExpression; if (isSameAssignee(thenAssignment, elseAssignment) && ternaryAssignment.getRightHandSide().equals(ternaryStructure.getConditionalExpression())) { matchList.add(new Pair<Expression>(thenAssignment.getLeftHandSide(), ternaryAssignment.getLeftHandSide())); matchList.add(new Pair<Expression>(elseAssignment.getLeftHandSide(), ternaryAssignment.getLeftHandSide())); matchList.add(new Pair<Expression>(thenAssignment.getRightHandSide(), ternaryStructure.getThenExpression())); matchList.add(new Pair<Expression>(elseAssignment.getRightHandSide(), ternaryStructure.getElseExpression())); } } // if all three expressions are MethodInvocations else if (thenExpression instanceof MethodInvocation && elseExpression instanceof MethodInvocation && ternaryExpression instanceof MethodInvocation) { MethodInvocation thenMethodInvocation = (MethodInvocation) thenExpression; MethodInvocation elseMethodInvocation = (MethodInvocation) elseExpression; MethodInvocation ternaryMethodInvocation = (MethodInvocation) ternaryExpression; Integer ternaryArgumentIndex = getTernaryArgumentIndex(ternaryMethodInvocation, ternaryStructure.getConditionalExpression()); List<Expression> thenArguments = thenMethodInvocation.arguments(); List<Expression> elseArguments = elseMethodInvocation.arguments(); List<Expression> ternaryArguments = ternaryMethodInvocation.arguments(); // if all three methods have the same method binding if (thenMethodInvocation.resolveMethodBinding().isEqualTo(elseMethodInvocation.resolveMethodBinding()) && thenMethodInvocation.resolveMethodBinding().isEqualTo(ternaryMethodInvocation.resolveMethodBinding())) { // if the ConditionalExpression is in the arguments if (ternaryArgumentIndex != null) { // match the expressions matchList.add(new Pair<Expression>(thenMethodInvocation.getExpression(), ternaryMethodInvocation.getExpression())); matchList.add(new Pair<Expression>(elseMethodInvocation.getExpression(), ternaryMethodInvocation.getExpression())); for (int i = 0; i < ternaryArguments.size(); i++) { // match the arguments if (i == ternaryArgumentIndex) { matchList.add(new Pair<Expression>(thenArguments.get(i), ternaryStructure.getThenExpression())); matchList.add(new Pair<Expression>(elseArguments.get(i), ternaryStructure.getElseExpression())); } else { matchList.add(new Pair<Expression>(thenArguments.get(i), ternaryArguments.get(i))); matchList.add(new Pair<Expression>(elseArguments.get(i), ternaryArguments.get(i))); } } } // if the ConditionalExpression is the method's expression else if (ternaryMethodInvocation.getExpression() != null && (unparenthesize(ternaryMethodInvocation.getExpression()).equals(ternaryStructure.getConditionalExpression()))) { // match the expressions Expression thenMethodExpression = thenMethodInvocation.getExpression(); Expression elseMethodExpression = elseMethodInvocation.getExpression(); matchList.add(new Pair<Expression>(thenMethodExpression, ternaryStructure.getThenExpression())); matchList.add(new Pair<Expression>(elseMethodExpression, ternaryStructure.getElseExpression())); // match the arguments for (int i = 0; i < ternaryArguments.size(); i++) { matchList.add(new Pair<Expression>(thenArguments.get(i), ternaryArguments.get(i))); matchList.add(new Pair<Expression>(elseArguments.get(i), ternaryArguments.get(i))); } } } } }
Example 17
Source File: DistanceMatrix.java From JDeodorant with MIT License | 4 votes |
private List<MoveMethodCandidateRefactoring> identifyConceptualBindings(MyMethod method, Set<String> targetClasses) { List<MoveMethodCandidateRefactoring> candidateRefactoringList = new ArrayList<MoveMethodCandidateRefactoring>(); MethodObject methodObject = method.getMethodObject(); String sourceClass = method.getClassOrigin(); for(String targetClass : targetClasses) { if(!targetClass.equals(sourceClass)) { ClassObject targetClassObject = system.getClass(targetClass).getClassObject(); ListIterator<ParameterObject> parameterIterator = methodObject.getParameterListIterator(); while(parameterIterator.hasNext()) { ParameterObject parameter = parameterIterator.next(); Association association = system.containsAssociationWithMultiplicityBetweenClasses(targetClass, parameter.getType().getClassType()); if(association != null) { List<MethodInvocationObject> methodInvocations = methodObject.getMethodInvocations(); for(MethodInvocationObject methodInvocation : methodInvocations) { if(methodInvocation.getOriginClassName().equals(targetClass)) { MethodInvocation invocation = methodInvocation.getMethodInvocation(); boolean parameterIsPassedAsArgument = false; List<Expression> invocationArguments = invocation.arguments(); for(Expression expression : invocationArguments) { if(expression instanceof SimpleName) { SimpleName argumentName = (SimpleName)expression; if(parameter.getSingleVariableDeclaration().resolveBinding().isEqualTo(argumentName.resolveBinding())) parameterIsPassedAsArgument = true; } } if(parameterIsPassedAsArgument) { MethodObject invokedMethod = targetClassObject.getMethod(methodInvocation); List<FieldInstructionObject> fieldInstructions = invokedMethod.getFieldInstructions(); boolean containerFieldIsAccessed = false; for(FieldInstructionObject fieldInstruction : fieldInstructions) { if(association.getFieldObject().equals(fieldInstruction)) { containerFieldIsAccessed = true; break; } } if(containerFieldIsAccessed) { MyClass mySourceClass = classList.get(classIndexMap.get(sourceClass)); MyClass myTargetClass = classList.get(classIndexMap.get(targetClass)); MoveMethodCandidateRefactoring candidate = new MoveMethodCandidateRefactoring(system,mySourceClass,myTargetClass,method); Map<MethodInvocation, MethodDeclaration> additionalMethodsToBeMoved = candidate.getAdditionalMethodsToBeMoved(); Collection<MethodDeclaration> values = additionalMethodsToBeMoved.values(); Set<String> methodEntitySet = entityMap.get(method.toString()); Set<String> sourceClassEntitySet = classMap.get(sourceClass); Set<String> targetClassEntitySet = classMap.get(targetClass); Set<String> intersectionWithSourceClass = DistanceCalculator.intersection(methodEntitySet, sourceClassEntitySet); Set<String> intersectionWithTargetClass = DistanceCalculator.intersection(methodEntitySet, targetClassEntitySet); Set<String> entitiesToRemoveFromIntersectionWithSourceClass = new LinkedHashSet<String>(); if(!values.isEmpty()) { for(String s : intersectionWithSourceClass) { int entityPosition = entityIndexMap.get(s); Entity e = entityList.get(entityPosition); if(e instanceof MyMethod) { MyMethod myInvokedMethod = (MyMethod)e; if(values.contains(myInvokedMethod.getMethodObject().getMethodDeclaration())) { entitiesToRemoveFromIntersectionWithSourceClass.add(s); } } } intersectionWithSourceClass.removeAll(entitiesToRemoveFromIntersectionWithSourceClass); } if(intersectionWithTargetClass.size() >= intersectionWithSourceClass.size()) { if(candidate.isApplicable()) { int sourceClassDependencies = candidate.getDistinctSourceDependencies(); int targetClassDependencies = candidate.getDistinctTargetDependencies(); if(sourceClassDependencies <= maximumNumberOfSourceClassMembersAccessedByMoveMethodCandidate && sourceClassDependencies < targetClassDependencies) { candidateRefactoringList.add(candidate); } } } } } } } } } } } return candidateRefactoringList; }
Example 18
Source File: BaseTranslator.java From junion with BSD 3-Clause "New" or "Revised" License | 4 votes |
public MethodInvocation methodTmpArrayIndex(ASTNode ArrayExpression, SimpleName ArrayIdentifier, Entry TypeBind, List dims) { if(dims.size() < 1) throw new IllegalArgumentException(); MethodInvocation m = ast.newMethodInvocation(); m.setExpression(name(MEM0)); m.setName(name("tmparr")); List args = m.arguments(); if(dims.size() == 1) { args.add((Expression)copySubtreeIfHasParent(ArrayExpression)); } else { FieldAccess fa = ast.newFieldAccess(); fa.setExpression((Expression)copySubtreeIfHasParent(ArrayExpression)); fa.setName(name("r")); args.add(fa); } args.add((Expression)copySubtreeIfHasParent(ArrayIdentifier)); args.add(returnInt(0)); if(dims.size() == 1) args.add(copySubtreeIfHasParent(dims.get(0))); else { MethodInvocation idx2 = ast.newMethodInvocation(); idx2.setExpression((Expression)copySubtreeIfHasParent(ArrayIdentifier)); idx2.setName(name(getIndexMethodName(dims.size()))); idx2.setProperty(TYPEBIND_PROP, FieldType.LONG); for(int i = 0; i < dims.size(); i++) { idx2.arguments().add(copySubtreeIfHasParent(dims.get(i))); } for(int i = 0; i < dims.size(); i++) { ASTNode arg3 = (ASTNode)dims.get(i); MethodTmp tmp3 = getMethodTmp(arg3); if(tmp3 != null) { replaceMethodTmp(arg3, (MethodInvocation)arg3, tmp3, MethodType.get, null, Assignment.Operator.ASSIGN); } } args.add(idx2); } m.setProperty(TYPEBIND_PROP, TypeBind); m.setProperty(TYPEBIND_METHOD_TMP, new MethodTmp(TypebindMethodTmp.Array, TypeBind)); return m; }
Example 19
Source File: AccessAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public boolean visit(Assignment node) { Expression leftHandSide= node.getLeftHandSide(); if (!considerBinding(resolveBinding(leftHandSide), leftHandSide)) return true; checkParent(node); Expression rightHandSide= node.getRightHandSide(); if (!fIsFieldFinal) { // Write access. AST ast= node.getAST(); MethodInvocation invocation= ast.newMethodInvocation(); invocation.setName(ast.newSimpleName(fSetter)); fReferencingSetter= true; Expression receiver= getReceiver(leftHandSide); if (receiver != null) invocation.setExpression((Expression)fRewriter.createCopyTarget(receiver)); List<Expression> arguments= invocation.arguments(); if (node.getOperator() == Assignment.Operator.ASSIGN) { arguments.add((Expression)fRewriter.createCopyTarget(rightHandSide)); } else { // This is the compound assignment case: field+= 10; InfixExpression exp= ast.newInfixExpression(); exp.setOperator(ASTNodes.convertToInfixOperator(node.getOperator())); MethodInvocation getter= ast.newMethodInvocation(); getter.setName(ast.newSimpleName(fGetter)); fReferencingGetter= true; if (receiver != null) getter.setExpression((Expression)fRewriter.createCopyTarget(receiver)); exp.setLeftOperand(getter); Expression rhs= (Expression)fRewriter.createCopyTarget(rightHandSide); if (NecessaryParenthesesChecker.needsParenthesesForRightOperand(rightHandSide, exp, leftHandSide.resolveTypeBinding())) { ParenthesizedExpression p= ast.newParenthesizedExpression(); p.setExpression(rhs); rhs= p; } exp.setRightOperand(rhs); arguments.add(exp); } fRewriter.replace(node, invocation, createGroupDescription(WRITE_ACCESS)); } rightHandSide.accept(this); return false; }
Example 20
Source File: StubUtility2.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public static MethodDeclaration createDelegationStub(ICompilationUnit unit, ASTRewrite rewrite, ImportRewrite imports, ImportRewriteContext context, IMethodBinding delegate, IVariableBinding delegatingField, CodeGenerationSettings settings) throws CoreException { Assert.isNotNull(delegate); Assert.isNotNull(delegatingField); Assert.isNotNull(settings); AST ast= rewrite.getAST(); MethodDeclaration decl= ast.newMethodDeclaration(); decl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, delegate.getModifiers() & ~Modifier.SYNCHRONIZED & ~Modifier.ABSTRACT & ~Modifier.NATIVE)); decl.setName(ast.newSimpleName(delegate.getName())); decl.setConstructor(false); createTypeParameters(imports, context, ast, delegate, decl); decl.setReturnType2(imports.addImport(delegate.getReturnType(), ast, context)); List<SingleVariableDeclaration> params= createParameters(unit.getJavaProject(), imports, context, ast, delegate, null, decl); createThrownExceptions(decl, delegate, imports, context, ast); Block body= ast.newBlock(); decl.setBody(body); String delimiter= StubUtility.getLineDelimiterUsed(unit); Statement statement= null; MethodInvocation invocation= ast.newMethodInvocation(); invocation.setName(ast.newSimpleName(delegate.getName())); List<Expression> arguments= invocation.arguments(); for (int i= 0; i < params.size(); i++) arguments.add(ast.newSimpleName(params.get(i).getName().getIdentifier())); if (settings.useKeywordThis) { FieldAccess access= ast.newFieldAccess(); access.setExpression(ast.newThisExpression()); access.setName(ast.newSimpleName(delegatingField.getName())); invocation.setExpression(access); } else invocation.setExpression(ast.newSimpleName(delegatingField.getName())); if (delegate.getReturnType().isPrimitive() && delegate.getReturnType().getName().equals("void")) {//$NON-NLS-1$ statement= ast.newExpressionStatement(invocation); } else { ReturnStatement returnStatement= ast.newReturnStatement(); returnStatement.setExpression(invocation); statement= returnStatement; } body.statements().add(statement); ITypeBinding declaringType= delegatingField.getDeclaringClass(); if (declaringType == null) { // can be null for return decl; } String qualifiedName= declaringType.getQualifiedName(); IPackageBinding packageBinding= declaringType.getPackage(); if (packageBinding != null) { if (packageBinding.getName().length() > 0 && qualifiedName.startsWith(packageBinding.getName())) qualifiedName= qualifiedName.substring(packageBinding.getName().length()); } if (settings.createComments) { /* * TODO: have API for delegate method comments This is an inlined * version of * {@link CodeGeneration#getMethodComment(ICompilationUnit, String, MethodDeclaration, IMethodBinding, String)} */ delegate= delegate.getMethodDeclaration(); String declaringClassQualifiedName= delegate.getDeclaringClass().getQualifiedName(); String linkToMethodName= delegate.getName(); String[] parameterTypesQualifiedNames= StubUtility.getParameterTypeNamesForSeeTag(delegate); String string= StubUtility.getMethodComment(unit, qualifiedName, decl, delegate.isDeprecated(), linkToMethodName, declaringClassQualifiedName, parameterTypesQualifiedNames, true, delimiter); if (string != null) { Javadoc javadoc= (Javadoc) rewrite.createStringPlaceholder(string, ASTNode.JAVADOC); decl.setJavadoc(javadoc); } } return decl; }