下面列出了怎么用org.eclipse.jdt.core.dom.TypeLiteral的API类实例代码及写法,或者点击链接到github查看源代码。
protected boolean isTypeHolder(Object o) {
if(o.getClass().equals(MethodInvocation.class) || o.getClass().equals(SuperMethodInvocation.class)
|| o.getClass().equals(NumberLiteral.class) || o.getClass().equals(StringLiteral.class)
|| o.getClass().equals(CharacterLiteral.class) || o.getClass().equals(BooleanLiteral.class)
|| o.getClass().equals(TypeLiteral.class) || o.getClass().equals(NullLiteral.class)
|| o.getClass().equals(ArrayCreation.class)
|| o.getClass().equals(ClassInstanceCreation.class)
|| o.getClass().equals(ArrayAccess.class) || o.getClass().equals(FieldAccess.class)
|| o.getClass().equals(SuperFieldAccess.class) || o.getClass().equals(ParenthesizedExpression.class)
|| o.getClass().equals(SimpleName.class) || o.getClass().equals(QualifiedName.class)
|| o.getClass().equals(CastExpression.class) || o.getClass().equals(InfixExpression.class)
|| o.getClass().equals(PrefixExpression.class) || o.getClass().equals(InstanceofExpression.class)
|| o.getClass().equals(ThisExpression.class) || o.getClass().equals(ConditionalExpression.class))
return true;
return false;
}
private TyLiteral visit(TypeLiteral node) {
int startLine = _cunit.getLineNumber(node.getStartPosition());
int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength());
TyLiteral tyLiteral = new TyLiteral(startLine, endLine, node);
tyLiteral.setValue(node.getType());
tyLiteral.setType(node.getType());
return tyLiteral;
}
private NormalAnnotation createAnnotation(AST ast, CompilationUnitModificationDomain compilationUnitModificationDomain, TypeDeclaration builderType) {
TypeLiteral typeLiteral = createBuilderClassReferenceLiteral(ast, compilationUnitModificationDomain, builderType);
NormalAnnotation jsonDeserializeAnnotation = ast.newNormalAnnotation();
jsonDeserializeAnnotation.setTypeName(ast.newSimpleName(JSON_DESERIALIZE_CLASS_NAME));
MemberValuePair builderAttribute = ast.newMemberValuePair();
builderAttribute.setName(ast.newSimpleName("builder"));
builderAttribute.setValue(typeLiteral);
jsonDeserializeAnnotation.values().add(builderAttribute);
return jsonDeserializeAnnotation;
}
private TypeLiteral createBuilderClassReferenceLiteral(AST ast, CompilationUnitModificationDomain compilationUnitModificationDomain, TypeDeclaration builderType) {
String originalClassName = compilationUnitModificationDomain.getOriginalType().getName().toString();
String builderClassName = builderType.getName().toString();
QualifiedType qualifiedType = ast.newQualifiedType(ast.newSimpleType(ast.newSimpleName(originalClassName)), ast.newSimpleName(builderClassName));
TypeLiteral typeLiteral = ast.newTypeLiteral();
typeLiteral.setType(qualifiedType);
return typeLiteral;
}
@Override
public void endVisit(TypeLiteral node) {
if (skipNode(node)) {
return;
}
assignFlowInfo(node, node.getType());
}
@Override
public boolean visit(final TypeLiteral node) {
if (this.fallBackStrategy) {
this.appendToBuffer("typeof(");
}
node.getType().accept(this);
if (this.fallBackStrategy) {
this.appendToBuffer(")");
}
return false;
}
@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);
}
public boolean visit(TypeLiteral node) {
typeLiterals.add(node.toString());
if(current.getUserObject() != null) {
AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject();
anonymous.getTypeLiterals().add(node.toString());
}
return super.visit(node);
}
public static ITypeBinding obtainTypeBindingFromExpression(Expression expr) {
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;
}
public boolean instanceOf(Expression expression) {
if(expression instanceof BooleanLiteral || expression instanceof CharacterLiteral || expression instanceof StringLiteral ||
expression instanceof NullLiteral || expression instanceof NumberLiteral || expression instanceof TypeLiteral)
return true;
else
return false;
}
public boolean visit(TypeLiteral expr) {
String key;
if(expr.getType().resolveBinding() != null)
key = expr.getType().resolveBinding().getKey() + ".class";
else
key = expr.toString();
bindingKeys.add(key);
return false;
}
public boolean visit(TypeLiteral expr) {
/*
* ( Type | void ) . class
*/
activateDiffStyle(expr);
handleType(expr.getType());
appendPeriod();
styledString.append("class", determineDiffStyle(expr, new StyledStringStyler(keywordStyle)));
deactivateDiffStyle(expr);
return false;
}
@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);
}
public Entry typeLiteral(Object o) {
TypeLiteral typeLit = (TypeLiteral)o;
Type type = typeLit.getType();
return entry(type);
}
@Override
public boolean visit(final TypeLiteral node) {
addToMap(identifiers, node, node.getType().toString());
return super.visit(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);
}
public LiteralObject(Expression expression) {
if(expression instanceof StringLiteral) {
StringLiteral stringLiteral = (StringLiteral)expression;
literalType = LiteralType.STRING;
value = stringLiteral.getLiteralValue();
type = TypeObject.extractTypeObject(stringLiteral.resolveTypeBinding().getQualifiedName());
}
else if(expression instanceof NullLiteral) {
NullLiteral nullLiteral = (NullLiteral)expression;
literalType = LiteralType.NULL;
value = "null";
if(nullLiteral.resolveTypeBinding() != null) {
type = TypeObject.extractTypeObject(nullLiteral.resolveTypeBinding().getQualifiedName());
}
}
else if(expression instanceof NumberLiteral) {
NumberLiteral numberLiteral = (NumberLiteral)expression;
literalType = LiteralType.NUMBER;
value = numberLiteral.getToken();
type = TypeObject.extractTypeObject(numberLiteral.resolveTypeBinding().getQualifiedName());
}
else if(expression instanceof BooleanLiteral) {
BooleanLiteral booleanLiteral = (BooleanLiteral)expression;
literalType = LiteralType.BOOLEAN;
value = Boolean.toString(booleanLiteral.booleanValue());
type = TypeObject.extractTypeObject(booleanLiteral.resolveTypeBinding().getQualifiedName());
}
else if(expression instanceof CharacterLiteral) {
CharacterLiteral characterLiteral = (CharacterLiteral)expression;
literalType = LiteralType.CHARACTER;
value = Character.toString(characterLiteral.charValue());
type = TypeObject.extractTypeObject(characterLiteral.resolveTypeBinding().getQualifiedName());
}
else if(expression instanceof TypeLiteral) {
TypeLiteral typeLiteral = (TypeLiteral)expression;
literalType = LiteralType.TYPE;
value = typeLiteral.getType().toString();
type = TypeObject.extractTypeObject(typeLiteral.resolveTypeBinding().getQualifiedName());
}
this.literal = ASTInformationGenerator.generateASTInformation(expression);
}
public boolean instanceOf(Expression expression) {
if(expression instanceof TypeLiteral)
return true;
else
return false;
}
private void handleExpression(Expression expression) {
if (expression instanceof ArrayAccess) {
visit((ArrayAccess) expression);
} else if (expression instanceof ArrayCreation) {
visit((ArrayCreation) expression);
} else if (expression instanceof ArrayInitializer) {
visit((ArrayInitializer) expression);
} else if (expression instanceof Assignment) {
visit((Assignment) expression);
} else if (expression instanceof BooleanLiteral) {
visit((BooleanLiteral) expression);
} else if (expression instanceof CastExpression) {
visit((CastExpression) expression);
} else if (expression instanceof CharacterLiteral) {
visit((CharacterLiteral) expression);
} else if (expression instanceof ClassInstanceCreation) {
visit((ClassInstanceCreation) expression);
} else if (expression instanceof ConditionalExpression) {
visit((ConditionalExpression) expression);
} else if (expression instanceof FieldAccess) {
visit((FieldAccess) expression);
} else if (expression instanceof InfixExpression) {
visit((InfixExpression) expression);
} else if (expression instanceof InstanceofExpression) {
visit((InstanceofExpression) expression);
} else if (expression instanceof MethodInvocation) {
visit((MethodInvocation) expression);
} else if (expression instanceof NullLiteral) {
visit((NullLiteral) expression);
} else if (expression instanceof NumberLiteral) {
visit((NumberLiteral) expression);
} else if (expression instanceof ParenthesizedExpression) {
visit((ParenthesizedExpression) expression);
} else if (expression instanceof PostfixExpression) {
visit((PostfixExpression) expression);
} else if (expression instanceof PrefixExpression) {
visit((PrefixExpression) expression);
} else if ((expression instanceof QualifiedName)) {
visit((QualifiedName) expression);
} else if (expression instanceof SimpleName) {
visit((SimpleName) expression);
} else if (expression instanceof StringLiteral) {
visit((StringLiteral) expression);
} else if (expression instanceof SuperFieldAccess) {
visit((SuperFieldAccess) expression);
} else if (expression instanceof SuperMethodInvocation) {
visit((SuperMethodInvocation) expression);
} else if (expression instanceof ThisExpression) {
visit((ThisExpression) expression);
} else if (expression instanceof TypeLiteral) {
visit((TypeLiteral) expression);
} else if (expression instanceof VariableDeclarationExpression) {
visit((VariableDeclarationExpression) expression);
}
}
private void handleExpression(Expression expression) {
if (expression instanceof ArrayAccess) {
visit((ArrayAccess) expression);
} else if (expression instanceof ArrayCreation) {
visit((ArrayCreation) expression);
} else if (expression instanceof ArrayInitializer) {
visit((ArrayInitializer) expression);
} else if (expression instanceof Assignment) {
visit((Assignment) expression);
} else if (expression instanceof BooleanLiteral) {
visit((BooleanLiteral) expression);
} else if (expression instanceof CastExpression) {
visit((CastExpression) expression);
} else if (expression instanceof CharacterLiteral) {
visit((CharacterLiteral) expression);
} else if (expression instanceof ClassInstanceCreation) {
visit((ClassInstanceCreation) expression);
} else if (expression instanceof ConditionalExpression) {
visit((ConditionalExpression) expression);
} else if (expression instanceof FieldAccess) {
visit((FieldAccess) expression);
} else if (expression instanceof InfixExpression) {
visit((InfixExpression) expression);
} else if (expression instanceof InstanceofExpression) {
visit((InstanceofExpression) expression);
} else if (expression instanceof MethodInvocation) {
visit((MethodInvocation) expression);
} else if (expression instanceof NullLiteral) {
visit((NullLiteral) expression);
} else if (expression instanceof NumberLiteral) {
visit((NumberLiteral) expression);
} else if (expression instanceof ParenthesizedExpression) {
visit((ParenthesizedExpression) expression);
} else if (expression instanceof PostfixExpression) {
visit((PostfixExpression) expression);
} else if (expression instanceof PrefixExpression) {
visit((PrefixExpression) expression);
} else if ((expression instanceof QualifiedName)) {
visit((QualifiedName) expression);
} else if (expression instanceof SimpleName) {
visit((SimpleName) expression);
} else if (expression instanceof StringLiteral) {
visit((StringLiteral) expression);
} else if (expression instanceof SuperFieldAccess) {
visit((SuperFieldAccess) expression);
} else if (expression instanceof SuperMethodInvocation) {
visit((SuperMethodInvocation) expression);
} else if (expression instanceof ThisExpression) {
visit((ThisExpression) expression);
} else if (expression instanceof TypeLiteral) {
visit((TypeLiteral) expression);
} else if (expression instanceof VariableDeclarationExpression) {
visit((VariableDeclarationExpression) expression);
}
}
@Override
public boolean visit(final TypeLiteral node) {
addToMap(identifiers, node, node.getType().toString());
return super.visit(node);
}