Java 类org.eclipse.jdt.core.dom.TypeLiteral 实例源码

项目:reflectify    文件:ClassAccessTest.java   
/** 
 * @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;
}
项目:reflectify    文件:MethodInvocationProposalCreator.java   
@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;
}
项目:reflectify    文件:ClassAccessProposalCreator.java   
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));
}
项目:junit2spock    文件:MatcherHandler.java   
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());
    }
}
项目:junit2spock    文件:MatcherHandler.java   
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());
    }
}
项目:junit2spock    文件:MatcherHandler.java   
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();
    }
}
项目:junit2spock    文件:TestMethodModel.java   
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())))));
}
项目:eclipse.jdt.ls    文件:FlowAnalyzer.java   
@Override
public void endVisit(TypeLiteral node) {
    if (skipNode(node)) {
        return;
    }
    assignFlowInfo(node, node.getType());
}
项目:che    文件:InferTypeArgumentsRefactoring.java   
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;
}
项目:txtUML    文件:SharedUtils.java   
public static ITypeBinding obtainTypeLiteralAnnotation(BodyDeclaration declaration, Class<?> annotationClass) {
    Expression expr = obtainSingleMemberAnnotationValue(declaration, annotationClass);
    if (expr instanceof TypeLiteral) {
        return ((TypeLiteral) expr).getType().resolveBinding();
    }
    return null;
}
项目:tassal    文件:TypenameScopeExtractor.java   
@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);
}
项目:Eclipse-Postfix-Code-Completion    文件:InferTypeArgumentsRefactoring.java   
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;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:InferTypeArgumentsRefactoring.java   
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;
}
项目:fb-contrib-eclipse-quick-fixes    文件:LoggerOdditiesResolution.java   
@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);
}
项目:fb-contrib-eclipse-quick-fixes    文件:LoggerOdditiesResolution.java   
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;
}
项目:fb-contrib-eclipse-quick-fixes    文件:UseEnumCollectionsResolution.java   
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);
}
项目:fb-contrib-eclipse-quick-fixes    文件:UseEnumCollectionsResolution.java   
@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;
}
项目:fb-contrib-eclipse-quick-fixes    文件:UseEnumCollectionsResolution.java   
@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;
}
项目:codemining-core    文件:TypenameScopeExtractor.java   
@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);
}
项目:eclipse-tapestry5-plugin    文件:TapestryServiceCapturingVisitor.java   
private String typeLiteralToClassName(Object node)
{
    if (node instanceof TypeLiteral)
    {
        return EclipseUtils.toClassName(tapestryModule.getEclipseProject(), (TypeLiteral) node);
    }
    return null;
}
项目:codehint    文件:ExpressionSkeleton.java   
/**
 * 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);
    }
}
项目:j2d    文件:J2dVisitor.java   
@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;
}
项目:reflectify    文件:ClassInstanceCreationProposalCreator.java   
@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;
}
项目:junit2spock    文件:MatcherHandler.java   
private InfixExpression classMatcher(Type type) {
    TypeLiteral classLiteral = nodeFactory.typeLiteral(nodeFactory.clone(type));
    return nodeFactory.infixExpression(CAST, wildcard(), classLiteral);
}
项目:junit2spock    文件:GroovyClosureBuilder.java   
public Builder withTypeLiteral(TypeLiteral typeLiteral) {
    this.typeLiteral = typeLiteral;
    return this;
}
项目:RefDiff    文件:DependenciesAstVisitor.java   
@Override
public final boolean visit(TypeLiteral node) {
    Type type = node.getType();
    handleTypeBinding(node, type.resolveBinding(), true);
    return true;
}
项目:RefDiff    文件:DependenciesAstVisitor.java   
@Override
public final boolean visit(TypeLiteral node) {
    Type type = node.getType();
    handleTypeBinding(node, type.resolveBinding(), true);
    return true;
}
项目:che    文件:InferTypeArgumentsConstraintCreator.java   
@Override
public void endVisit(TypeLiteral node) {
  ITypeBinding typeBinding = node.resolveTypeBinding();
  ImmutableTypeVariable2 cv = fTCModel.makeImmutableTypeVariable(typeBinding, /*no boxing*/ null);
  setConstraintVariable(node, cv);
}
项目:evosuite    文件:LoggingVisitor.java   
/** {@inheritDoc} */
@Override
public void endVisit(TypeLiteral node) {
    logger.warn("Method endVisitTypeLiteral for " + node + " for " + node + " not implemented!");
    super.endVisit(node);
}
项目:evosuite    文件:LoggingVisitor.java   
/** {@inheritDoc} */
@Override
public boolean visit(TypeLiteral node) {
    logger.warn("Method visitTypeLiteral for " + node + " not implemented!");
    return super.visit(node);
}
项目:Beagle    文件:NotRecursingAstVisitor.java   
@Override
public boolean visit(final TypeLiteral node) {
    return false;
}
项目:Beagle    文件:InstrumentableAstNodeLister.java   
@Override
public boolean visit(final TypeLiteral node) {
    return this.visitInstrumentable(node);
}
项目:tassal    文件:IdentifierPerType.java   
@Override
public boolean visit(final TypeLiteral node) {
    addToMap(identifiers, node, node.getType().toString());
    return super.visit(node);
}
项目:Eclipse-Postfix-Code-Completion    文件:SuperTypeConstraintsCreator.java   
@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));
}
项目:Eclipse-Postfix-Code-Completion    文件:InferTypeArgumentsConstraintCreator.java   
@Override
public void endVisit(TypeLiteral node) {
    ITypeBinding typeBinding= node.resolveTypeBinding();
    ImmutableTypeVariable2 cv= fTCModel.makeImmutableTypeVariable(typeBinding, /*no boxing*/null);
    setConstraintVariable(node, cv);
}
项目:Eclipse-Postfix-Code-Completion    文件:FlowAnalyzer.java   
@Override
public void endVisit(TypeLiteral node) {
    if (skipNode(node))
        return;
    assignFlowInfo(node, node.getType());
}
项目:Eclipse-Postfix-Code-Completion    文件:AstMatchingNodeFinder.java   
@Override
public boolean visit(TypeLiteral node) {
    if (node.subtreeMatch(fMatcher, fNodeToMatch))
        return matches(node);
    return super.visit(node);
}
项目:Eclipse-Postfix-Code-Completion    文件:ConstraintCollector.java   
@Override
public boolean visit(TypeLiteral node) {
    add(fCreator.create(node));
    return true;
}
项目:Eclipse-Postfix-Code-Completion    文件:GenericVisitor.java   
@Override
public void endVisit(TypeLiteral node) {
    endVisitNode(node);
}
项目:Eclipse-Postfix-Code-Completion    文件:GenericVisitor.java   
@Override
public boolean visit(TypeLiteral node) {
    return visitNode(node);
}