当前位置: 首页>>代码示例>>Java>>正文


Java TypeLiteral类代码示例

本文整理汇总了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;
}
 
开发者ID:jwloka,项目名称:reflectify,代码行数:20,代码来源:ClassAccessTest.java

示例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;
}
 
开发者ID:jwloka,项目名称:reflectify,代码行数:17,代码来源:MethodInvocationProposalCreator.java

示例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));
}
 
开发者ID:jwloka,项目名称:reflectify,代码行数:24,代码来源:ClassAccessProposalCreator.java

示例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());
    }
}
 
开发者ID:opaluchlukasz,项目名称:junit2spock,代码行数:9,代码来源:MatcherHandler.java

示例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());
    }
}
 
开发者ID:opaluchlukasz,项目名称:junit2spock,代码行数:12,代码来源:MatcherHandler.java

示例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();
    }
}
 
开发者ID:opaluchlukasz,项目名称:junit2spock,代码行数:8,代码来源:MatcherHandler.java

示例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())))));
}
 
开发者ID:opaluchlukasz,项目名称:junit2spock,代码行数:11,代码来源:TestMethodModel.java

示例8: endVisit

import org.eclipse.jdt.core.dom.TypeLiteral; //导入依赖的package包/类
@Override
public void endVisit(TypeLiteral node) {
	if (skipNode(node)) {
		return;
	}
	assignFlowInfo(node, node.getType());
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:8,代码来源:FlowAnalyzer.java

示例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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:14,代码来源:InferTypeArgumentsRefactoring.java

示例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;
}
 
开发者ID:ELTE-Soft,项目名称:txtUML,代码行数:8,代码来源:SharedUtils.java

示例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);
}
 
开发者ID:mast-group,项目名称:tassal,代码行数:11,代码来源:TypenameScopeExtractor.java

示例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);
}
 
开发者ID:kjlubick,项目名称:fb-contrib-eclipse-quick-fixes,代码行数:10,代码来源:LoggerOdditiesResolution.java

示例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;
}
 
开发者ID:kjlubick,项目名称:fb-contrib-eclipse-quick-fixes,代码行数:10,代码来源:LoggerOdditiesResolution.java

示例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);
}
 
开发者ID:kjlubick,项目名称:fb-contrib-eclipse-quick-fixes,代码行数:11,代码来源:UseEnumCollectionsResolution.java


注:本文中的org.eclipse.jdt.core.dom.TypeLiteral类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。