本文整理汇总了Java中org.eclipse.jdt.core.dom.MethodDeclaration类的典型用法代码示例。如果您正苦于以下问题:Java MethodDeclaration类的具体用法?Java MethodDeclaration怎么用?Java MethodDeclaration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MethodDeclaration类属于org.eclipse.jdt.core.dom包,在下文中一共展示了MethodDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decideRuleKind
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入依赖的package包/类
private static String decideRuleKind(ReferencedClassesParser parser, Set<String> dependencies) {
CompilationUnit cu = parser.compilationUnit;
if (cu.types().isEmpty()) {
return "java_library";
}
AbstractTypeDeclaration topLevelClass = (AbstractTypeDeclaration) cu.types().get(0);
if ((topLevelClass.getModifiers() & Modifier.ABSTRACT) != 0) {
// Class is abstract, can't be a test.
return "java_library";
}
// JUnit 4 tests
if (parser.className.endsWith("Test") && dependencies.contains("org.junit.Test")) {
return "java_test";
}
if (any(
topLevelClass.bodyDeclarations(),
d -> d instanceof MethodDeclaration && isMainMethod((MethodDeclaration) d))) {
return "java_binary";
}
return "java_library";
}
示例2: handle
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入依赖的package包/类
@Override
public DSubTree handle() {
DSubTree tree = new DSubTree();
// add the expression's subtree (e.g: foo(..).bar() should handle foo(..) first)
DSubTree Texp = new DOMExpression(creation.getExpression()).handle();
tree.addNodes(Texp.getNodes());
// evaluate arguments first
for (Object o : creation.arguments()) {
DSubTree Targ = new DOMExpression((Expression) o).handle();
tree.addNodes(Targ.getNodes());
}
IMethodBinding binding = creation.resolveConstructorBinding();
// get to the generic declaration, if this binding is an instantiation
while (binding != null && binding.getMethodDeclaration() != binding)
binding = binding.getMethodDeclaration();
MethodDeclaration localMethod = Utils.checkAndGetLocalMethod(binding);
if (localMethod != null) {
DSubTree Tmethod = new DOMMethodDeclaration(localMethod).handle();
tree.addNodes(Tmethod.getNodes());
}
else if (Utils.isRelevantCall(binding))
tree.addNode(new DAPICall(binding, Visitor.V().getLineNumber(creation)));
return tree;
}
示例3: asClosure
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入依赖的package包/类
public static Optional<GroovyClosure> asClosure(ASTNodeFactory nodeFactory, GroovyClosureBuilder groovyClosureBuilder,
Expression expression, String methodName) {
if (expression instanceof ClassInstanceCreation) {
ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
if (classInstanceCreation.getAnonymousClassDeclaration() != null) {
AnonymousClassDeclaration classDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
if (classDeclaration.bodyDeclarations().size() == 1 &&
classDeclaration.bodyDeclarations().get(0) instanceof MethodDeclaration &&
((MethodDeclaration) classDeclaration.bodyDeclarations().get(0))
.getName().getIdentifier().equals(methodName)) {
MethodDeclaration methodDeclaration = (MethodDeclaration) classDeclaration.bodyDeclarations().get(0);
List<Statement> statements = nodeFactory.clone(methodDeclaration.getBody()).statements();
GroovyClosure closure = groovyClosureBuilder.aClosure()
.withBodyStatements(statements)
.withTypeLiteral(nodeFactory.typeLiteral(type(nodeFactory, classInstanceCreation)))
.withArgument(nodeFactory.clone((SingleVariableDeclaration) methodDeclaration.parameters().get(0)))
.build();
return Optional.of(closure);
}
}
}
return empty();
}
示例4: createMethod
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入依赖的package包/类
public RastNode createMethod(String methodSignature, HasChildrenNodes parent, String sourceFilePath, boolean constructor, MethodDeclaration ast) {
String methodName = ast.isConstructor() ? "" : ast.getName().getIdentifier();
RastNode rastNode = new RastNode(++nodeCounter);
rastNode.setType(ast.getClass().getSimpleName());
Block body = ast.getBody();
int bodyStart;
int bodyLength;
if (body == null) {
rastNode.addStereotypes(Stereotype.ABSTRACT);
bodyStart = ast.getStartPosition() + ast.getLength();
bodyLength = 0;
} else {
bodyStart = body.getStartPosition();
bodyLength = body.getLength();
}
rastNode.setLocation(new Location(sourceFilePath, ast.getStartPosition(), ast.getStartPosition() + ast.getLength(), bodyStart, bodyStart + bodyLength));
rastNode.setLocalName(methodSignature);
rastNode.setSimpleName(methodName);
parent.addNode(rastNode);
keyMap.put(JavaParser.getKey(rastNode), rastNode);
return rastNode;
}
示例5: getSignatureFromMethodDeclaration
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入依赖的package包/类
public static String getSignatureFromMethodDeclaration(MethodDeclaration methodDeclaration) {
String methodName = methodDeclaration.isConstructor() ? "" : methodDeclaration.getName().getIdentifier();
// if (methodName.equals("allObjectsSorted")) {
// System.out.println();
// }
StringBuilder sb = new StringBuilder();
sb.append(methodName);
sb.append('(');
@SuppressWarnings("unchecked")
Iterator<SingleVariableDeclaration> parameters = methodDeclaration.parameters().iterator();
while (parameters.hasNext()) {
SingleVariableDeclaration parameter = parameters.next();
Type parameterType = parameter.getType();
String typeName = normalizeTypeName(parameterType, parameter.getExtraDimensions(), parameter.isVarargs());
sb.append(typeName);
if (parameters.hasNext()) {
sb.append(", ");
}
}
sb.append(')');
String methodSignature = sb.toString();
return methodSignature;
}
示例6: getBlockType
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入依赖的package包/类
private BlockInfo.Type getBlockType(ASTNode node) {
if(node instanceof TypeDeclaration)
return BlockInfo.Type.TYPE;
else if(node instanceof MethodDeclaration)
return BlockInfo.Type.METHOD;
else if(node instanceof WhileStatement)
return BlockInfo.Type.WHILE;
else if(node instanceof ForStatement)
return BlockInfo.Type.FOR;
else if(node instanceof IfStatement)
return BlockInfo.Type.IF;
else
return BlockInfo.Type.OTHER;
}
示例7: visit
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入依赖的package包/类
@Override
public boolean visit(MethodDeclaration node) {
boolean instanceMember = !node.isConstructor() && !Modifier.isStatic(node.getModifiers());
if(((TypeDeclaration) node.getParent()).isPackageMemberTypeDeclaration()) {
AssignmentVisitor v = new AssignmentVisitor();
node.accept(v);
if(instanceMember) {
MethodInfo m = new MethodInfo(
node.getName().getIdentifier(),
VisibilityInfo.from(node),
node.getReturnType2().resolveBinding().isParameterizedType() ? Object.class.toString() : node.getReturnType2().resolveBinding().getQualifiedName(),
v.params,
v.containsFieldAssignments);
info.addMethod(m);
}
}
return false;
}
示例8: scanForMethodDeclarations
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入依赖的package包/类
/**
* Collects all top level methods from CompilationUnits. (Embedded Methods are currently not collected.)
*
* @param compilationUnitToASTNode the mapping of CompilationUnits to preparsed ASTNodes
* @return the list of all top level methods within the CompilationUnits
*/
public static List<MethodDeclaration> scanForMethodDeclarations(
Map<ICompilationUnit, ASTNode> compilationUnitToASTNode) {
if (compilationUnitToASTNode == null) {
throw new CrystalRuntimeException("null map of compilation units to ASTNodes");
}
// Create an empty list
List<MethodDeclaration> methodList = new LinkedList<MethodDeclaration>();
List<MethodDeclaration> tempMethodList;
// Get all CompilationUnits and look for MethodDeclarations in each
Set<Entry<ICompilationUnit, ASTNode>> entrySet = compilationUnitToASTNode.entrySet();
Iterator<Entry<ICompilationUnit, ASTNode>> iterator = entrySet.iterator();
while(iterator.hasNext()) {
Entry<ICompilationUnit, ASTNode> entry = iterator.next();
ICompilationUnit icu = entry.getKey();
tempMethodList = WorkspaceUtilities.scanForMethodDeclarationsFromAST(compilationUnitToASTNode.get(icu));
methodList.addAll(tempMethodList);
}
return methodList;
}
示例9: listRewriteHandleGeneratedMethods
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入依赖的package包/类
public static RewriteEvent[] listRewriteHandleGeneratedMethods(RewriteEvent parent) {
RewriteEvent[] children = parent.getChildren();
List<RewriteEvent> newChildren = new ArrayList<RewriteEvent>();
List<RewriteEvent> modifiedChildren = new ArrayList<RewriteEvent>();
for (int i = 0; i < children.length; i++) {
RewriteEvent child = children[i];
boolean isGenerated = isGenerated((org.eclipse.jdt.core.dom.ASTNode) child.getOriginalValue());
if (isGenerated) {
boolean isReplacedOrRemoved = child.getChangeKind() == RewriteEvent.REPLACED || child.getChangeKind() == RewriteEvent.REMOVED;
boolean convertingFromMethod = child.getOriginalValue() instanceof org.eclipse.jdt.core.dom.MethodDeclaration;
if (isReplacedOrRemoved && convertingFromMethod && child.getNewValue() != null) {
modifiedChildren.add(new NodeRewriteEvent(null, child.getNewValue()));
}
} else {
newChildren.add(child);
}
}
// Since Eclipse doesn't honor the "insert at specified location" for already existing members,
// we'll just add them last
newChildren.addAll(modifiedChildren);
return newChildren.toArray(new RewriteEvent[newChildren.size()]);
}
示例10: populateMethodDeclarations
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入依赖的package包/类
private void populateMethodDeclarations(TypeDeclaration declaration){
TypeDeclaration[] nestedTypes = declaration.getTypes();
for (int i = 0; i < nestedTypes.length; i++) {
TypeDeclaration nestedType = nestedTypes[i];
populateMethodDeclarations(nestedType);
}
FieldDeclaration[] fields = declaration.getFields();
for (FieldDeclaration fieldDeclaration : fields) {
fieldDeclaration.accept(new HeuristicOwnedVisitor());
}
MethodDeclaration[] methods = declaration.getMethods();
for (MethodDeclaration methodDeclaration : methods) {
methodDeclaration.accept(new HeuristicOwnedVisitor());
methodDeclaration.accept(new HeuristicOwnedLocalsVisitor());
this.methodDecls.add(methodDeclaration);
}
}
示例11: checkMethodsBody
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入依赖的package包/类
/**
* Method that check the method's body to detect some
* connection between them
* @author Mariana Azevedo
* @since 20/01/2016
* @param firstMethod
* @param secondMethod
*/
private void checkMethodsBody(MethodDeclaration firstMethod, MethodDeclaration secondMethod) {
if (firstMethod != null && secondMethod != null){
Block firstMethodBody = firstMethod.getBody();
Block secondMethodBody = secondMethod.getBody();
if (firstMethodBody != null && secondMethodBody != null){
for (String attribute : listOfAttributes){
if (firstMethodBody.toString().contains(attribute) &&
secondMethodBody.toString().contains(attribute)){
numDirectConnections++;
}
}
}
}
}
示例12: calculateWeightMethods
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入依赖的package包/类
/**
* Method to calculate the sum of the complexities of all class methods.
* @author Mariana Azevedo
* @since 13/07/2014
* @param node
*/
@SuppressWarnings("unchecked")
private void calculateWeightMethods(CompilationUnit node){
for (Object type : node.types()){
if ((type instanceof TypeDeclaration) && !((TypeDeclaration) type).isInterface()){
List<TypeDeclaration> bodyDeclarationsList = ((TypeDeclaration) type).
bodyDeclarations();
Iterator<TypeDeclaration> itBodyDeclaration = bodyDeclarationsList.iterator();
while (itBodyDeclaration.hasNext()){
Object itItem = itBodyDeclaration.next();
if (itItem instanceof MethodDeclaration){
checkStatementsInMethodsDeclaration(itItem);
}
}
this.wmcIndex += this.visitor.getCyclomaticComplexityIndex();
}
}
}
示例13: getMethodDeclaration
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入依赖的package包/类
/***
* Lookup an ast.MethodDeclaration based on className and methodName
*
* @param qualifiedTypeName
* @param methodName
* @return ast.MethodDeclaration
*
* HACK: XXX, also include in the search type of parameters.
* Currently the search does not distinguish between C.m and C.m(A)
* class C{
* void m(){}
* void m(A a){}
* }
*/
public static ast.MethodDeclaration getMethodDeclaration(String qualifiedTypeName, String methodName) {
ast.MethodDeclaration methodDeclaration = Adapter.getInstance().getMethodDeclaration(qualifiedTypeName + methodName);
if (methodDeclaration != null)
return methodDeclaration;
// If not found, it may not have been added yet?
// XXX. But why not do this once?
Collection<ast.MethodDeclaration> allNodes = Adapter.getInstance().getMethodDeclarations();
for (ast.MethodDeclaration md : allNodes) {
ast.TypeDeclaration td = md.enclosingType;
if (td != null && td.type != null)
if (td.type.getFullyQualifiedName().equals(qualifiedTypeName))
if (md.methodName.equals(methodName)) {
Adapter.getInstance().mapMethodDeclaration(md);
return md;
}
}
return null;
}
示例14: getNumberOfIndirectConnections
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入依赖的package包/类
/**
* Method to get the number of methods with indirect connections.
* @author Mariana Azevedo
* @since 13/07/2014
* @param methodsWithDirectConn
* @param itMethods
*/
private void getNumberOfIndirectConnections(List<MethodDeclaration> methodsWithDirectConn,
Iterator<MethodDeclaration> itMethods){
int i=0;
while (itMethods.hasNext()){
MethodDeclaration firstMethod = itMethods.next();
if (firstMethod != null){
Block firstMethodBody = firstMethod.getBody();
if (firstMethodBody != null){
SimpleName methodDeclaration = methodsWithDirectConn.get(i).getName();
if (firstMethodBody.toString().contains(methodDeclaration.toString())){
numIndirectConnections++;
}
}
}
}
}
示例15: getIJavaElement
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入依赖的package包/类
public static IJavaElement getIJavaElement(ASTNode node){
IJavaElement javaElement = null;
// Find IJavaElement corresponding to the ASTNode
if (node instanceof MethodDeclaration) {
javaElement = ((MethodDeclaration) node).resolveBinding()
.getJavaElement();
} else if (node instanceof VariableDeclaration) {
javaElement = ((VariableDeclaration) node).resolveBinding()
.getJavaElement();
}else if(node instanceof TypeDeclaration){
javaElement = ((TypeDeclaration)node).resolveBinding()
.getJavaElement();
}else if(node instanceof ClassInstanceCreation){
javaElement = ((ClassInstanceCreation)node).resolveConstructorBinding().getJavaElement();
}
return javaElement;
}