List of usage examples for org.eclipse.jdt.core.dom SingleMemberAnnotation VALUE_PROPERTY
ChildPropertyDescriptor VALUE_PROPERTY
To view the source code for org.eclipse.jdt.core.dom SingleMemberAnnotation VALUE_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;/* www . ja va 2 s.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 setSMAStringValue(Annotation annotation, String string) throws GeneratorException { editLock();//from w w w. j a v a 2s . co m if (annotation == null) { throw new IllegalArgumentException("'annotation' argument cannot be null!"); } if (string == null || string.length() == 0) { throw new IllegalArgumentException("'string' argument must have a valid value!"); } StringLiteral literal = removeOnTypeMismatch( getRewrite().get(annotation, SingleMemberAnnotation.VALUE_PROPERTY), StringLiteral.class); if (literal == null) { literal = getAST().newStringLiteral(); getRewrite().set(annotation, SingleMemberAnnotation.VALUE_PROPERTY, literal, getEditGroup()); } String value = literal.getLiteralValue(); if (value == null || !value.equals(string)) { value = "\"" + string + "\""; getRewrite().set(literal, StringLiteral.ESCAPED_VALUE_PROPERTY, value, getEditGroup()); } }
From source file:org.moe.natjgen.EditContext.java
License:Apache License
protected void setSMATypeValue(Annotation annotation, String type) throws GeneratorException { editLock();/*from ww w.j a va2 s . c o m*/ if (annotation == null) { throw new IllegalArgumentException("'annotation' argument cannot be null!"); } if (type == null || type.length() == 0) { throw new IllegalArgumentException("'type' argument must have a valid value!"); } TypeLiteral literal = removeOnTypeMismatch( getRewrite().get(annotation, SingleMemberAnnotation.VALUE_PROPERTY), TypeLiteral.class); if (literal == null) { literal = getAST().newTypeLiteral(); getRewrite().set(annotation, SingleMemberAnnotation.VALUE_PROPERTY, literal, getEditGroup()); } SimpleType value_type = removeOnTypeMismatch(literal.getType(), SimpleType.class); if (value_type == null) { getRewrite().set(literal, TypeLiteral.TYPE_PROPERTY, getAST().newSimpleType(getAST().newName(type)), getEditGroup()); } else { if (value_type.getName() == null || !value_type.getName().equals(type)) { getRewrite().set(value_type, SimpleType.NAME_PROPERTY, getAST().newName(type), getEditGroup()); } } }
From source file:org.moe.natjgen.EditContext.java
License:Apache License
protected Expression getSMAValue(Annotation annotation) { if (annotation.isMarkerAnnotation()) { return null; } else if (annotation.isSingleMemberAnnotation()) { return (Expression) getRewrite().get(annotation, SingleMemberAnnotation.VALUE_PROPERTY); }//from w ww. jav a 2 s . c om throw new RuntimeException(); }