本文整理汇总了Java中org.eclipse.jdt.core.dom.UnionType类的典型用法代码示例。如果您正苦于以下问题:Java UnionType类的具体用法?Java UnionType怎么用?Java UnionType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnionType类属于org.eclipse.jdt.core.dom包,在下文中一共展示了UnionType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getTopMostType
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
/**
* 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;
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:26,代码来源:ASTNodes.java
示例2: getTopMostType
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
/**
* 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;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:ASTNodes.java
示例3: removeException
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
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);
}
}
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:11,代码来源:QuickAssistProcessor.java
示例4: handleCatchArguments
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
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());
}
}
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:14,代码来源:AbstractExceptionAnalyzer.java
示例5: handleCatchArguments
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
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());
}
}
}
开发者ID:eclipse,项目名称:che,代码行数:14,代码来源:AbstractExceptionAnalyzer.java
示例6: handleCatchArguments
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
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());
}
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:14,代码来源:AbstractExceptionAnalyzer.java
示例7: visit
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
@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;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:36,代码来源:ExceptionOccurrencesFinder.java
示例8: removeException
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
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);
}
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:11,代码来源:QuickAssistProcessor.java
示例9: visit
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
@Override
public boolean visit(UnionType node) {
for (Iterator<Type> it= node.types().iterator(); it.hasNext();) {
Type t= it.next();
t.accept(this);
if (it.hasNext()) {
this.fBuffer.append("|");//$NON-NLS-1$
}
}
return false;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:12,代码来源:ASTFlattener.java
示例10: newType
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
/**
* Returns the new type node corresponding to the type of the given declaration
* including the extra dimensions. If the type is a {@link UnionType}, use the LUB type.
* If the <code>importRewrite</code> is <code>null</code>, the type may be fully-qualified.
*
* @param ast The AST to create the resulting type with.
* @param declaration The variable declaration to get the type from
* @param importRewrite the import rewrite to use, or <code>null</code>
* @param context the import rewrite context, or <code>null</code>
* @return a new type node created with the given AST.
*
* @since 3.7.1
*/
public static Type newType(AST ast, VariableDeclaration declaration, ImportRewrite importRewrite, ImportRewriteContext context) {
Type type= ASTNodes.getType(declaration);
if (declaration instanceof SingleVariableDeclaration) {
Type type2= ((SingleVariableDeclaration) declaration).getType();
if (type2 instanceof UnionType) {
ITypeBinding typeBinding= type2.resolveBinding();
if (typeBinding != null) {
if (importRewrite != null) {
type= importRewrite.addImport(typeBinding, ast, context);
return type;
} else {
String qualifiedName= typeBinding.getQualifiedName();
if (qualifiedName.length() > 0) {
type= ast.newSimpleType(ast.newName(qualifiedName));
return type;
}
}
}
// XXX: fallback for intersection types or unresolved types: take first type of union
type= (Type) ((UnionType) type2).types().get(0);
return type;
}
}
int extraDim= declaration.getExtraDimensions();
type= (Type) ASTNode.copySubtree(ast, type);
for (int i= 0; i < extraDim; i++) {
type= ast.newArrayType(type);
}
return type;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:45,代码来源:ASTNodeFactory.java
示例11: initialize
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
public String initialize(CompilationUnit root, ASTNode node) {
fASTRoot= root;
if (!(node instanceof Name)) {
return SearchMessages.ExceptionOccurrencesFinder_no_exception;
}
fSelectedName= ASTNodes.getTopMostName((Name)node);
ASTNode parent= fSelectedName.getParent();
MethodDeclaration decl= resolveMethodDeclaration(parent);
if (decl != null && methodThrowsException(decl, fSelectedName)) {
fException= fSelectedName.resolveTypeBinding();
fStart= decl.getBody();
} else if (parent instanceof Type) {
parent= parent.getParent();
if (parent instanceof UnionType) {
parent= parent.getParent();
}
if (parent instanceof SingleVariableDeclaration && parent.getParent() instanceof CatchClause) {
CatchClause catchClause= (CatchClause)parent.getParent();
fTryStatement= (TryStatement)catchClause.getParent();
if (fTryStatement != null) {
fException= fSelectedName.resolveTypeBinding();
fStart= fTryStatement.getBody();
}
}
}
if (fException == null || fStart == null)
return SearchMessages.ExceptionOccurrencesFinder_no_exception;
fDescription= Messages.format(SearchMessages.ExceptionOccurrencesFinder_occurrence_description, BasicElementLabels.getJavaElementName(fException.getName()));
return null;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:31,代码来源:ExceptionOccurrencesFinder.java
示例12: visit
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
public boolean visit(UnionType node) {
for (Iterator it = node.types().iterator(); it.hasNext(); ) {
Type t = (Type) it.next();
t.accept(this);
if (it.hasNext()) {
this.buffer.append('|');
}
}
return false;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:11,代码来源:NaiveASTFlattener.java
示例13: visit
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
@Override
public boolean visit(CatchClause node) {
//System.out.println("Found: " + node.getClass());
ArrayList<Type> types = new ArrayList<>();
// Handle union types in catch clauses
if (node.getException().getType() instanceof UnionType) {
//println("UNIONUNIONUNION");
UnionType ut = (UnionType)node.getException().getType();
for (Object o : ut.types()) {
types.add((Type)o);
}
} else {
types.add(node.getException().getType());
}
for (Type t : types) {
print("catch (");
t.accept(this);
print(" ");
node.getException().getName().accept(this);
//node.getException().accept(this);
println(") {");
indent++;
node.getBody().accept(this);
indent--;
print("} ");
}
return false;
}
开发者ID:mrmonday,项目名称:j2d,代码行数:29,代码来源:J2dVisitor.java
示例14: visit
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
@Override
public boolean visit(final UnionType node) {
return false;
}
开发者ID:Beagle-PSE,项目名称:Beagle,代码行数:5,代码来源:NotRecursingAstVisitor.java
示例15: visit
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
@Override
public boolean visit(final UnionType node) {
// not instrumentable, contains no instrumentable nodes
return false;
}
开发者ID:Beagle-PSE,项目名称:Beagle,代码行数:6,代码来源:InstrumentableAstNodeLister.java
示例16: endVisit
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
@Override
public void endVisit(UnionType node) {
endVisitNode(node);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:5,代码来源:GenericVisitor.java
示例17: visit
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
@Override
public boolean visit(UnionType node) {
return visitNode(node);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:5,代码来源:GenericVisitor.java
示例18: initialize
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
public String initialize(CompilationUnit root, ASTNode node) {
fASTRoot= root;
if (node == null)
return SearchMessages.ExceptionOccurrencesFinder_no_exception;
MethodDeclaration method= ASTResolving.findParentMethodDeclaration(node);
if (method == null)
return SearchMessages.ExceptionOccurrencesFinder_no_exception;
// The ExceptionOccurrencesFinder selects the whole type, no matter what part of it was selected. MethodExitsFinder behaves similar.
if (node instanceof Name) {
node= ASTNodes.getTopMostName((Name) node);
}
ASTNode parent= node.getParent();
if (node.getLocationInParent() == TagElement.FRAGMENTS_PROPERTY) {
// in Javadoc tag:
TagElement tagElement= (TagElement) parent;
String tagName= tagElement.getTagName();
if (node instanceof Name
&& node == tagElement.fragments().get(0)
&& (TagElement.TAG_EXCEPTION.equals(tagName) || TagElement.TAG_THROWS.equals(tagName))) {
fSelectedNode= node;
fException= ((Name) node).resolveTypeBinding();
fStart= method;
}
} else {
Type type= ASTNodes.getTopMostType(node);
if (type == null) {
return SearchMessages.ExceptionOccurrencesFinder_no_exception;
}
// in method's "throws" list:
if (type.getLocationInParent() == MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) {
fSelectedNode= type;
fException= type.resolveBinding();
fStart= method;
}
// in catch clause:
Type topType= type;
if (type.getLocationInParent() == UnionType.TYPES_PROPERTY) {
topType= (Type) type.getParent();
}
if (topType.getLocationInParent() == SingleVariableDeclaration.TYPE_PROPERTY
&& topType.getParent().getLocationInParent() == CatchClause.EXCEPTION_PROPERTY) {
fSelectedNode= type;
fException= type.resolveBinding();
fTryStatement= (TryStatement) topType.getParent().getParent().getParent();
fStart= fTryStatement.getBody();
}
}
if (fException == null || fStart == null)
return SearchMessages.ExceptionOccurrencesFinder_no_exception;
fDescription= Messages.format(SearchMessages.ExceptionOccurrencesFinder_occurrence_description, BasicElementLabels.getJavaElementName(fException.getName()));
return null;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:59,代码来源:ExceptionOccurrencesFinder.java
示例19: getPickoutTypeFromMulticatchProposals
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
private static boolean getPickoutTypeFromMulticatchProposals(IInvocationContext context, ASTNode node, ArrayList<ASTNode> coveredNodes, Collection<ICommandAccess> resultingCollections) {
CatchClause catchClause= (CatchClause) ASTResolving.findAncestor(node, ASTNode.CATCH_CLAUSE);
if (catchClause == null) {
return false;
}
Statement statement= ASTResolving.findParentStatement(node);
if (statement != catchClause.getParent() && statement != catchClause.getBody()) {
return false; // selection is in a statement inside the body
}
Type type= catchClause.getException().getType();
if (!type.isUnionType()) {
return false;
}
Type selectedMultiCatchType= null;
if (type.isUnionType() && node instanceof Name) {
Name topMostName= ASTNodes.getTopMostName((Name) node);
ASTNode parent= topMostName.getParent();
if (parent instanceof SimpleType || parent instanceof NameQualifiedType) {
selectedMultiCatchType= (Type) parent;
}
}
boolean multipleExceptions= coveredNodes.size() > 1;
if ((selectedMultiCatchType == null) && (!(node instanceof UnionType) || !multipleExceptions)) {
return false;
}
if (!multipleExceptions) {
coveredNodes.add(selectedMultiCatchType);
}
BodyDeclaration bodyDeclaration= ASTResolving.findParentBodyDeclaration(catchClause);
if (!(bodyDeclaration instanceof MethodDeclaration) && !(bodyDeclaration instanceof Initializer)) {
return false;
}
if (resultingCollections == null) {
return true;
}
AST ast= bodyDeclaration.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
CatchClause newCatchClause= ast.newCatchClause();
SingleVariableDeclaration newSingleVariableDeclaration= ast.newSingleVariableDeclaration();
UnionType newUnionType= ast.newUnionType();
List<Type> types= newUnionType.types();
for (int i= 0; i < coveredNodes.size(); i++) {
ASTNode typeNode= coveredNodes.get(i);
types.add((Type) rewrite.createCopyTarget(typeNode));
rewrite.remove(typeNode, null);
}
newSingleVariableDeclaration.setType(newUnionType);
newSingleVariableDeclaration.setName((SimpleName) rewrite.createCopyTarget(catchClause.getException().getName()));
newCatchClause.setException(newSingleVariableDeclaration);
setCatchClauseBody(newCatchClause, rewrite, catchClause);
TryStatement tryStatement= (TryStatement)catchClause.getParent();
ListRewrite listRewrite= rewrite.getListRewrite(tryStatement, TryStatement.CATCH_CLAUSES_PROPERTY);
listRewrite.insertAfter(newCatchClause, catchClause, null);
Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION);
String label= !multipleExceptions
? CorrectionMessages.QuickAssistProcessor_move_exception_to_separate_catch_block
: CorrectionMessages.QuickAssistProcessor_move_exceptions_to_separate_catch_block;
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.MOVE_EXCEPTION_TO_SEPERATE_CATCH_BLOCK, image);
resultingCollections.add(proposal);
return true;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:74,代码来源:QuickAssistProcessor.java
示例20: getUnrollMultiCatchProposals
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
private static boolean getUnrollMultiCatchProposals(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) {
if (!JavaModelUtil.is17OrHigher(context.getCompilationUnit().getJavaProject()))
return false;
CatchClause catchClause= (CatchClause) ASTResolving.findAncestor(covering, ASTNode.CATCH_CLAUSE);
if (catchClause == null) {
return false;
}
Statement statement= ASTResolving.findParentStatement(covering);
if (statement != catchClause.getParent() && statement != catchClause.getBody()) {
return false; // selection is in a statement inside the body
}
Type type1= catchClause.getException().getType();
Type selectedMultiCatchType= null;
if (type1.isUnionType() && covering instanceof Name) {
Name topMostName= ASTNodes.getTopMostName((Name) covering);
ASTNode parent= topMostName.getParent();
if (parent instanceof SimpleType || parent instanceof NameQualifiedType) {
selectedMultiCatchType= (Type) parent;
}
}
if (selectedMultiCatchType != null)
return false;
SingleVariableDeclaration singleVariableDeclaration= catchClause.getException();
Type type= singleVariableDeclaration.getType();
if (!(type instanceof UnionType))
return false;
if (resultingCollections == null)
return true;
AST ast= covering.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
TryStatement tryStatement= (TryStatement) catchClause.getParent();
ListRewrite listRewrite= rewrite.getListRewrite(tryStatement, TryStatement.CATCH_CLAUSES_PROPERTY);
UnionType unionType= (UnionType) type;
List<Type> types= unionType.types();
for (int i= types.size() - 1; i >= 0; i--) {
Type type2= types.get(i);
CatchClause newCatchClause= ast.newCatchClause();
SingleVariableDeclaration newSingleVariableDeclaration= ast.newSingleVariableDeclaration();
newSingleVariableDeclaration.setType((Type) rewrite.createCopyTarget(type2));
newSingleVariableDeclaration.setName((SimpleName) rewrite.createCopyTarget(singleVariableDeclaration.getName()));
newCatchClause.setException(newSingleVariableDeclaration);
setCatchClauseBody(newCatchClause, rewrite, catchClause);
listRewrite.insertAfter(newCatchClause, catchClause, null);
}
rewrite.remove(catchClause, null);
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
String label= CorrectionMessages.QuickAssistProcessor_convert_to_multiple_singletype_catch_blocks;
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.USE_SEPARATE_CATCH_BLOCKS, image);
resultingCollections.add(proposal);
return true;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:62,代码来源:QuickAssistProcessor.java
注:本文中的org.eclipse.jdt.core.dom.UnionType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论