org.eclipse.jdt.core.dom.UnionType Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.UnionType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ASTNodes.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the topmost ancestor of <code>node</code> that is a {@link Type} (but not a {@link UnionType}).
 * <p>
 * <b>Note:</b> The returned node often resolves to a different binding than the given <code>node</code>!
 * 
 * @param node the starting node, can be <code>null</code>
 * @return the topmost type or <code>null</code> if the node is not a descendant of a type node
 * @see #getNormalizedNode(ASTNode)
 */
public static Type getTopMostType(ASTNode node) {
	ASTNode result= null;
	while (node instanceof Type && !(node instanceof UnionType)
			|| node instanceof Name
			|| node instanceof Annotation || node instanceof MemberValuePair
			|| node instanceof Expression) { // Expression could maybe be reduced to expression node types that can appear in an annotation
		result= node;
		node= node.getParent();
	}
	
	if (result instanceof Type)
		return (Type) result;
	
	return null;
}
 
Example #2
Source File: QuickAssistProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static void removeException(ASTRewrite rewrite, UnionType unionType, Type exception) {
	ListRewrite listRewrite = rewrite.getListRewrite(unionType, UnionType.TYPES_PROPERTY);
	List<Type> types = unionType.types();
	for (Iterator<Type> iterator = types.iterator(); iterator.hasNext();) {
		Type type = iterator.next();
		if (type.equals(exception)) {
			listRewrite.remove(type, null);
		}
	}
}
 
Example #3
Source File: AbstractExceptionAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void handleCatchArguments(List<CatchClause> catchClauses) {
	for (Iterator<CatchClause> iter = catchClauses.iterator(); iter.hasNext();) {
		Type type = iter.next().getException().getType();
		if (type instanceof UnionType) {
			List<Type> types = ((UnionType) type).types();
			for (Iterator<Type> iterator = types.iterator(); iterator.hasNext();) {
				removeCaughtExceptions(iterator.next().resolveBinding());
			}
		} else {
			removeCaughtExceptions(type.resolveBinding());
		}
	}
}
 
Example #4
Source File: TypeResolver.java    From KodeBeagle with Apache License 2.0 5 votes vote down vote up
/**
 * @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;
}
 
Example #5
Source File: JavaApproximateTypeInferencer.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @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;
}
 
Example #6
Source File: AbstractExceptionAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void handleCatchArguments(List<CatchClause> catchClauses) {
	for (Iterator<CatchClause> iter= catchClauses.iterator(); iter.hasNext(); ) {
		Type type= iter.next().getException().getType();
		if (type instanceof UnionType) {
			List<Type> types= ((UnionType) type).types();
			for (Iterator<Type> iterator= types.iterator(); iterator.hasNext();) {
				removeCaughtExceptions(iterator.next().resolveBinding());
			}
		} else {
			removeCaughtExceptions(type.resolveBinding());
		}
	}
}
 
Example #7
Source File: ExceptionOccurrencesFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(TryStatement node) {
	int currentSize= fCaughtExceptions.size();
	List<CatchClause> catchClauses= node.catchClauses();
	for (Iterator<CatchClause> iter= catchClauses.iterator(); iter.hasNext();) {
		Type type= iter.next().getException().getType();
		if (type instanceof UnionType) {
			List<Type> types= ((UnionType) type).types();
			for (Iterator<Type> iterator= types.iterator(); iterator.hasNext();) {
				addCaughtException(iterator.next());
			}
		} else {
			addCaughtException(type);
		}
	}

	node.getBody().accept(this);

	handleResourceDeclarations(node);

	int toRemove= fCaughtExceptions.size() - currentSize;
	for (int i= toRemove; i > 0; i--) {
		fCaughtExceptions.remove(currentSize);
	}

	// visit catch and finally
	for (Iterator<CatchClause> iter= catchClauses.iterator(); iter.hasNext();) {
		iter.next().accept(this);
	}
	if (node.getFinally() != null)
		node.getFinally().accept(this);

	// return false. We have visited the body by ourselves.
	return false;
}
 
Example #8
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static void removeException(ASTRewrite rewrite, UnionType unionType, Type exception) {
	ListRewrite listRewrite= rewrite.getListRewrite(unionType, UnionType.TYPES_PROPERTY);
	List<Type> types= unionType.types();
	for (Iterator<Type> iterator= types.iterator(); iterator.hasNext();) {
		Type type= iterator.next();
		if (type.equals(exception)) {
			listRewrite.remove(type, null);
		}
	}
}
 
Example #9
Source File: BindingSignatureVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean visit(UnionType type) {
	List types = type.types();
	for (int i = 0; i < types.size(); i++){
		handleType((Type) types.get(i));
	}
	return false;
}
 
Example #10
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean visit(UnionType type){
	/*
	 *  Type | Type { | Type }
	 */
	activateDiffStyle(type);
	for (int i = 0; i < type.types().size(); i++){
		handleType((Type) type.types().get(i));
		if (i < type.types().size() - 1){
			appendPipe();
		}
	}
	deactivateDiffStyle(type);
	return false;
}
 
Example #11
Source File: TypeResolver.java    From KodeBeagle with Apache License 2.0 4 votes vote down vote up
@Override
public boolean visit(UnionType node) {
	addTypeBinding(node);
	return true;
}
 
Example #12
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endVisit(UnionType node) {
	endVisitNode(node);
}
 
Example #13
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(UnionType node) {
	return visitNode(node);
}