/** * @return selection (offset,length) of first simple type node within statement given by <code>statementIndex</code> */ private int[] getTypeLiteralSelection(int statementIndex, IMethod target) { MethodDeclaration targetNode = compileTargetMethod(target); Statement stmt = (Statement) targetNode.getBody().statements().get(statementIndex ); final int[] selection = new int[2]; stmt.accept( new ASTVisitor() { @Override public boolean visit(TypeLiteral node) { if (selection[1] == 0) { selection[0] = node.getStartPosition(); selection[1] = node.getLength(); } return false; } }); return selection; }
@SuppressWarnings("unchecked") private MethodInvocation createGetClassMethodInvocation(MethodInvocation invNode, ITypeBinding[] paramTyps, AST ast) { MethodInvocation result = ast.newMethodInvocation(); result.setName(ast.newSimpleName("getMethod")); //$NON-NLS-1$ StringLiteral methName = ast.newStringLiteral(); methName.setLiteralValue(invNode.getName().getFullyQualifiedName()); result.arguments().add(methName); if (paramTyps != null && paramTyps.length > 0) { for (ITypeBinding paramTyp : paramTyps) { TypeLiteral curTyp = ast.newTypeLiteral(); curTyp.setType(createType(paramTyp, ast)); result.arguments().add(curTyp); } } return result; }
public IJavaCompletionProposal createProposal(ASTNode node, IInvocationContext context) { if (node == null || node.getNodeType() != ASTNode.TYPE_LITERAL) { throw new IllegalArgumentException(ReflectifyMessages.NoOrIllegalNodeError); } TypeLiteral litNode = (TypeLiteral)node; ITypeBinding typeBind = litNode.getType().resolveBinding(); if (typeBind == null) { throw new IllegalArgumentException(ReflectifyMessages.BindingResolutionError); } AST ast = litNode.getAST(); ASTRewrite rewrite = ASTRewrite.create(ast); MethodInvocation methInv = createClassForName(typeBind, ast); rewrite.replace(litNode, methInv, null); // no edit group return new ASTRewriteCorrectionProposal( ReflectifyMessages.ReflectifyAssistProcessor_class, context.getCompilationUnit(), rewrite, getRelevance(), JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_LOCAL)); }
private Type parametrizedTypeOf(MethodInvocation methodInvocation, Class<?> clazz) { if (methodInvocation.arguments().size() == 1 && methodInvocation.arguments().get(0) instanceof TypeLiteral) { return nodeFactory.parameterizedType(nodeFactory.simpleType(clazz.getSimpleName()), singletonList(nodeFactory.clone(((TypeLiteral) methodInvocation.arguments().get(0)).getType()))); } else { return nodeFactory.simpleType(clazz.getSimpleName()); } }
private Type anyMapOf(MethodInvocation methodInvocation, Class<?> clazz) { if (methodInvocation.arguments().size() == 2 && methodInvocation.arguments().get(0) instanceof TypeLiteral && methodInvocation.arguments().get(1) instanceof TypeLiteral) { return nodeFactory.parameterizedType(nodeFactory.simpleType(clazz.getSimpleName()), ImmutableList.of(nodeFactory.clone(((TypeLiteral) methodInvocation.arguments().get(0)).getType()), nodeFactory.clone(((TypeLiteral) methodInvocation.arguments().get(1)).getType()))); } else { return nodeFactory.simpleType(clazz.getSimpleName()); } }
private ASTNode anyMatcher(MethodInvocation methodInvocation) { if (methodInvocation.arguments().size() == 1 && methodInvocation.arguments().get(0) instanceof TypeLiteral) { return classMatcher(((TypeLiteral) methodInvocation.arguments().get(0)).getType()); } else { return wildcard(); } }
private void addThrownSupport(MethodDeclaration methodDeclaration) { Optional<Annotation> testAnnotation = annotatedWith(methodDeclaration, "Test"); Optional<Expression> expected = testAnnotation .filter(annotation -> annotation instanceof NormalAnnotation) .flatMap(this::expectedException); expected.ifPresent(expression -> body() .add(astNodeFactory().methodInvocation(THROWN, singletonList(astNodeFactory().simpleName(((TypeLiteral) expression).getType().toString()))))); }
@Override public void endVisit(TypeLiteral node) { if (skipNode(node)) { return; } assignFlowInfo(node, node.getType()); }
private static boolean unboundedWildcardAllowed(Type originalType) { ASTNode parent = originalType.getParent(); while (parent instanceof Type) parent = parent.getParent(); if (parent instanceof ClassInstanceCreation) { return false; } else if (parent instanceof AbstractTypeDeclaration) { return false; } else if (parent instanceof TypeLiteral) { return false; } return true; }
public static ITypeBinding obtainTypeLiteralAnnotation(BodyDeclaration declaration, Class<?> annotationClass) { Expression expr = obtainSingleMemberAnnotationValue(declaration, annotationClass); if (expr instanceof TypeLiteral) { return ((TypeLiteral) expr).getType().resolveBinding(); } return null; }
@Override public boolean visit(TypeLiteral node) { final String type = node.getType().toString(); if (topMethod != null && methodsAsRoot) { types.put(topMethod, type); } else if (topClass != null) { types.put(topClass, type); } return super.visit(node); }
private static boolean unboundedWildcardAllowed(Type originalType) { ASTNode parent= originalType.getParent(); while (parent instanceof Type) parent= parent.getParent(); if (parent instanceof ClassInstanceCreation) { return false; } else if (parent instanceof AbstractTypeDeclaration) { return false; } else if (parent instanceof TypeLiteral) { return false; } return true; }
@Override protected void repairBug(ASTRewrite rewrite, CompilationUnit workingUnit, BugInstance bug) throws BugResolutionException { ASTNode node = getASTNode(workingUnit, bug.getPrimarySourceLineAnnotation()); LOVisitor visitor = new LOVisitor(); node.accept(visitor); TypeLiteral fixedTypeLiteral = makeTypeLiteral(rewrite, node); rewrite.replace(visitor.badArgument, fixedTypeLiteral, null); }
private TypeLiteral makeTypeLiteral(ASTRewrite rewrite, ASTNode node) { TypeDeclaration tDeclaration = TraversalUtil.findClosestAncestor(node, TypeDeclaration.class); SimpleName name = tDeclaration.getName(); AST ast = rewrite.getAST(); SimpleType parentType = ast.newSimpleType(ast.newSimpleName(name.getIdentifier())); TypeLiteral fixedTypeLiteral = ast.newTypeLiteral(); fixedTypeLiteral.setType(parentType); return fixedTypeLiteral; }
private Expression makeEnumConstructor(EnumCollectionsVisitor visitor, ASTRewrite rewrite) { AST ast = rewrite.getAST(); TypeLiteral enumDotClass = ast.newTypeLiteral(); // this is the EnumHere.class enumDotClass.setType(ast.newSimpleType(ast.newName(visitor.enumNameToUse))); if (visitor.isMap) { return makeEnumMap(enumDotClass, ast); } return makeEnumSet(enumDotClass, ast); }
@SuppressWarnings("unchecked") private Expression makeEnumSet(TypeLiteral enumType, AST ast) { MethodInvocation newEnumSet = ast.newMethodInvocation(); newEnumSet.setExpression(ast.newSimpleName("EnumSet")); newEnumSet.setName(ast.newSimpleName("noneOf")); newEnumSet.arguments().add(enumType); return newEnumSet; }
@SuppressWarnings("unchecked") private Expression makeEnumMap(TypeLiteral enumType, AST ast) { ClassInstanceCreation newEnumMap = ast.newClassInstanceCreation(); Type enumMap = ast.newSimpleType(ast.newName("EnumMap")); // makes the <> braces by default newEnumMap.setType(ast.newParameterizedType(enumMap)); newEnumMap.arguments().add(enumType); return newEnumMap; }
private String typeLiteralToClassName(Object node) { if (node instanceof TypeLiteral) { return EclipseUtils.toClassName(tapestryModule.getEclipseProject(), (TypeLiteral) node); } return null; }
/** * Fills type literal skeleton pieces. * @param node The type literal part of the skeleton. * @return The synthesized expressions corresponding to this * skeleton piece and the type constraint representing their types. */ private ExpressionsAndTypeConstraints fillTypeLiteral(Expression node) { try { codehint.ast.Expression expr = ASTConverter.copy(node); IJavaType type = EclipseUtils.getType(((TypeLiteral)node).getType().toString(), stack, target, typeCache); IJavaClassObject classObj = ((IJavaReferenceType)type).getClassObject(); IJavaType classObjType = classObj.getJavaType(); expr.setStaticType(classObjType); Result result = new Result(classObj, valueCache, thread); expressionEvaluator.setResult(expr, result, Collections.<Effect>emptySet()); return new ExpressionsAndTypeConstraints(expr, new SupertypeBound(classObjType)); } catch (DebugException e) { throw new RuntimeException(e); } }
@Override public boolean visit(TypeLiteral node) { //System.out.println("Found: " + node.getClass()); // TODO I don't know if this is the right way to do this print("typeid("); node.getType().accept(this); print(")"); return false; }
@SuppressWarnings("unchecked") private MethodInvocation createGetConstructorMethod(ITypeBinding[] paramTyps, AST ast) { MethodInvocation methGet = ast.newMethodInvocation(); methGet.setName(ast.newSimpleName("getConstructor")); //$NON-NLS-1$ for (ITypeBinding paramTyp : paramTyps) { TypeLiteral curTyp = ast.newTypeLiteral(); curTyp.setType(createType(paramTyp, ast)); methGet.arguments().add(curTyp); } return methGet; }
private InfixExpression classMatcher(Type type) { TypeLiteral classLiteral = nodeFactory.typeLiteral(nodeFactory.clone(type)); return nodeFactory.infixExpression(CAST, wildcard(), classLiteral); }
public Builder withTypeLiteral(TypeLiteral typeLiteral) { this.typeLiteral = typeLiteral; return this; }
@Override public final boolean visit(TypeLiteral node) { Type type = node.getType(); handleTypeBinding(node, type.resolveBinding(), true); return true; }
@Override public void endVisit(TypeLiteral node) { ITypeBinding typeBinding = node.resolveTypeBinding(); ImmutableTypeVariable2 cv = fTCModel.makeImmutableTypeVariable(typeBinding, /*no boxing*/ null); setConstraintVariable(node, cv); }
/** {@inheritDoc} */ @Override public void endVisit(TypeLiteral node) { logger.warn("Method endVisitTypeLiteral for " + node + " for " + node + " not implemented!"); super.endVisit(node); }
/** {@inheritDoc} */ @Override public boolean visit(TypeLiteral node) { logger.warn("Method visitTypeLiteral for " + node + " not implemented!"); return super.visit(node); }
@Override public boolean visit(final TypeLiteral node) { return false; }
@Override public boolean visit(final TypeLiteral node) { return this.visitInstrumentable(node); }
@Override public boolean visit(final TypeLiteral node) { addToMap(identifiers, node, node.getType().toString()); return super.visit(node); }
@Override public final void endVisit(final Type node) { final ASTNode parent= node.getParent(); if (!(parent instanceof AbstractTypeDeclaration) && !(parent instanceof ClassInstanceCreation) && !(parent instanceof TypeLiteral) && (!(parent instanceof InstanceofExpression) || fInstanceOf)) node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, fModel.createTypeVariable(node)); }
@Override public void endVisit(TypeLiteral node) { ITypeBinding typeBinding= node.resolveTypeBinding(); ImmutableTypeVariable2 cv= fTCModel.makeImmutableTypeVariable(typeBinding, /*no boxing*/null); setConstraintVariable(node, cv); }
@Override public void endVisit(TypeLiteral node) { if (skipNode(node)) return; assignFlowInfo(node, node.getType()); }
@Override public boolean visit(TypeLiteral node) { if (node.subtreeMatch(fMatcher, fNodeToMatch)) return matches(node); return super.visit(node); }
@Override public boolean visit(TypeLiteral node) { add(fCreator.create(node)); return true; }
@Override public void endVisit(TypeLiteral node) { endVisitNode(node); }
@Override public boolean visit(TypeLiteral node) { return visitNode(node); }