本文整理匯總了Java中org.eclipse.jdt.core.dom.CompilationUnit.findDeclaringNode方法的典型用法代碼示例。如果您正苦於以下問題:Java CompilationUnit.findDeclaringNode方法的具體用法?Java CompilationUnit.findDeclaringNode怎麽用?Java CompilationUnit.findDeclaringNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.CompilationUnit
的用法示例。
在下文中一共展示了CompilationUnit.findDeclaringNode方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: rewriteAST
import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel linkedModel) throws CoreException {
ASTRewrite rewrite= cuRewrite.getASTRewrite();
IBinding binding= fUnusedName.resolveBinding();
CompilationUnit root= (CompilationUnit) fUnusedName.getRoot();
String displayString= FixMessages.UnusedCodeFix_RemoveUnusedTypeParameter_description;
TextEditGroup group= createTextEditGroup(displayString, cuRewrite);
if (binding.getKind() == IBinding.TYPE) {
ITypeBinding decl= ((ITypeBinding) binding).getTypeDeclaration();
ASTNode declaration= root.findDeclaringNode(decl);
if (declaration.getParent() instanceof TypeDeclarationStatement) {
declaration= declaration.getParent();
}
rewrite.remove(declaration, group);
}
}
示例2: getRewrite
import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
@Override
protected ASTRewrite getRewrite() throws CoreException {
ASTNode boundNode= fAstRoot.findDeclaringNode(fBinding);
ASTNode declNode= null;
CompilationUnit newRoot= fAstRoot;
if (boundNode != null) {
declNode= boundNode; // is same CU
} else {
newRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
declNode= newRoot.findDeclaringNode(fBinding.getKey());
}
ImportRewrite imports= createImportRewrite(newRoot);
if (declNode instanceof TypeDeclaration) {
AST ast= declNode.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(declNode, imports);
Type newInterface= imports.addImport(fNewInterface, ast, importRewriteContext, TypeLocation.OTHER);
ListRewrite listRewrite= rewrite.getListRewrite(declNode, TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY);
listRewrite.insertLast(newInterface, null);
return rewrite;
}
return null;
}
示例3: doAddEnumConst
import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
private ASTRewrite doAddEnumConst(CompilationUnit astRoot) {
SimpleName node= fOriginalNode;
ASTNode newTypeDecl= astRoot.findDeclaringNode(fSenderBinding);
if (newTypeDecl == null) {
astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey());
}
if (newTypeDecl != null) {
AST ast= newTypeDecl.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
EnumConstantDeclaration constDecl= ast.newEnumConstantDeclaration();
constDecl.setName(ast.newSimpleName(node.getIdentifier()));
ListRewrite listRewriter= rewrite.getListRewrite(newTypeDecl, EnumDeclaration.ENUM_CONSTANTS_PROPERTY);
listRewriter.insertLast(constDecl, null);
return rewrite;
}
return null;
}
示例4: getRewrite
import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
@Override
protected ASTRewrite getRewrite() throws CoreException {
CompilationUnit astRoot = ASTResolving.findParentCompilationUnit(fNode);
ASTNode typeDecl = astRoot.findDeclaringNode(fSenderBinding);
ASTNode newTypeDecl = null;
if (typeDecl != null) {
newTypeDecl = typeDecl;
} else {
astRoot = ASTResolving.createQuickFixAST(getCompilationUnit(), null);
newTypeDecl = astRoot.findDeclaringNode(fSenderBinding.getKey());
}
createImportRewrite(astRoot);
if (newTypeDecl != null) {
ASTRewrite rewrite = ASTRewrite.create(astRoot.getAST());
ChildListPropertyDescriptor property = ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
List<BodyDeclaration> members = ASTNodes.getBodyDeclarations(newTypeDecl);
int insertIndex = members.size();
ListRewrite listRewriter = rewrite.getListRewrite(newTypeDecl, property);
isGetter = true;
MethodDeclaration newStub = getStub(rewrite, newTypeDecl);
listRewriter.insertAt(newStub, insertIndex, null);
isGetter = false;
newStub = getStub(rewrite, newTypeDecl);
listRewriter.insertAt(newStub, insertIndex + 1, null);
return rewrite;
}
return null;
}
示例5: doAddField
import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
private ASTRewrite doAddField(CompilationUnit astRoot) {
SimpleName node= fOriginalNode;
boolean isInDifferentCU= false;
ASTNode newTypeDecl= astRoot.findDeclaringNode(fSenderBinding);
if (newTypeDecl == null) {
astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey());
isInDifferentCU= true;
}
ImportRewrite imports= createImportRewrite(astRoot);
ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(ASTResolving.findParentBodyDeclaration(node), imports);
if (newTypeDecl != null) {
AST ast= newTypeDecl.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
fragment.setName(ast.newSimpleName(node.getIdentifier()));
Type type= evaluateVariableType(ast, imports, importRewriteContext, fSenderBinding, TypeLocation.FIELD);
FieldDeclaration newDecl= ast.newFieldDeclaration(fragment);
newDecl.setType(type);
newDecl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, evaluateFieldModifiers(newTypeDecl)));
if (fSenderBinding.isInterface() || fVariableKind == CONST_FIELD) {
fragment.setInitializer(ASTNodeFactory.newDefaultExpression(ast, type, 0));
}
ChildListPropertyDescriptor property= ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
List<BodyDeclaration> decls= ASTNodes.<BodyDeclaration>getChildListProperty(newTypeDecl, property);
int maxOffset= isInDifferentCU ? -1 : node.getStartPosition();
int insertIndex= findFieldInsertIndex(decls, newDecl, maxOffset);
ListRewrite listRewriter= rewrite.getListRewrite(newTypeDecl, property);
listRewriter.insertAt(newDecl, insertIndex, null);
return rewrite;
}
return null;
}
示例6: addNewFieldProposals
import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
private static void addNewFieldProposals(ICompilationUnit cu, CompilationUnit astRoot, ITypeBinding binding,
ITypeBinding declaringTypeBinding, SimpleName simpleName, boolean isWriteAccess,
Collection<CUCorrectionProposal> proposals) throws JavaModelException {
// new variables
ICompilationUnit targetCU;
ITypeBinding senderDeclBinding;
if (binding != null) {
senderDeclBinding= binding.getTypeDeclaration();
targetCU= ASTResolving.findCompilationUnitForBinding(cu, astRoot, senderDeclBinding);
} else { // binding is null for accesses without qualifier
senderDeclBinding= declaringTypeBinding;
targetCU= cu;
}
if (!senderDeclBinding.isFromSource() || targetCU == null) {
return;
}
boolean mustBeConst= ASTResolving.isInsideModifiers(simpleName);
addNewFieldForType(targetCU, binding, senderDeclBinding, simpleName, isWriteAccess, mustBeConst, proposals);
if (binding == null && senderDeclBinding.isNested()) {
ASTNode anonymDecl= astRoot.findDeclaringNode(senderDeclBinding);
if (anonymDecl != null) {
ITypeBinding bind= Bindings.getBindingOfParentType(anonymDecl.getParent());
if (!bind.isAnonymous()) {
addNewFieldForType(targetCU, bind, bind, simpleName, isWriteAccess, mustBeConst, proposals);
}
}
}
}
示例7: getRewrite
import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
@Override
protected ASTRewrite getRewrite() throws CoreException {
CompilationUnit astRoot= ASTResolving.findParentCompilationUnit(fInvocationNode);
ASTNode typeDecl= astRoot.findDeclaringNode(fSenderBinding);
ASTNode newTypeDecl= null;
if (typeDecl != null) {
newTypeDecl= typeDecl;
} else {
astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey());
}
createImportRewrite(astRoot);
if (newTypeDecl instanceof AnnotationTypeDeclaration) {
AnnotationTypeDeclaration newAnnotationTypeDecl= (AnnotationTypeDeclaration) newTypeDecl;
ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
AnnotationTypeMemberDeclaration newStub= getStub(rewrite, newAnnotationTypeDecl);
List<BodyDeclaration> members= newAnnotationTypeDecl.bodyDeclarations();
int insertIndex= members.size();
ListRewrite listRewriter= rewrite.getListRewrite(newAnnotationTypeDecl, AnnotationTypeDeclaration.BODY_DECLARATIONS_PROPERTY);
listRewriter.insertAt(newStub, insertIndex, null);
return rewrite;
}
return null;
}
示例8: getRewrite
import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
@Override
protected ASTRewrite getRewrite() throws CoreException {
CompilationUnit astRoot= ASTResolving.findParentCompilationUnit(fNode);
ASTNode typeDecl= astRoot.findDeclaringNode(fSenderBinding);
ASTNode newTypeDecl= null;
boolean isInDifferentCU;
if (typeDecl != null) {
isInDifferentCU= false;
newTypeDecl= typeDecl;
} else {
isInDifferentCU= true;
astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey());
}
createImportRewrite(astRoot);
if (newTypeDecl != null) {
ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
MethodDeclaration newStub= getStub(rewrite, newTypeDecl);
ChildListPropertyDescriptor property= ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
List<BodyDeclaration> members= ASTNodes.getBodyDeclarations(newTypeDecl);
int insertIndex;
if (isConstructor()) {
insertIndex= findConstructorInsertIndex(members);
} else if (!isInDifferentCU) {
insertIndex= findMethodInsertIndex(members, fNode.getStartPosition());
} else {
insertIndex= members.size();
}
ListRewrite listRewriter= rewrite.getListRewrite(newTypeDecl, property);
listRewriter.insertAt(newStub, insertIndex, null);
return rewrite;
}
return null;
}
示例9: getRewrite
import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
@Override
protected ASTRewrite getRewrite() throws CoreException {
CompilationUnit astRoot= (CompilationUnit) fInvocationNode.getRoot();
ASTNode methodDecl= astRoot.findDeclaringNode(fSenderBinding);
ASTNode newMethodDecl= null;
if (methodDecl != null) {
newMethodDecl= methodDecl;
} else {
astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
newMethodDecl= astRoot.findDeclaringNode(fSenderBinding.getKey());
}
createImportRewrite(astRoot);
if (newMethodDecl instanceof MethodDeclaration) {
MethodDeclaration decl= (MethodDeclaration) newMethodDecl;
ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
if (fParameterChanges != null) {
modifyParameters(rewrite, decl);
}
if (fExceptionChanges != null) {
modifyExceptions(rewrite, decl);
}
return rewrite;
}
return null;
}
示例10: getDeclaringNode
import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
public ASTNode getDeclaringNode(IBinding binding) {
ASTNode node = null;
for (ASTNode compUnit : parsedCompilationUnits.values()) {
if (compUnit instanceof CompilationUnit) {
CompilationUnit compilationUnit = (CompilationUnit) compUnit;
node = compilationUnit.findDeclaringNode(binding);
if (node != null) {
break;
}
}
}
return node;
}
示例11: addNewMethodProposals
import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
private static void addNewMethodProposals(ICompilationUnit cu, CompilationUnit astRoot, Expression sender,
List<Expression> arguments, boolean isSuperInvocation, ASTNode invocationNode, String methodName,
Collection<CUCorrectionProposal> proposals) throws JavaModelException {
ITypeBinding nodeParentType= Bindings.getBindingOfParentType(invocationNode);
ITypeBinding binding= null;
if (sender != null) {
binding= sender.resolveTypeBinding();
} else {
binding= nodeParentType;
if (isSuperInvocation && binding != null) {
binding= binding.getSuperclass();
}
}
if (binding != null && binding.isFromSource()) {
ITypeBinding senderDeclBinding= binding.getTypeDeclaration();
ICompilationUnit targetCU= ASTResolving.findCompilationUnitForBinding(cu, astRoot, senderDeclBinding);
if (targetCU != null) {
String label;
ITypeBinding[] parameterTypes= getParameterTypes(arguments);
if (parameterTypes != null) {
String sig = ASTResolving.getMethodSignature(methodName, parameterTypes, false);
boolean is18OrHigher= JavaModelUtil.is18OrHigher(targetCU.getJavaProject());
boolean isSenderBindingInterface= senderDeclBinding.isInterface();
if (nodeParentType == senderDeclBinding) {
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createmethod_description, sig);
} else {
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createmethod_other_description, new Object[] { sig, BasicElementLabels.getJavaElementName(senderDeclBinding.getName()) } );
}
if (is18OrHigher || !isSenderBindingInterface
|| (nodeParentType != senderDeclBinding && (!(sender instanceof SimpleName) || !((SimpleName) sender).getIdentifier().equals(senderDeclBinding.getName())))) {
proposals.add(new NewMethodCorrectionProposal(label, targetCU, invocationNode, arguments,
senderDeclBinding, IProposalRelevance.CREATE_METHOD));
}
if (senderDeclBinding.isNested() && cu.equals(targetCU) && sender == null && Bindings.findMethodInHierarchy(senderDeclBinding, methodName, (ITypeBinding[]) null) == null) { // no covering method
ASTNode anonymDecl= astRoot.findDeclaringNode(senderDeclBinding);
if (anonymDecl != null) {
senderDeclBinding= Bindings.getBindingOfParentType(anonymDecl.getParent());
isSenderBindingInterface= senderDeclBinding.isInterface();
if (!senderDeclBinding.isAnonymous()) {
if (is18OrHigher || !isSenderBindingInterface) {
String[] args = new String[] { sig,
ASTResolving.getTypeSignature(senderDeclBinding) };
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createmethod_other_description, args);
proposals.add(new NewMethodCorrectionProposal(label, targetCU, invocationNode,
arguments, senderDeclBinding, IProposalRelevance.CREATE_METHOD));
}
}
}
}
}
}
}
}