本文整理汇总了Java中org.eclipse.jdt.core.dom.TypeLiteral类的典型用法代码示例。如果您正苦于以下问题:Java TypeLiteral类的具体用法?Java TypeLiteral怎么用?Java TypeLiteral使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeLiteral类属于org.eclipse.jdt.core.dom包,在下文中一共展示了TypeLiteral类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypeLiteralSelection
import org.eclipse.jdt.core.dom.TypeLiteral; //导入依赖的package包/类
/**
* @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;
}
示例2: createGetClassMethodInvocation
import org.eclipse.jdt.core.dom.TypeLiteral; //导入依赖的package包/类
@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;
}
示例3: createProposal
import org.eclipse.jdt.core.dom.TypeLiteral; //导入依赖的package包/类
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));
}
示例4: parametrizedTypeOf
import org.eclipse.jdt.core.dom.TypeLiteral; //导入依赖的package包/类
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());
}
}
示例5: anyMapOf
import org.eclipse.jdt.core.dom.TypeLiteral; //导入依赖的package包/类
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());
}
}
示例6: anyMatcher
import org.eclipse.jdt.core.dom.TypeLiteral; //导入依赖的package包/类
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();
}
}
示例7: addThrownSupport
import org.eclipse.jdt.core.dom.TypeLiteral; //导入依赖的package包/类
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())))));
}
示例8: endVisit
import org.eclipse.jdt.core.dom.TypeLiteral; //导入依赖的package包/类
@Override
public void endVisit(TypeLiteral node) {
if (skipNode(node)) {
return;
}
assignFlowInfo(node, node.getType());
}
示例9: unboundedWildcardAllowed
import org.eclipse.jdt.core.dom.TypeLiteral; //导入依赖的package包/类
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;
}
示例10: obtainTypeLiteralAnnotation
import org.eclipse.jdt.core.dom.TypeLiteral; //导入依赖的package包/类
public static ITypeBinding obtainTypeLiteralAnnotation(BodyDeclaration declaration, Class<?> annotationClass) {
Expression expr = obtainSingleMemberAnnotationValue(declaration, annotationClass);
if (expr instanceof TypeLiteral) {
return ((TypeLiteral) expr).getType().resolveBinding();
}
return null;
}
示例11: visit
import org.eclipse.jdt.core.dom.TypeLiteral; //导入依赖的package包/类
@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);
}
示例12: unboundedWildcardAllowed
import org.eclipse.jdt.core.dom.TypeLiteral; //导入依赖的package包/类
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;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:15,代码来源:InferTypeArgumentsRefactoring.java
示例13: repairBug
import org.eclipse.jdt.core.dom.TypeLiteral; //导入依赖的package包/类
@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);
}
示例14: makeTypeLiteral
import org.eclipse.jdt.core.dom.TypeLiteral; //导入依赖的package包/类
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;
}
示例15: makeEnumConstructor
import org.eclipse.jdt.core.dom.TypeLiteral; //导入依赖的package包/类
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);
}