类org.eclipse.jdt.core.dom.WildcardType源码实例Demo

下面列出了怎么用org.eclipse.jdt.core.dom.WildcardType的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: JDeodorant   文件: StyledStringVisitor.java
public boolean visit(WildcardType type) {
	/*
	 * WildcardType: ? [ ( extends | super) Type ]
	 */
	activateDiffStyle(type);
	appendQuestionMark();
	if(type.getBound() != null) {
		if (type.isUpperBound()) {
			styledString.append("extends", determineDiffStyle(type, new StyledStringStyler(keywordStyle)));
		} else {
			styledString.append("super", determineDiffStyle(type, new StyledStringStyler(keywordStyle)));
		}
		handleType(type.getBound());
	}
	deactivateDiffStyle(type);
	return false;
}
 
源代码2 项目: eclipse.jdt.ls   文件: FlowAnalyzer.java
@Override
public void endVisit(WildcardType node) {
	if (skipNode(node)) {
		return;
	}
	assignFlowInfo(node, node.getBound());
}
 
源代码3 项目: xtext-xtend   文件: JavaASTFlattener.java
@Override
public boolean visit(final WildcardType node) {
  this.appendToBuffer("?");
  Type bound = node.getBound();
  if ((bound != null)) {
    boolean _isUpperBound = node.isUpperBound();
    if (_isUpperBound) {
      this.appendToBuffer(" extends ");
    } else {
      this.appendToBuffer(" super ");
    }
    bound.accept(this);
  }
  return false;
}
 
源代码4 项目: KodeBeagle   文件: TypeResolver.java
/**
 * @param type
 * @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 StringBuilder sb = new StringBuilder();
			for (final Object unionedType : uType.types()) {
				sb.append(getNameOfType((Type) unionedType));
                   break;
			}

			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;
}
 
/**
 * @param type
 * @return
 */
protected String getNameOfType(final Type type) {
	final String nameOfType;
	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()) {
		final UnionType uType = (UnionType) type;
		final StringBuffer sb = new StringBuffer();
		for (final Object unionedType : uType.types()) {
			sb.append(getNameOfType(((Type) unionedType)));
			sb.append(" | ");
		}
		sb.delete(sb.length() - 3, sb.length());
		nameOfType = sb.toString();
	} else if (type.isWildcardType()) {
		final WildcardType wType = (WildcardType) type;
		if (wType.getBound() == null)
			return "?";
		nameOfType = (wType.isUpperBound() ? "? extends " : "? super ") + getNameOfType(wType.getBound());
	} else {
		nameOfType = getFullyQualifiedNameFor(type.toString());
	}
	return nameOfType;
}
 
源代码6 项目: RefactoringMiner   文件: Visitor.java
public boolean visit(WildcardType node) {
	types.add(node.toString());
	if(current.getUserObject() != null) {
		AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject();
		anonymous.getTypes().add(node.toString());
	}
	return false;
}
 
源代码7 项目: JDeodorant   文件: BindingSignatureVisitor.java
public boolean visit(WildcardType type) {
	if(type.getBound() != null) {
		if (type.isUpperBound()) {
			bindingKeys.add("extends");
		} else {
			bindingKeys.add("super");
		}
		handleType(type.getBound());
	}
	return false;
}
 
源代码8 项目: JDeodorant   文件: BindingSignatureVisitor.java
private void handleType(Type type) {
	if (type instanceof PrimitiveType) {
		visit((PrimitiveType) type);
	} else if (type instanceof ArrayType) {
		visit((ArrayType) type);
	} else if (type instanceof SimpleType) {
		visit((SimpleType) type);
	} else if (type instanceof QualifiedType) {
		visit((QualifiedType) type);
	} else if (type instanceof ParameterizedType) {
		visit((ParameterizedType) type);
	} else if (type instanceof WildcardType) {
		visit((WildcardType) type);
	}
}
 
源代码9 项目: JDeodorant   文件: StyledStringVisitor.java
private void handleType(Type type) {
	if (type instanceof PrimitiveType) {
		visit((PrimitiveType) type);
	} else if (type instanceof ArrayType) {
		visit((ArrayType) type);
	} else if (type instanceof SimpleType) {
		visit((SimpleType) type);
	} else if (type instanceof QualifiedType) {
		visit((QualifiedType) type);
	} else if (type instanceof ParameterizedType) {
		visit((ParameterizedType) type);
	} else if (type instanceof WildcardType) {
		visit((WildcardType) type);
	}
}
 
源代码10 项目: SimFix   文件: NodeUtils.java
public static boolean replaceExpr(int srcID, String avoid, Expr srcExpr, Expr tarExpr, Map<String, String> varTrans, Map<String, Type> allUsableVariables, List<Modification> modifications){
	if(srcExpr.toSrcString().toString().equals(tarExpr.toSrcString().toString())){
		return true;
	}
	if(srcExpr.toSrcString().toString().length() < 2){
		return false;
	}
	if(srcExpr instanceof MethodInv){
		if(tarExpr instanceof MethodInv){
			MethodInv srcMethod = (MethodInv) srcExpr;
			MethodInv tarMethod = (MethodInv) tarExpr;
			List<Modification> tmp = new LinkedList<>();
			if (srcMethod.getExpression() != null && tarMethod.getExpression() != null) {
				Expr src = srcMethod.getExpression();
				Expr tar = tarMethod.getExpression();
				if ((src instanceof SName || tar instanceof SName)
						&& ((NodeUtils.isClass(src.toSrcString().toString())
								&& !NodeUtils.isClass(tar.toSrcString().toString()))
								|| (!NodeUtils.isClass(src.toSrcString().toString())
										&& NodeUtils.isClass(tar.toSrcString().toString())))) {
					return false;
				} else if(!srcMethod.getExpression().match(tarMethod.getExpression(), varTrans, allUsableVariables,tmp)){
					return false;
				}
			}
		} else {
			return false;
		}
	} else if(tarExpr instanceof MethodInv){
		return false;
	}
	if(srcExpr instanceof InfixExpr){
		if(!(tarExpr instanceof InfixExpr)){
			return false;
		} else if(!canReplaceOperator(((InfixExpr)srcExpr).getOperator(), ((InfixExpr)tarExpr).getOperator())){
			return false;
		}
	} else if(tarExpr instanceof InfixExpr){
		InfixExpr infixExpr = (InfixExpr) tarExpr;
		if(infixExpr.getLhs() instanceof NumLiteral && NodeUtils.isBoundaryValue((NumLiteral) infixExpr.getLhs())){
			return false;
		} else if(infixExpr.getRhs() instanceof NumLiteral && NodeUtils.isBoundaryValue((NumLiteral) infixExpr.getRhs())){
			return false;
		}
	}
	Type srcType = srcExpr.getType();
	Type tarType = tarExpr.getType();
	if (srcType.toString().equals(tarType.toString()) || srcType instanceof WildcardType
			|| tarType instanceof WildcardType) {
		Map<SName, Pair<String, String>> record = tryReplaceAllVariables(tarExpr, varTrans, allUsableVariables);
		if (record != null) {
			// replace all variable
			replaceVariable(record);
			String target = tarExpr.toSrcString().toString();
			if (!srcExpr.toSrcString().toString().equals(target) && !avoid.equals(target)) {
				Revision revision = new Revision(srcExpr.getParent(), srcID, target, srcExpr.getNodeType());
				modifications.add(revision);
			}
			// restore all variable
			restoreVariables(record);
		}
		return true;
	} else {
		return false;
	}
}
 
源代码11 项目: KodeBeagle   文件: TypeResolver.java
@Override
public boolean visit(WildcardType node) {
	addTypeBinding(node);
	return true;
}
 
@Override
public void endVisit(WildcardType node) {
	if (skipNode(node))
		return;
	assignFlowInfo(node, node.getBound());
}
 
@Override
public boolean visit(WildcardType node) {
	if (node.subtreeMatch(fMatcher, fNodeToMatch))
		return matches(node);
	return super.visit(node);
}
 
@Override
public void endVisit(WildcardType node) {
	endVisitNode(node);
}
 
@Override
public boolean visit(WildcardType node) {
	return visitNode(node);
}
 
源代码16 项目: Eclipse-Postfix-Code-Completion   文件: Util.java
private static void getFullyQualifiedName(Type type, StringBuffer buffer) {
	switch (type.getNodeType()) {
		case ASTNode.ARRAY_TYPE:
			ArrayType arrayType = (ArrayType) type;
			getFullyQualifiedName(arrayType.getElementType(), buffer);
			for (int i = 0, length = arrayType.getDimensions(); i < length; i++) {
				buffer.append('[');
				buffer.append(']');
			}
			break;
		case ASTNode.PARAMETERIZED_TYPE:
			ParameterizedType parameterizedType = (ParameterizedType) type;
			getFullyQualifiedName(parameterizedType.getType(), buffer);
			buffer.append('<');
			Iterator iterator = parameterizedType.typeArguments().iterator();
			boolean isFirst = true;
			while (iterator.hasNext()) {
				if (!isFirst)
					buffer.append(',');
				else
					isFirst = false;
				Type typeArgument = (Type) iterator.next();
				getFullyQualifiedName(typeArgument, buffer);
			}
			buffer.append('>');
			break;
		case ASTNode.PRIMITIVE_TYPE:
			buffer.append(((PrimitiveType) type).getPrimitiveTypeCode().toString());
			break;
		case ASTNode.QUALIFIED_TYPE:
			buffer.append(((QualifiedType) type).getName().getFullyQualifiedName());
			break;
		case ASTNode.SIMPLE_TYPE:
			buffer.append(((SimpleType) type).getName().getFullyQualifiedName());
			break;
		case ASTNode.WILDCARD_TYPE:
			buffer.append('?');
			WildcardType wildcardType = (WildcardType) type;
			Type bound = wildcardType.getBound();
			if (bound == null) return;
			if (wildcardType.isUpperBound()) {
				buffer.append(" extends "); //$NON-NLS-1$
			} else {
				buffer.append(" super "); //$NON-NLS-1$
			}
			getFullyQualifiedName(bound, buffer);
			break;
	}
}
 
private Type createType(String typeSig, AST ast) {
	int sigKind = Signature.getTypeSignatureKind(typeSig);
       switch (sigKind) {
           case Signature.BASE_TYPE_SIGNATURE:
               return ast.newPrimitiveType(PrimitiveType.toCode(Signature.toString(typeSig)));
           case Signature.ARRAY_TYPE_SIGNATURE:
               Type elementType = createType(Signature.getElementType(typeSig), ast);
               return ast.newArrayType(elementType, Signature.getArrayCount(typeSig));
           case Signature.CLASS_TYPE_SIGNATURE:
               String erasureSig = Signature.getTypeErasure(typeSig);

               String erasureName = Signature.toString(erasureSig);
               if (erasureSig.charAt(0) == Signature.C_RESOLVED) {
                   erasureName = addImport(erasureName);
               }
               
               Type baseType= ast.newSimpleType(ast.newName(erasureName));
               String[] typeArguments = Signature.getTypeArguments(typeSig);
               if (typeArguments.length > 0) {
                   ParameterizedType type = ast.newParameterizedType(baseType);
                   List argNodes = type.typeArguments();
                   for (int i = 0; i < typeArguments.length; i++) {
                       String curr = typeArguments[i];
                       if (containsNestedCapture(curr)) {
                           argNodes.add(ast.newWildcardType());
                       } else {
                           argNodes.add(createType(curr, ast));
                       }
                   }
                   return type;
               }
               return baseType;
           case Signature.TYPE_VARIABLE_SIGNATURE:
               return ast.newSimpleType(ast.newSimpleName(Signature.toString(typeSig)));
           case Signature.WILDCARD_TYPE_SIGNATURE:
               WildcardType wildcardType= ast.newWildcardType();
               char ch = typeSig.charAt(0);
               if (ch != Signature.C_STAR) {
                   Type bound= createType(typeSig.substring(1), ast);
                   wildcardType.setBound(bound, ch == Signature.C_EXTENDS);
               }
               return wildcardType;
           case Signature.CAPTURE_TYPE_SIGNATURE:
               return createType(typeSig.substring(1), ast);
       }
       
       return ast.newSimpleType(ast.newName("java.lang.Object"));
}
 
 类所在包
 类方法
 同包方法