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

The following examples show how to use org.eclipse.jdt.core.dom.MethodDeclaration. 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 vote down vote up
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: CreateAsyncMethodProposal.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static List<IJavaCompletionProposal> createProposalsForProblemOnAsyncType(
    ICompilationUnit asyncCompilationUnit, ASTNode problemNode,
    String syncMethodBindingKey) {
  TypeDeclaration asyncTypeDecl = (TypeDeclaration) ASTResolving.findAncestor(
      problemNode, ASTNode.TYPE_DECLARATION);
  assert (asyncTypeDecl != null);
  String asyncQualifiedTypeName = asyncTypeDecl.resolveBinding().getQualifiedName();

  // Lookup the sync version of the interface
  IType syncType = RemoteServiceUtilities.findSyncType(asyncTypeDecl);
  if (syncType == null) {
    return Collections.emptyList();
  }

  MethodDeclaration syncMethodDecl = JavaASTUtils.findMethodDeclaration(
      syncType.getCompilationUnit(), syncMethodBindingKey);
  if (syncMethodDecl == null) {
    return Collections.emptyList();
  }

  return Collections.<IJavaCompletionProposal> singletonList(new CreateAsyncMethodProposal(
      asyncCompilationUnit, asyncQualifiedTypeName, syncMethodDecl));
}
 
Example #3
Source File: VariableDeclarationFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean isWrittenInTypeConstructors(List<SimpleName> writes, ITypeBinding declaringClass) {

			for (int i= 0; i < writes.size(); i++) {
	            SimpleName name= writes.get(i);

	            MethodDeclaration methodDeclaration= getWritingConstructor(name);
	            if (methodDeclaration == null)
	            	return false;

	            if (!methodDeclaration.isConstructor())
	            	return false;

	            IMethodBinding constructor= methodDeclaration.resolveBinding();
	            if (constructor == null)
	            	return false;

	            ITypeBinding declaringClass2= constructor.getDeclaringClass();
	            if (!declaringClass.equals(declaringClass2))
	            	return false;
            }

	        return true;
        }
 
Example #4
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static ASTNode getInlineableMethodNode(ASTNode node, IJavaElement unit) {
	if (node == null)
		return null;
	switch (node.getNodeType()) {
		case ASTNode.SIMPLE_NAME:
			StructuralPropertyDescriptor locationInParent= node.getLocationInParent();
			if (locationInParent == MethodDeclaration.NAME_PROPERTY) {
				return node.getParent();
			} else if (locationInParent == MethodInvocation.NAME_PROPERTY
					|| locationInParent == SuperMethodInvocation.NAME_PROPERTY) {
				return unit instanceof ICompilationUnit ? node.getParent() : null; // don't start on invocations in binary
			}
			return null;
		case ASTNode.EXPRESSION_STATEMENT:
			node= ((ExpressionStatement)node).getExpression();
	}
	switch (node.getNodeType()) {
		case ASTNode.METHOD_DECLARATION:
			return node;
		case ASTNode.METHOD_INVOCATION:
		case ASTNode.SUPER_METHOD_INVOCATION:
		case ASTNode.CONSTRUCTOR_INVOCATION:
			return unit instanceof ICompilationUnit ? node : null; // don't start on invocations in binary
	}
	return null;
}
 
Example #5
Source File: MoveMethodRefactoring.java    From JDeodorant with MIT License 6 votes vote down vote up
private void removeAdditionalMethodsFromSourceClass() {
	Set<MethodDeclaration> methodsToBeMoved = new LinkedHashSet<MethodDeclaration>(additionalMethodsToBeMoved.values());
	for(MethodDeclaration methodDeclaration : methodsToBeMoved) {
		ASTRewrite sourceRewriter = ASTRewrite.create(sourceCompilationUnit.getAST());
		ListRewrite sourceClassBodyRewrite = sourceRewriter.getListRewrite(sourceTypeDeclaration, TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
		sourceClassBodyRewrite.remove(methodDeclaration, null);
		try {
			TextEdit sourceEdit = sourceRewriter.rewriteAST();
			sourceMultiTextEdit.addChild(sourceEdit);
			sourceCompilationUnitChange.addTextEditGroup(new TextEditGroup("Remove additional moved method", new TextEdit[] {sourceEdit}));
		}
		catch(JavaModelException javaModelException) {
			javaModelException.printStackTrace();
		}
	}
}
 
Example #6
Source File: DeclarationInfoManager.java    From lapse-plus with GNU General Public License v3.0 6 votes vote down vote up
public VariableDeclaration getVariableDeclaration(SimpleName name) {
	ASTNode node = name;
	do {
		node = node.getParent();
	} while ( node != null && !(node instanceof MethodDeclaration) );
	
	String key = null;
	
	if(node != null) {
		key = node.toString() + "/" + name.getFullyQualifiedName();
	}else {
		key = "GLOBAL" + name.getFullyQualifiedName();	
	}
	
	logError("Trying " + key);
	VariableDeclaration var = getVariableDeclaration(key);
	if(var == null && node != null) {
		key = "GLOBAL" + name.getFullyQualifiedName();
		log("Trying " + key);
		var = getVariableDeclaration(key);
	}
	
	return var;
}
 
Example #7
Source File: TypeCheckingEvolution.java    From JDeodorant with MIT License 6 votes vote down vote up
private List<TypeCheckElimination> generateTypeCheckEliminationsWithinTypeDeclaration(TypeDeclaration typeDeclaration, TypeCheckElimination originalTypeCheckElimination) {
	List<TypeCheckElimination> typeCheckEliminations = new ArrayList<TypeCheckElimination>();
	for(MethodDeclaration method : typeDeclaration.getMethods()) {
		Block methodBody = method.getBody();
		if(methodBody != null) {
			List<TypeCheckElimination> list = generateTypeCheckEliminationsWithinMethodBody(methodBody);
			for(TypeCheckElimination typeCheckElimination : list) {
				if(!typeCheckElimination.allTypeCheckBranchesAreEmpty()) {
					TypeCheckCodeFragmentAnalyzer analyzer = new TypeCheckCodeFragmentAnalyzer(typeCheckElimination, typeDeclaration, method, null);
					if((typeCheckElimination.getTypeField() != null || typeCheckElimination.getTypeLocalVariable() != null || typeCheckElimination.getTypeMethodInvocation() != null) &&
							typeCheckElimination.allTypeCheckingsContainStaticFieldOrSubclassType() && typeCheckElimination.isApplicable()) {
						if(originalTypeCheckElimination.matchingStatesOrSubTypes(typeCheckElimination))
							typeCheckEliminations.add(typeCheckElimination);
					}
				}
			}
		}
	}
	return typeCheckEliminations;
}
 
Example #8
Source File: JavaMethodDeclarationBindingExtractor.java    From api-mining with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Add argument-related features.
 *
 * @param md
 * @param features
 */
private void addArgumentFeatures(final MethodDeclaration md,
		final Set<String> features) {
	checkArgument(activeFeatures.contains(AvailableFeatures.ARGUMENTS));
	features.add("nParams:" + md.parameters().size());
	for (int i = 0; i < md.parameters().size(); i++) {
		final SingleVariableDeclaration varDecl = (SingleVariableDeclaration) md
				.parameters().get(i);
		features.add("param" + i + "Type:" + varDecl.getType().toString());
		for (final String namepart : JavaFeatureExtractor
				.getNameParts(varDecl.getName().toString())) {
			features.add("paramName:" + namepart);
		}
	}

	if (md.isVarargs()) {
		features.add("isVarArg");
	}
}
 
Example #9
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the bindings of the method argument types of the specified
 * declaration.
 *
 * @param declaration
 *            the method declaration
 * @return the array of method argument variable bindings
 */
protected static ITypeBinding[] getArgumentTypes(final MethodDeclaration declaration) {
	Assert.isNotNull(declaration);
	final IVariableBinding[] parameters= getArgumentBindings(declaration);
	final List<ITypeBinding> types= new ArrayList<ITypeBinding>(parameters.length);
	IVariableBinding binding= null;
	ITypeBinding type= null;
	for (int index= 0; index < parameters.length; index++) {
		binding= parameters[index];
		type= binding.getType();
		if (type != null)
			types.add(type);
	}
	final ITypeBinding[] result= new ITypeBinding[types.size()];
	types.toArray(result);
	return result;
}
 
Example #10
Source File: MoveMethodRefactoring.java    From JDeodorant with MIT License 6 votes vote down vote up
private void modifySourceStaticMethodInvocationsInTargetClass(MethodDeclaration newMethodDeclaration, ASTRewrite targetRewriter) {
	ExpressionExtractor extractor = new ExpressionExtractor();	
	List<Expression> sourceMethodInvocations = extractor.getMethodInvocations(sourceMethod.getBody());
	List<Expression> newMethodInvocations = extractor.getMethodInvocations(newMethodDeclaration.getBody());
	int i = 0;
	for(Expression expression : sourceMethodInvocations) {
		if(expression instanceof MethodInvocation) {
			MethodInvocation methodInvocation = (MethodInvocation)expression;
			IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
			if((methodBinding.getModifiers() & Modifier.STATIC) != 0 &&
					methodBinding.getDeclaringClass().isEqualTo(sourceTypeDeclaration.resolveBinding()) &&
					!additionalMethodsToBeMoved.containsKey(methodInvocation)) {
				AST ast = newMethodDeclaration.getAST();
				SimpleName qualifier = ast.newSimpleName(sourceTypeDeclaration.getName().getIdentifier());
				targetRewriter.set(newMethodInvocations.get(i), MethodInvocation.EXPRESSION_PROPERTY, qualifier, null);
				this.additionalTypeBindingsToBeImportedInTargetClass.add(sourceTypeDeclaration.resolveBinding());
			}
		}
		i++;
	}
}
 
Example #11
Source File: ExpressionExtractor.java    From JDeodorant with MIT License 6 votes vote down vote up
private List<Expression> getExpressions(AnonymousClassDeclaration anonymousClassDeclaration) {
	List<Expression> expressionList = new ArrayList<Expression>();
	List<BodyDeclaration> bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
	for(BodyDeclaration bodyDeclaration : bodyDeclarations) {
		if(bodyDeclaration instanceof MethodDeclaration) {
			MethodDeclaration methodDeclaration = (MethodDeclaration)bodyDeclaration;
			Block body = methodDeclaration.getBody();
			if(body != null) {
				List<Statement> statements = body.statements();
				for(Statement statement : statements) {
					expressionList.addAll(getExpressions(statement));
				}
			}
		}
	}
	return expressionList;
}
 
Example #12
Source File: UpdateAsyncSignatureProposal.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected List<SingleVariableDeclaration> computeParams(AST ast,
    MethodDeclaration srcMethod, MethodDeclaration dstMethod,
    ImportRewrite imports) {

  // Clone the sync method parameters
  List<SingleVariableDeclaration> params = new ArrayList<SingleVariableDeclaration>();
  params.addAll(JavaASTUtils.cloneParameters(ast, adjustSrcParams(srcMethod),
      imports));

  // Append an AsyncCallback
  params.add(Util.createAsyncCallbackParameter(ast,
      srcMethod.getReturnType2(), computeCallBackName(dstMethod), imports));

  return params;
}
 
Example #13
Source File: MethodDiff.java    From apidiff with MIT License 6 votes vote down vote up
/**
 * Finding deprecated methods
 * 
 * @param version1
 * @param version2
 */
private void findAddedDeprecatedMethods(APIVersion version1, APIVersion version2) {
	
	for(TypeDeclaration typeVersion2 : version2.getApiAcessibleTypes()){
		for(MethodDeclaration methodVersion2 : typeVersion2.getMethods()){
			
			if(this.isMethodAcessible(methodVersion2) && this.isDeprecated(methodVersion2, typeVersion2)){
				MethodDeclaration methodInVersion1 = version1.findMethodByNameAndParametersAndReturn(methodVersion2, typeVersion2);
				if(methodInVersion1 == null || !this.isDeprecated(methodInVersion1, version1.getVersionAccessibleType(typeVersion2))){
					String description = this.description.deprecate(this.getSimpleNameMethod(methodVersion2), UtilTools.getPath(typeVersion2));
					this.addChange(typeVersion2, methodVersion2, Category.METHOD_DEPRECATED, false, description);
				}
			}
		}
	}
}
 
Example #14
Source File: IntroduceFactoryRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Finds and returns the <code>ASTNode</code> for the given source text
 * selection, if it is an entire constructor call or the class name portion
 * of a constructor call or constructor declaration, or null otherwise.
 * @param unit The compilation unit in which the selection was made
 * @param offset The textual offset of the start of the selection
 * @param length The length of the selection in characters
 * @return ClassInstanceCreation or MethodDeclaration
 */
private ASTNode getTargetNode(ICompilationUnit unit, int offset, int length) {
	ASTNode node= ASTNodes.getNormalizedNode(NodeFinder.perform(fCU, offset, length));
	if (node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION)
		return node;
	if (node.getNodeType() == ASTNode.METHOD_DECLARATION && ((MethodDeclaration)node).isConstructor())
		return node;
	// we have some sub node. Make sure its the right child of the parent
	StructuralPropertyDescriptor location= node.getLocationInParent();
	ASTNode parent= node.getParent();
	if (location == ClassInstanceCreation.TYPE_PROPERTY) {
		return parent;
	} else if (location == MethodDeclaration.NAME_PROPERTY && ((MethodDeclaration)parent).isConstructor()) {
		return parent;
	}
	return null;
}
 
Example #15
Source File: MoveMethodRefactoring.java    From JDeodorant with MIT License 6 votes vote down vote up
private void removeParamTagElementFromJavadoc(MethodDeclaration newMethodDeclaration, ASTRewrite targetRewriter, String parameterToBeRemoved) {
	if(newMethodDeclaration.getJavadoc() != null) {
		Javadoc javadoc = newMethodDeclaration.getJavadoc();
		List<TagElement> tags = javadoc.tags();
		for(TagElement tag : tags) {
			if(tag.getTagName() != null && tag.getTagName().equals(TagElement.TAG_PARAM)) {
				List<ASTNode> tagFragments = tag.fragments();
				boolean paramFound = false;
				for(ASTNode node : tagFragments) {
					if(node instanceof SimpleName) {
						SimpleName simpleName = (SimpleName)node;
						if(simpleName.getIdentifier().equals(parameterToBeRemoved)) {
							paramFound = true;
							break;
						}
					}
				}
				if(paramFound) {
					ListRewrite tagsRewrite = targetRewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY);
					tagsRewrite.remove(tag, null);
					break;
				}
			}
		}
	}
}
 
Example #16
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 #17
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the reserved identifiers in the method to move.
 *
 * @return the reserved identifiers
 * @throws JavaModelException
 *             if the method declaration could not be found
 */
protected String[] computeReservedIdentifiers() throws JavaModelException {
	final List<String> names= new ArrayList<String>();
	final MethodDeclaration declaration= ASTNodeSearchUtil.getMethodDeclarationNode(fMethod, fSourceRewrite.getRoot());
	if (declaration != null) {
		final List<SingleVariableDeclaration> parameters= declaration.parameters();
		VariableDeclaration variable= null;
		for (int index= 0; index < parameters.size(); index++) {
			variable= parameters.get(index);
			names.add(variable.getName().getIdentifier());
		}
		final Block body= declaration.getBody();
		if (body != null) {
			final IBinding[] bindings= new ScopeAnalyzer(fSourceRewrite.getRoot()).getDeclarationsAfter(body.getStartPosition(), ScopeAnalyzer.VARIABLES);
			for (int index= 0; index < bindings.length; index++)
				names.add(bindings[index].getName());
		}
	}
	final String[] result= new String[names.size()];
	names.toArray(result);
	return result;
}
 
Example #18
Source File: MoveMethodRefactoring.java    From JDeodorant with MIT License 6 votes vote down vote up
private void addParamTagElementToJavadoc(MethodDeclaration newMethodDeclaration, ASTRewrite targetRewriter, String parameterToBeAdded) {
	if(newMethodDeclaration.getJavadoc() != null) {
		AST ast = newMethodDeclaration.getAST();
		Javadoc javadoc = newMethodDeclaration.getJavadoc();
		List<TagElement> tags = javadoc.tags();
		TagElement returnTagElement = null;
		for(TagElement tag : tags) {
			if(tag.getTagName() != null && tag.getTagName().equals(TagElement.TAG_RETURN)) {
				returnTagElement = tag;
				break;
			}
		}
		
		TagElement tagElement = ast.newTagElement();
		targetRewriter.set(tagElement, TagElement.TAG_NAME_PROPERTY, TagElement.TAG_PARAM, null);
		ListRewrite fragmentsRewrite = targetRewriter.getListRewrite(tagElement, TagElement.FRAGMENTS_PROPERTY);
		SimpleName paramName = ast.newSimpleName(parameterToBeAdded);
		fragmentsRewrite.insertLast(paramName, null);
		
		ListRewrite tagsRewrite = targetRewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY);
		if(returnTagElement != null)
			tagsRewrite.insertBefore(tagElement, returnTagElement, null);
		else
			tagsRewrite.insertLast(tagElement, null);
	}
}
 
Example #19
Source File: CodeRefactoringUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static RefactoringStatus checkMethodSyntaxErrors(int selectionStart, int selectionLength, CompilationUnit cuNode, String invalidSelectionMessage){
	SelectionAnalyzer analyzer= new SelectionAnalyzer(Selection.createFromStartLength(selectionStart, selectionLength), true);
	cuNode.accept(analyzer);
	ASTNode coveringNode= analyzer.getLastCoveringNode();
	if (! (coveringNode instanceof Block) || ! (coveringNode.getParent() instanceof MethodDeclaration))
		return RefactoringStatus.createFatalErrorStatus(invalidSelectionMessage);
	if (ASTNodes.getMessages(coveringNode, ASTNodes.NODE_ONLY).length == 0)
		return RefactoringStatus.createFatalErrorStatus(invalidSelectionMessage);

	MethodDeclaration methodDecl= (MethodDeclaration)coveringNode.getParent();
	String message= Messages.format(RefactoringCoreMessages.CodeRefactoringUtil_error_message, BasicElementLabels.getJavaElementName(methodDecl.getName().getIdentifier()));
	return RefactoringStatus.createFatalErrorStatus(message);
}
 
Example #20
Source File: ASTResolving.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * The node's enclosing method declaration or <code>null</code> if
 * the node is not inside a method and is not a method declaration itself.
 * 
 * @param node a node
 * @return the enclosing method declaration or <code>null</code>
 */
public static MethodDeclaration findParentMethodDeclaration(ASTNode node) {
	while (node != null) {
		if (node instanceof MethodDeclaration) {
			return (MethodDeclaration) node;
		} else if (node instanceof BodyDeclaration || node instanceof AnonymousClassDeclaration || node instanceof LambdaExpression) {
			return null;
		}
		node= node.getParent();
	}
	return null;
}
 
Example #21
Source File: MethodVisitor.java    From DesigniteJava with Apache License 2.0 5 votes vote down vote up
@Override
public boolean visit(MethodDeclaration method) {
	SM_Method newMethod = new SM_Method(method, parentType);
	methods.add(newMethod);
	
	return super.visit(method);
}
 
Example #22
Source File: JavadocAdder.java    From SparkBuilderGenerator with MIT License 5 votes vote down vote up
public void addJavadocForBuildMethod(AST ast, MethodDeclaration buildMethod) {
    if (preferencesManager.getPreferenceValue(GENERATE_JAVADOC_ON_EACH_BUILDER_METHOD)) {
        Javadoc javadoc = javadocGenerator.generateJavadoc(ast, "Builder method of the builder.",
                Collections.singletonMap(RETURN_JAVADOC_TAG_NAME, "built class"));
        buildMethod.setJavadoc(javadoc);
    }
}
 
Example #23
Source File: PrivateConstructorRemover.java    From SparkBuilderGenerator with MIT License 5 votes vote down vote up
private List<MethodDeclaration> extractPrivateConstructors(TypeDeclaration mainType) {
    return Arrays.stream(mainType.getMethods())
            .filter(method -> method.isConstructor())
            .filter(method -> method.parameters().size() == 1)
            .filter(isPrivatePredicate)
            .collect(Collectors.toList());
}
 
Example #24
Source File: MethodRetriever.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
public static Map<String, MethodDeclaration> getMethodNodes(
		final String file) throws Exception {
	final JavaASTExtractor astExtractor = new JavaASTExtractor(false);
	final MethodRetriever m = new MethodRetriever();
	final ASTNode cu = astExtractor.getBestEffortAstNode(file);
	cu.accept(m);
	return m.methods;
}
 
Example #25
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the bindings of the method arguments of the specified
 * declaration.
 *
 * @param declaration
 *            the method declaration
 * @return the array of method argument variable bindings
 */
protected static IVariableBinding[] getArgumentBindings(final MethodDeclaration declaration) {
	Assert.isNotNull(declaration);
	final List<IVariableBinding> parameters= new ArrayList<IVariableBinding>(declaration.parameters().size());
	for (final Iterator<SingleVariableDeclaration> iterator= declaration.parameters().iterator(); iterator.hasNext();) {
		VariableDeclaration variable= iterator.next();
		IVariableBinding binding= variable.resolveBinding();
		if (binding == null)
			return new IVariableBinding[0];
		parameters.add(binding);
	}
	final IVariableBinding[] result= new IVariableBinding[parameters.size()];
	parameters.toArray(result);
	return result;
}
 
Example #26
Source File: UpdateSyncSignatureProposal.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected List<SingleVariableDeclaration> adjustSrcParams(
    MethodDeclaration method) {

  // The source method is in the async interface
  List<SingleVariableDeclaration> params = method.parameters();

  if (Util.getCallbackParameter(method) != null) {
    params = params.subList(0, params.size() - 1);
  }

  return params;
}
 
Example #27
Source File: SuperClassSetterFieldCollector.java    From SparkBuilderGenerator with MIT License 5 votes vote down vote up
private List<SuperSetterBasedBuilderField> findParametersWithSettersInType(TypeDeclaration parentTypeDeclaration) {
    return ((List<BodyDeclaration>) parentTypeDeclaration.bodyDeclarations())
            .stream()
            .filter(declaration -> isMethod(declaration))
            .map(declaration -> (MethodDeclaration) declaration)
            .filter(method -> isSetter(method))
            .map(method -> createBuilderField(method))
            .collect(Collectors.toList());
}
 
Example #28
Source File: InOutFlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void endVisit(MethodDeclaration node) {
	super.endVisit(node);
	FlowInfo info = accessFlowInfo(node);
	for (Iterator<SingleVariableDeclaration> iter = node.parameters().iterator(); iter.hasNext();) {
		clearAccessMode(info, iter.next());
	}
}
 
Example #29
Source File: CyclomaticCalculator.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(final MethodDeclaration arg0) {
	/*
	 * if (isConcrete(arg0)) { complexity.startMethod(); return
	 * super.visit(arg0); } return false;
	 */
	complexity++; // TODO: Not exactly true, but we'll use that
	return super.visit(arg0);
}
 
Example #30
Source File: AbstractMethodCorrectionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected ASTRewrite getRewrite() throws CoreException {
	CompilationUnit astRoot= ASTResolving.findParentCompilationUnit(fNode);
	ASTNode typeDecl= astRoot.findDeclaringNode(fSenderBinding);
	ASTNode newTypeDecl= null;
	boolean isInDifferentCU;
	if (typeDecl != null) {
		isInDifferentCU= false;
		newTypeDecl= typeDecl;
	} else {
		isInDifferentCU= true;
		astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
		newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey());
	}
	createImportRewrite(astRoot);

	if (newTypeDecl != null) {
		ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());

		MethodDeclaration newStub= getStub(rewrite, newTypeDecl);

		ChildListPropertyDescriptor property= ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
		List<BodyDeclaration> members= ASTNodes.getBodyDeclarations(newTypeDecl);

		int insertIndex;
		if (isConstructor()) {
			insertIndex= findConstructorInsertIndex(members);
		} else if (!isInDifferentCU) {
			insertIndex= findMethodInsertIndex(members, fNode.getStartPosition());
		} else {
			insertIndex= members.size();
		}
		ListRewrite listRewriter= rewrite.getListRewrite(newTypeDecl, property);
		listRewriter.insertAt(newStub, insertIndex, null);

		return rewrite;
	}
	return null;
}