List of usage examples for org.eclipse.jdt.core.dom MethodInvocation resolveTypeBinding
public final ITypeBinding resolveTypeBinding()
From source file:fr.imag.exschema.mongodb.MongoInsertVisitor.java
License:Open Source License
/** * Decide whether or not the given invocation represents a MongoDB * collection's insert operation./*from w w w.j a v a 2 s . c o m*/ * * @param invocation * @return */ private boolean isInsertMethod(final MethodInvocation invocation) { boolean returnValue; ITypeBinding typeBinding; returnValue = false; typeBinding = invocation.resolveTypeBinding(); if (typeBinding != null) { // Analyze when documents are saved in mongodb if (typeBinding.getQualifiedName().toString().equals("com.mongodb.WriteResult")) { if (invocation.getName().toString().equals("insert")) { returnValue = true; } } } return returnValue; }
From source file:jmockit.assist.MockASTVisitor.java
License:Open Source License
@Override public boolean visit(final MethodInvocation node) { IMethodBinding meth = node.resolveMethodBinding(); if (meth == null) { return false; }/*from ww w . java2 s . co m*/ if (MockUtil.isMockUpType(meth.getDeclaringClass()) && MockUtil.GET_INST.equals(meth.getName())) { ITypeBinding returnType = node.resolveTypeBinding(); if (!returnType.isInterface()) { String msg = "getMockInstance() used on mock of class " + returnType.getName() + ". Use on interfaces"; addMarker(node.getName(), msg, false); } } visitItFieldInvocation(node, meth); return true; }
From source file:lang.java.jdt.internal.BindingsResolver.java
License:Open Source License
public void resolveBindings(MethodInvocation node) { importBinding(node.resolveMethodBinding()); importBinding(node.resolveTypeBinding()); }
From source file:org.autorefactor.refactoring.rules.UnboxingRatherThanExplicitMethodRefactoring.java
License:Open Source License
@Override public boolean visit(MethodInvocation node) { if (node.getExpression() != null && getJavaMinorVersion() >= 5 && (isMethod(node, "java.lang.Boolean", "booleanValue") || isMethod(node, "java.lang.Byte", "byteValue") || isMethod(node, "java.lang.Character", "charValue") || isMethod(node, "java.lang.Short", "shortValue") || isMethod(node, "java.lang.Integer", "intValue") || isMethod(node, "java.lang.Long", "longValue") || isMethod(node, "java.lang.Float", "floatValue") || isMethod(node, "java.lang.Double", "doubleValue"))) { final ITypeBinding actualResultType = getDestinationType(node); if (actualResultType != null && actualResultType.isAssignmentCompatible(node.resolveTypeBinding())) { useUnboxing(node);/*from w ww. j a va 2 s.c o m*/ return DO_NOT_VISIT_SUBTREE; } } return VISIT_SUBTREE; }
From source file:org.evosuite.junit.TestExtractingVisitor.java
License:Open Source License
/** * <p>/*from ww w . ja v a 2 s. co m*/ * retrieveTypeClass * </p> * * @param argument * a {@link java.lang.Object} object. * @return a {@link java.lang.Class} object. */ protected Class<?> retrieveTypeClass(Object argument) { assert argument != null; if (argument instanceof SimpleType) { SimpleType simpleType = (SimpleType) argument; return retrieveTypeClass(simpleType); } if (argument instanceof ITypeBinding) { ITypeBinding binding = (ITypeBinding) argument; return retrieveTypeClass(binding); } if (argument instanceof IVariableBinding) { IVariableBinding variableBinding = (IVariableBinding) argument; return retrieveTypeClass(variableBinding.getType()); } if (argument instanceof SimpleName) { SimpleName simpleName = (SimpleName) argument; return retrieveTypeClass(simpleName.resolveBinding()); } if (argument instanceof StringLiteral) { return String.class; } if (argument instanceof NumberLiteral) { return retrieveTypeClass((NumberLiteral) argument); } if (argument instanceof PrimitiveType) { PrimitiveType primitiveType = (PrimitiveType) argument; String typeCode = primitiveType.getPrimitiveTypeCode().toString(); Class<?> result = PRIMITIVE_TYPECODE_MAPPING.get(typeCode); assert result != null : "Could not resolve typecode " + typeCode + "."; return result; } if (argument instanceof ArrayType) { ArrayType arrayType = (ArrayType) argument; return retrieveTypeClass(arrayType); } if (argument instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) argument; return retrieveTypeClass(parameterizedType.getType()); } if (argument instanceof VariableDeclarationFragment) { VariableDeclarationFragment varDeclFrgmnt = (VariableDeclarationFragment) argument; return retrieveTypeClass(varDeclFrgmnt.resolveBinding()); } if (argument instanceof InfixExpression) { InfixExpression infixExpr = (InfixExpression) argument; ITypeBinding refTypeBinding = infixExpr.resolveTypeBinding(); if (refTypeBinding != null) { return retrieveTypeClass(refTypeBinding); } else { throw new RuntimeException( "Could not determine type class of infix expression '" + infixExpr + "'."); } } if (argument instanceof MethodInvocation) { MethodInvocation methodInvocation = (MethodInvocation) argument; ITypeBinding typeBinding = methodInvocation.resolveTypeBinding(); if (typeBinding != null) { return retrieveTypeClass(typeBinding); } Expression typeExpression = methodInvocation.getExpression(); if (typeExpression instanceof MethodInvocation) { MethodInvocation parentMethodInvocation = (MethodInvocation) typeExpression; IMethodBinding parentMethodBinding = parentMethodInvocation.resolveMethodBinding(); return retrieveTypeClass(parentMethodBinding.getDeclaringClass()); } else { return retrieveTypeClass(typeExpression); } } if (argument instanceof ArrayAccess) { ArrayAccess arrayAccess = (ArrayAccess) argument; return retrieveTypeClass(arrayAccess.getArray()); } if (argument instanceof Class<?>) { return (Class<?>) argument; } if (argument instanceof ClassInstanceCreation) { return retrieveTypeClass(((ClassInstanceCreation) argument).resolveTypeBinding()); } if (argument instanceof BooleanLiteral) { return Boolean.TYPE; } throw new UnsupportedOperationException( "Retrieval of type " + argument.getClass() + " not implemented yet!"); }
From source file:org.gw4e.eclipse.facade.JDTManager.java
License:Open Source License
/** * @param project//from w ww .j a va 2s . c om * @param itype * @return * @throws JavaModelException */ private static IPath findPathInStaticField(IProject project, IType itype) throws JavaModelException { List<IPath> wrapper = new ArrayList<IPath>(); ICompilationUnit cu = itype.getCompilationUnit(); CompilationUnit ast = parse(cu); ast.accept(new ASTVisitor() { public boolean visit(VariableDeclarationFragment node) { SimpleName simpleName = node.getName(); IBinding bding = simpleName.resolveBinding(); if (bding instanceof IVariableBinding) { IVariableBinding binding = (IVariableBinding) bding; String type = binding.getType().getBinaryName(); // String name = simpleName.getFullyQualifiedName(); if ("MODEL_PATH".equals(name) && "java.nio.file.Path".equals(type)) { Expression expression = node.getInitializer(); if (expression instanceof MethodInvocation) { MethodInvocation mi = (MethodInvocation) expression; if ("get".equals(mi.resolveMethodBinding().getName()) && "java.nio.file.Path".equals(mi.resolveTypeBinding().getBinaryName())) { StringLiteral sl = (StringLiteral) mi.arguments().get(0); String argument = sl.getLiteralValue(); try { IPath p = ResourceManager.find(project, argument); wrapper.add(p); } catch (CoreException e) { ResourceManager.logException(e); } } } } } return true; } }); if (wrapper.size() > 0) return wrapper.get(0); return null; }
From source file:padl.creator.javafile.eclipse.astVisitors.CompleteVisitor.java
License:Open Source License
@Override public void endVisit(final MethodInvocation node) { ProxyConsole.getInstance().debugOutput().println( " SuperMethodInvocation " + node.toString() + node.resolveTypeBinding().getQualifiedName()); super.endVisit(node); }