List of usage examples for org.eclipse.jdt.core.dom MemberValuePair NAME_PROPERTY
ChildPropertyDescriptor NAME_PROPERTY
To view the source code for org.eclipse.jdt.core.dom MemberValuePair NAME_PROPERTY.
Click Source Link
From source file:org.eclipse.ajdt.internal.ui.editor.quickfix.UnresolvedElementsSubProcessor.java
License:Open Source License
public static void getAnnotationMemberProposals(IInvocationContext context, IProblemLocation problem, Collection proposals) throws CoreException { CompilationUnit astRoot = context.getASTRoot(); ICompilationUnit cu = context.getCompilationUnit(); ASTNode selectedNode = problem.getCoveringNode(astRoot); Annotation annotation;/*from w w w. j a va 2s . c om*/ String memberName; if (selectedNode.getLocationInParent() == MemberValuePair.NAME_PROPERTY) { if (selectedNode.getParent().getLocationInParent() != NormalAnnotation.VALUES_PROPERTY) { return; } annotation = (Annotation) selectedNode.getParent().getParent(); memberName = ((SimpleName) selectedNode).getIdentifier(); } else if (selectedNode.getLocationInParent() == SingleMemberAnnotation.VALUE_PROPERTY) { annotation = (Annotation) selectedNode.getParent(); memberName = "value"; //$NON-NLS-1$ } else { return; } ITypeBinding annotBinding = annotation.resolveTypeBinding(); if (annotBinding == null) { return; } if (annotation instanceof NormalAnnotation) { // similar names IMethodBinding[] otherMembers = annotBinding.getDeclaredMethods(); for (int i = 0; i < otherMembers.length; i++) { IMethodBinding binding = otherMembers[i]; String curr = binding.getName(); int relevance = NameMatcher.isSimilarName(memberName, curr) ? 6 : 3; String label = Messages.format( CorrectionMessages.UnresolvedElementsSubProcessor_UnresolvedElementsSubProcessor_changetoattribute_description, curr); proposals.add(new RenameNodeCorrectionProposal(label, cu, problem.getOffset(), problem.getLength(), curr, relevance)); } } if (annotBinding.isFromSource()) { ICompilationUnit targetCU = ASTResolving.findCompilationUnitForBinding(cu, astRoot, annotBinding); if (targetCU != null) { String label = Messages.format( CorrectionMessages.UnresolvedElementsSubProcessor_UnresolvedElementsSubProcessor_createattribute_description, memberName); Image image = JavaPluginImages.get(JavaPluginImages.IMG_MISC_PUBLIC); proposals.add( new NewAnnotationMemberProposal(label, targetCU, selectedNode, annotBinding, 5, image)); } } }
From source file:org.moe.natjgen.EditContext.java
License:Apache License
protected void setNAField(Annotation annotation, int index, String key, Expression value) throws GeneratorException { editLock();// w ww . jav a 2 s .c om MemberValuePair mvp = getNAField(annotation, key); if (mvp == null) { mvp = getAST().newMemberValuePair(); ListRewrite vlrw = getRewrite().getListRewrite(annotation, NormalAnnotation.VALUES_PROPERTY); vlrw.insertLast(mvp, getEditGroup()); getRewrite().set(mvp, MemberValuePair.NAME_PROPERTY, getAST().newSimpleName(key), getEditGroup()); } getRewrite().set(mvp, MemberValuePair.VALUE_PROPERTY, value, getEditGroup()); }
From source file:org.moe.natjgen.EditContext.java
License:Apache License
@SuppressWarnings("unchecked") protected MemberValuePair getNAField(Annotation annotation, String key) { if (annotation.isNormalAnnotation()) { ListRewrite vlrw = getRewrite().getListRewrite(annotation, NormalAnnotation.VALUES_PROPERTY); for (MemberValuePair mvp : (List<MemberValuePair>) vlrw.getRewrittenList()) { SimpleName name = (SimpleName) getRewrite().get(mvp, MemberValuePair.NAME_PROPERTY); if (key.equals(name.getFullyQualifiedName())) { return mvp; }/*from w ww . ja v a 2 s. c o m*/ } return null; } throw new RuntimeException(); }
From source file:org.moe.natjgen.EditContext.java
License:Apache License
@SuppressWarnings("unchecked") protected void removeNAKeysExcluding(Annotation annotation, ArrayList<String> keys) throws GeneratorException { editLock();/*from w w w . j av a2 s . com*/ ListRewrite vlrw = getRewrite().getListRewrite(annotation, NormalAnnotation.VALUES_PROPERTY); List<MemberValuePair> mvpl = (List<MemberValuePair>) vlrw.getRewrittenList(); int idx = 0; for (MemberValuePair mvp : mvpl) { if (idx < keys.size()) { SimpleName name = (SimpleName) getRewrite().get(mvp, MemberValuePair.NAME_PROPERTY); if (!keys.get(idx).equals(name.getFullyQualifiedName())) { vlrw.remove(mvp, getEditGroup()); } } else { vlrw.remove(mvp, getEditGroup()); } ++idx; } }