List of usage examples for org.eclipse.jdt.core.dom WildcardType getBound
public Type getBound()
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(WildcardType node) { printTypeAnnotations(node);/*from w ww .j av a 2 s .c o m*/ this.fBuffer.append("?");//$NON-NLS-1$ Type bound = node.getBound(); if (bound != null) { if (node.isUpperBound()) { this.fBuffer.append(" extends ");//$NON-NLS-1$ } else { this.fBuffer.append(" super ");//$NON-NLS-1$ } bound.accept(this); } return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
protected String typeName(final WildcardType t) { String name = "?"; if (t.getBound() != null) { name += " " + (t.isUpperBound() ? "extends" : "super"); name += " " + typeName(t.getBound()); }/*w ww .j a v a2 s . c om*/ return name; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(WildcardType node) { this.buffer.append("?");//$NON-NLS-1$ Type bound = node.getBound(); if (bound != null) { if (node.isUpperBound()) { this.buffer.append(" extends ");//$NON-NLS-1$ } else {//from w w w . j a v a 2 s .c om this.buffer.append(" super ");//$NON-NLS-1$ } bound.accept(this); } return false; }
From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java
License:Open Source License
@Override public boolean visit(WildcardType node) { handleToken(node, TokenNameQUESTION, this.options.insert_space_before_question_in_wilcard, this.options.insert_space_after_question_in_wilcard || node.getBound() != null); return true;/*from w ww. java2s .c om*/ }
From source file:com.google.dart.java2dart.SyntaxTranslator.java
License:Open Source License
@Override public boolean visit(org.eclipse.jdt.core.dom.WildcardType node) { org.eclipse.jdt.core.dom.Type javaBoundType = node.getBound(); if (javaBoundType == null) { return done(typeName("Object")); } else {/*www . j a v a2 s. c o m*/ return done(translate(javaBoundType)); } }
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
License:Apache License
/** Visitor method for {@link WildcardType}s. */ @Override/*from ww w . j a va2s. c o m*/ public boolean visit(WildcardType node) { sync(node); beforeAnnotatableType(node); builder.open(ZERO); token("?"); if (node.getBound() != null) { builder.open(plusFour); builder.space(); token(node.isUpperBound() ? "extends" : "super"); builder.breakOp(" "); node.getBound().accept(this); builder.close(); } builder.close(); return false; }
From source file:com.halware.nakedide.eclipse.ext.annot.utils.AstUtils.java
License:Open Source License
public static String asString(Type type) { if (type.isArrayType()) { ArrayType arrayType = (ArrayType) type; return asString(arrayType.getComponentType()) + "[]"; }/*from w w w .java 2 s . co m*/ if (type.isParameterizedType()) { ParameterizedType parameterizedType = (ParameterizedType) type; List<Type> typeArguments = Generics.asT(parameterizedType.typeArguments()); class TypeToString implements ClosureUtil.IClosure<Type, String> { public String eval(Type type) { return asString(type); } } return asString(parameterizedType.getType()) + "<" + StringUtil.join(ClosureUtil.forEach(typeArguments, new TypeToString()), ", ") + ">"; } if (type.isPrimitiveType()) { PrimitiveType primitiveType = (PrimitiveType) type; return primitiveType.getPrimitiveTypeCode().toString(); } if (type.isQualifiedType()) { QualifiedType qualifiedType = (QualifiedType) type; return qualifiedType.getName().getFullyQualifiedName(); } if (type.isSimpleType()) { SimpleType simpleType = (SimpleType) type; return simpleType.getName().getFullyQualifiedName(); } if (type.isWildcardType()) { WildcardType wildcardType = (WildcardType) type; Type boundType = wildcardType.getBound(); if (boundType != null) { if (wildcardType.isUpperBound()) { return "? extends " + asString(boundType); } else { return "? super " + asString(boundType); } } else { return "?"; } } return "(unknown type)"; }
From source file:com.kodebeagle.javaparser.TypeResolver.java
License:Apache License
/** * @param type//w w w .j a v a2 s .c o m * @return */ protected String getNameOfType(final Type type) { String nameOfType = ""; if (type != null) { if (type.isPrimitiveType()) { nameOfType = type.toString(); } else if (type.isParameterizedType()) { nameOfType = getParametrizedType((ParameterizedType) type); } else if (type.isArrayType()) { final ArrayType array = (ArrayType) type; nameOfType = getNameOfType(array.getElementType()) /*+ "[]"*/; } else if (type.isUnionType()) { // TODO: this is used for exceptions till now // So we will just capture the first type that we encounter final UnionType uType = (UnionType) type; final StringBuffer sb = new StringBuffer(); for (final Object unionedType : uType.types()) { sb.append(getNameOfType(((Type) unionedType))); break; // sb.append(" | "); } // sb.delete(sb.length() - 3, sb.length()); nameOfType = sb.toString(); } else if (type.isWildcardType()) { final WildcardType wType = (WildcardType) type; nameOfType = (wType.isUpperBound() ? "? extends " : "? super ") + getNameOfType(wType.getBound()); } else { nameOfType = getFullyQualifiedNameFor(type.toString()); } } return nameOfType; }
From source file:de.akra.idocit.java.services.ReflectionHelper.java
License:Apache License
/** * Returns the identifier from the {@link Type} depending on the containing type. * //from ww w .jav a 2 s .com * @param type * [SOURCE] * * @return [OBJECT] * @see Type * @thematicgrid Extracting Operations */ public static String extractIdentifierFrom(Type type) { switch (type.getNodeType()) { case ASTNode.PRIMITIVE_TYPE: { PrimitiveType primitiveType = (PrimitiveType) type; return primitiveType.getPrimitiveTypeCode().toString(); } case ASTNode.ARRAY_TYPE: { ArrayType arrayType = (ArrayType) type; String name = extractIdentifierFrom(arrayType.getElementType()); StringBuffer identifier = new StringBuffer(name); for (int i = 0; i < arrayType.getDimensions(); i++) { identifier.append("[]"); } return identifier.toString(); } case ASTNode.SIMPLE_TYPE: { SimpleType simpleType = (SimpleType) type; return simpleType.getName().getFullyQualifiedName(); } case ASTNode.QUALIFIED_TYPE: { QualifiedType qType = (QualifiedType) type; return extractIdentifierFrom(qType.getQualifier()) + "." + qType.getName().getIdentifier(); } case ASTNode.PARAMETERIZED_TYPE: { ParameterizedType paramType = (ParameterizedType) type; StringBuffer identifier = new StringBuffer(extractIdentifierFrom(paramType.getType())); identifier.append('<'); @SuppressWarnings("unchecked") Iterator<Type> iterTypeArgs = (Iterator<Type>) paramType.typeArguments().iterator(); while (iterTypeArgs.hasNext()) { Type typeArg = iterTypeArgs.next(); identifier.append(extractIdentifierFrom(typeArg)); if (iterTypeArgs.hasNext()) { identifier.append(','); } } identifier.append('>'); return identifier.toString(); } case ASTNode.WILDCARD_TYPE: { WildcardType wildcard = (WildcardType) type; String identifier = "? extends "; if (!wildcard.isUpperBound()) { identifier = "? super "; } return identifier + extractIdentifierFrom(wildcard.getBound()); } } return SignatureElement.ANONYMOUS_IDENTIFIER; }
From source file:de.fkoeberle.autocommit.message.java.helper.TypeUtil.java
License:Open Source License
/** * @return a string version of the specified type or another string * indicating an error./*from ww w. j a va 2 s. c om*/ */ public static void appendTypeTo(Type type, StringBuilder builder) { if (type instanceof SimpleType) { SimpleType simpleType = (SimpleType) type; builder.append(simpleType.getName().getFullyQualifiedName()); } else if (type instanceof PrimitiveType) { PrimitiveType primitiveType = (PrimitiveType) type; Code code = primitiveType.getPrimitiveTypeCode(); builder.append(code.toString()); } else if (type instanceof ArrayType) { ArrayType arrayType = (ArrayType) type; appendTypeTo(arrayType.getComponentType(), builder); builder.append("[]"); //$NON-NLS-1$ } else if (type instanceof QualifiedType) { // There aren't test for this case, // since it seems to be impossible to get an instance of // QualifiedType. // Outer.Inner gets parsed as SimpleType QualifiedType qualifiedType = (QualifiedType) type; builder.append(qualifiedType.getQualifier()); builder.append('.'); builder.append(qualifiedType.getName().getIdentifier()); } else if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; builder.append(parameterizedType.getType()); builder.append("<"); //$NON-NLS-1$ @SuppressWarnings("unchecked") List<Type> typeArguments = parameterizedType.typeArguments(); boolean addComma = false; for (Type typeArg : typeArguments) { if (addComma) { builder.append(", "); } else { addComma = true; } appendTypeTo(typeArg, builder); } builder.append(">"); //$NON-NLS-1$ } else if (type instanceof WildcardType) { WildcardType wildcardType = (WildcardType) type; Type bound = wildcardType.getBound(); if (bound != null) { if (wildcardType.isUpperBound()) { builder.append("? extends "); //$NON-NLS-1$ } else { builder.append("? super "); //$NON-NLS-1$ } appendTypeTo(bound, builder); } else { builder.append("?"); //$NON-NLS-1$ } } else { assert false : "Expected no other types"; //$NON-NLS-1$ } }