Java 类org.eclipse.jdt.core.dom.SingleMemberAnnotation 实例源码

项目:code    文件:RemoveAnnotations.java   
private void setFieldAnnotation(ASTRewrite rewrite, FieldDeclaration fieldDeclaration, String annotation) {
    SingleMemberAnnotation newFieldAnnotation = fieldDeclaration.getAST().newSingleMemberAnnotation();
    newFieldAnnotation.setTypeName(rewrite.getAST().newSimpleName("Domain"));
    StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral();
    newStringLiteral.setLiteralValue(annotation);
    newFieldAnnotation.setValue(newStringLiteral);
    ASTNode modifier = getModifier(fieldDeclaration.modifiers());
    if (modifier != null) {
        ListRewrite paramRewrite = rewrite.getListRewrite(fieldDeclaration, FieldDeclaration.MODIFIERS2_PROPERTY);
        paramRewrite.insertAfter(newFieldAnnotation, modifier, null);
    }
    else {
        ListRewrite fieldRewrite = rewrite.getListRewrite(fieldDeclaration, FieldDeclaration.MODIFIERS2_PROPERTY);
        fieldRewrite.insertFirst(newFieldAnnotation, null);
    }

}
项目:code    文件:RemoveAnnotations.java   
private ASTNode getAnnotation(List paramModifiers, String annotation) {
    ASTNode found = null;
    for (Iterator itParamModifiers = paramModifiers.iterator(); itParamModifiers.hasNext();) {
        IExtendedModifier o = (IExtendedModifier) itParamModifiers.next();
        if (o instanceof SingleMemberAnnotation) {
            SingleMemberAnnotation annot = (SingleMemberAnnotation) o;

            String name = annot.getTypeName().toString();
            if (name.compareTo(annotation) == 0) {
                found = annot;
                break;
            }
        }
    }
    return found;
}
项目:code    文件:SaveAnnotations.java   
private void setTypeAnnotationDomains(ASTRewrite rewrite, TypeDeclaration typeDeclaration, String annotation,
        String domainName, ASTNode after) {

    SingleMemberAnnotation newParamAnnotation = getTypeAnnotationDomain(rewrite,
            typeDeclaration,
            annotation,
            domainName);

    ListRewrite paramRewrite = rewrite.getListRewrite(typeDeclaration, TypeDeclaration.MODIFIERS2_PROPERTY);
    if (after == null) {
        paramRewrite.insertFirst(newParamAnnotation, null);
    }
    else {
        paramRewrite.insertAfter(newParamAnnotation, after, null);
    }
}
项目:code    文件:SaveAnnotations.java   
private SingleMemberAnnotation getTypeAnnotationDomainAssumes(ASTRewrite rewrite, TypeDeclaration typeDeclaration, String annotation, String domainName) {
   ArrayInitializer initializer = rewrite.getAST().newArrayInitializer();

if (domainName != null) {
    ListRewrite listRewrite = rewrite.getListRewrite(initializer, ArrayInitializer.EXPRESSIONS_PROPERTY);

    StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral();
    newStringLiteral.setLiteralValue(domainName);
    listRewrite.insertFirst(newStringLiteral, null);

    declareOtherDomains(rewrite, listRewrite, typeDeclaration);
}

SingleMemberAnnotation newParamAnnotation = typeDeclaration.getAST().newSingleMemberAnnotation();
newParamAnnotation.setTypeName(rewrite.getAST().newSimpleName(annotation));
newParamAnnotation.setValue(initializer);
   return newParamAnnotation;
  }
项目:code    文件:SaveAnnotations.java   
private SingleMemberAnnotation getTypeAnnotationParams(ASTRewrite rewrite, TypeDeclaration typeDeclaration,
          String annotation) {
   ArrayInitializer initializer = rewrite.getAST().newArrayInitializer();

if (!typeDeclaration.resolveBinding().getQualifiedName().equals(Config.MAINCLASS)) {
    StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral();
    newStringLiteral.setLiteralValue("p");

    ListRewrite listRewrite = rewrite.getListRewrite(initializer, ArrayInitializer.EXPRESSIONS_PROPERTY);
    listRewrite.insertFirst(newStringLiteral, null);
}
SingleMemberAnnotation newParamAnnotation = typeDeclaration.getAST().newSingleMemberAnnotation();
newParamAnnotation.setTypeName(rewrite.getAST().newSimpleName(annotation));
newParamAnnotation.setValue(initializer);
   return newParamAnnotation;
  }
项目:code    文件:RemoveAnnotations.java   
private void setFieldAnnotation(ASTRewrite rewrite, FieldDeclaration fieldDeclaration, String annotation) {
    SingleMemberAnnotation newFieldAnnotation = fieldDeclaration.getAST().newSingleMemberAnnotation();
    newFieldAnnotation.setTypeName(rewrite.getAST().newSimpleName("Domain"));
    StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral();
    newStringLiteral.setLiteralValue(annotation);
    newFieldAnnotation.setValue(newStringLiteral);
    ASTNode modifier = getModifier(fieldDeclaration.modifiers());
    if (modifier != null) {
        ListRewrite paramRewrite = rewrite.getListRewrite(fieldDeclaration, FieldDeclaration.MODIFIERS2_PROPERTY);
        paramRewrite.insertAfter(newFieldAnnotation, modifier, null);
    }
    else {
        ListRewrite fieldRewrite = rewrite.getListRewrite(fieldDeclaration, FieldDeclaration.MODIFIERS2_PROPERTY);
        fieldRewrite.insertFirst(newFieldAnnotation, null);
    }

}
项目:code    文件:RemoveAnnotations.java   
private ASTNode getAnnotation(List paramModifiers, String annotation) {
    ASTNode found = null;
    for (Iterator itParamModifiers = paramModifiers.iterator(); itParamModifiers.hasNext();) {
        IExtendedModifier o = (IExtendedModifier) itParamModifiers.next();
        if (o instanceof SingleMemberAnnotation) {
            SingleMemberAnnotation annot = (SingleMemberAnnotation) o;

            String name = annot.getTypeName().toString();
            if (name.compareTo(annotation) == 0) {
                found = annot;
                break;
            }
        }
    }
    return found;
}
项目:code    文件:SaveAnnotations.java   
private void setTypeAnnotationDomains(ASTRewrite rewrite, TypeDeclaration typeDeclaration, String annotation,
        String domainName, ASTNode after) {

    SingleMemberAnnotation newParamAnnotation = getTypeAnnotationDomain(rewrite,
            typeDeclaration,
            annotation,
            domainName);

    ListRewrite paramRewrite = rewrite.getListRewrite(typeDeclaration, TypeDeclaration.MODIFIERS2_PROPERTY);
    if (after == null) {
        paramRewrite.insertFirst(newParamAnnotation, null);
    }
    else {
        paramRewrite.insertAfter(newParamAnnotation, after, null);
    }
}
项目:code    文件:SaveAnnotations.java   
private SingleMemberAnnotation getTypeAnnotationDomainAssumes(ASTRewrite rewrite, TypeDeclaration typeDeclaration, String annotation, String domainName) {
   ArrayInitializer initializer = rewrite.getAST().newArrayInitializer();

if (domainName != null) {
    ListRewrite listRewrite = rewrite.getListRewrite(initializer, ArrayInitializer.EXPRESSIONS_PROPERTY);

    StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral();
    newStringLiteral.setLiteralValue(domainName);
    listRewrite.insertFirst(newStringLiteral, null);

    declareOtherDomains(rewrite, listRewrite, typeDeclaration);
}

SingleMemberAnnotation newParamAnnotation = typeDeclaration.getAST().newSingleMemberAnnotation();
newParamAnnotation.setTypeName(rewrite.getAST().newSimpleName(annotation));
newParamAnnotation.setValue(initializer);
   return newParamAnnotation;
  }
项目:code    文件:SaveAnnotations.java   
private SingleMemberAnnotation getTypeAnnotationParams(ASTRewrite rewrite, TypeDeclaration typeDeclaration,
          String annotation) {
   ArrayInitializer initializer = rewrite.getAST().newArrayInitializer();

if (!typeDeclaration.resolveBinding().getQualifiedName().equals(Config.MAINCLASS)) {
    StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral();
    newStringLiteral.setLiteralValue("p");

    ListRewrite listRewrite = rewrite.getListRewrite(initializer, ArrayInitializer.EXPRESSIONS_PROPERTY);
    listRewrite.insertFirst(newStringLiteral, null);
}
SingleMemberAnnotation newParamAnnotation = typeDeclaration.getAST().newSingleMemberAnnotation();
newParamAnnotation.setTypeName(rewrite.getAST().newSimpleName(annotation));
newParamAnnotation.setValue(initializer);
   return newParamAnnotation;
  }
项目:che    文件:SuppressWarningsSubProcessor.java   
private static Annotation findExistingAnnotation(List<? extends ASTNode> modifiers) {
  for (int i = 0, len = modifiers.size(); i < len; i++) {
    Object curr = modifiers.get(i);
    if (curr instanceof NormalAnnotation || curr instanceof SingleMemberAnnotation) {
      Annotation annotation = (Annotation) curr;
      ITypeBinding typeBinding = annotation.resolveTypeBinding();
      if (typeBinding != null) {
        if ("java.lang.SuppressWarnings"
            .equals(typeBinding.getQualifiedName())) { // $NON-NLS-1$
          return annotation;
        }
      } else {
        String fullyQualifiedName = annotation.getTypeName().getFullyQualifiedName();
        if ("SuppressWarnings".equals(fullyQualifiedName)
            || "java.lang.SuppressWarnings"
                .equals(fullyQualifiedName)) { // $NON-NLS-1$ //$NON-NLS-2$
          return annotation;
        }
      }
    }
  }
  return null;
}
项目:gwt-eclipse-plugin    文件:UiBinderJavaValidator.java   
@SuppressWarnings("unchecked")
private void validateUiHandlerFieldExistenceInUiXml(
    MethodDeclaration uiHandlerDecl) {
  Annotation annotation = JavaASTUtils.findAnnotation(uiHandlerDecl,
      UiBinderConstants.UI_HANDLER_TYPE_NAME);

  if (annotation instanceof SingleMemberAnnotation) {
    SingleMemberAnnotation uiHandlerAnnotation = (SingleMemberAnnotation) annotation;
    Expression exp = uiHandlerAnnotation.getValue();
    if (exp instanceof StringLiteral) {
      validateFieldExistenceInUiXml(
          (TypeDeclaration) uiHandlerDecl.getParent(), exp,
          ((StringLiteral) exp).getLiteralValue());
    } else if (exp instanceof ArrayInitializer) {
      for (Expression element : (List<Expression>) ((ArrayInitializer) exp).expressions()) {
        if (element instanceof StringLiteral) {
          validateFieldExistenceInUiXml(
              (TypeDeclaration) uiHandlerDecl.getParent(), element,
              ((StringLiteral) element).getLiteralValue());
        }
      }
    }
  }
}
项目:txtUML    文件:MultiplicityProvider.java   
private static Integer getExplicitMultiplicity(TypeDeclaration typeDeclaration, String annotationName) {
    for (Object modifier : typeDeclaration.modifiers()) {
        if (modifier instanceof SingleMemberAnnotation) {
            SingleMemberAnnotation annotation = (SingleMemberAnnotation) modifier;
            if (annotation.getTypeName().toString().equals(annotationName)) {
                Expression value = annotation.getValue();
                if (value instanceof NumberLiteral) {
                    NumberLiteral num = (NumberLiteral) value;
                    try {
                        return new Integer(Integer.parseInt(num.getToken()));
                    } catch (NumberFormatException e) {
                        // Just let it fall through to returning 'null'
                        // below.
                    }
                }
            }
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:SuppressWarningsSubProcessor.java   
private static Annotation findExistingAnnotation(List<? extends ASTNode> modifiers) {
    for (int i= 0, len= modifiers.size(); i < len; i++) {
        Object curr= modifiers.get(i);
        if (curr instanceof NormalAnnotation || curr instanceof SingleMemberAnnotation) {
            Annotation annotation= (Annotation) curr;
            ITypeBinding typeBinding= annotation.resolveTypeBinding();
            if (typeBinding != null) {
                if ("java.lang.SuppressWarnings".equals(typeBinding.getQualifiedName())) { //$NON-NLS-1$
                    return annotation;
                }
            } else {
                String fullyQualifiedName= annotation.getTypeName().getFullyQualifiedName();
                if ("SuppressWarnings".equals(fullyQualifiedName) || "java.lang.SuppressWarnings".equals(fullyQualifiedName)) { //$NON-NLS-1$ //$NON-NLS-2$
                    return annotation;
                }
            }
        }
    }
    return null;
}
项目:EASyProducer    文件:JavaParentFragmentArtifact.java   
/**
 * Returns the annotations for a given <code>modifierList</code>.
 * 
 * @param modifierList the modifier list to be processed
 * @return An ArraySet with all annotations
 */
@OperationMeta(returnGenerics = JavaAnnotation.class)
public Set<JavaAnnotation> annotations(List<IExtendedModifier> modifierList) {
    List<JavaAnnotation> list = new ArrayList<JavaAnnotation>();
    for (Object modifier : modifierList) {
        if (modifier instanceof org.eclipse.jdt.core.dom.Annotation) {
            org.eclipse.jdt.core.dom.Annotation annot = (org.eclipse.jdt.core.dom.Annotation) modifier;
            // Get annotation name and value
            Map<String, String> fields = new HashMap<String, String>();
            // possibly the unqualified name as not resolved unless not given as qualified name!
            String name = annot.getTypeName().getFullyQualifiedName(); 
            if (annot instanceof SingleMemberAnnotation) {
                fields.put(JavaAnnotation.DEFAULT_FIELD, 
                    toString(((SingleMemberAnnotation) modifier).getValue()));
            } else if (annot instanceof NormalAnnotation) {
                @SuppressWarnings("unchecked")
                List<MemberValuePair> values = ((NormalAnnotation) annot).values();
                for (MemberValuePair pair : values) {
                    fields.put(pair.getName().getIdentifier(), toString(pair.getValue()));
                }
            }
            list.add(new JavaAnnotation(name, fields, this));
        }
    }
    return new ArraySet<JavaAnnotation>(list.toArray(new JavaAnnotation[list.size()]), JavaAnnotation.class);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:SuppressWarningsSubProcessor.java   
private static Annotation findExistingAnnotation(List<? extends ASTNode> modifiers) {
    for (int i= 0, len= modifiers.size(); i < len; i++) {
        Object curr= modifiers.get(i);
        if (curr instanceof NormalAnnotation || curr instanceof SingleMemberAnnotation) {
            Annotation annotation= (Annotation) curr;
            ITypeBinding typeBinding= annotation.resolveTypeBinding();
            if (typeBinding != null) {
                if ("java.lang.SuppressWarnings".equals(typeBinding.getQualifiedName())) { //$NON-NLS-1$
                    return annotation;
                }
            } else {
                String fullyQualifiedName= annotation.getTypeName().getFullyQualifiedName();
                if ("SuppressWarnings".equals(fullyQualifiedName) || "java.lang.SuppressWarnings".equals(fullyQualifiedName)) { //$NON-NLS-1$ //$NON-NLS-2$
                    return annotation;
                }
            }
        }
    }
    return null;
}
项目:SparkBuilderGenerator    文件:GeneratedAnnotationPopulator.java   
private SingleMemberAnnotation createGeneratedAnnotation(AST ast) {
    SingleMemberAnnotation generatedAnnotation = ast.newSingleMemberAnnotation();
    generatedAnnotation.setTypeName(ast.newSimpleName("Generated"));
    StringLiteral annotationValue = ast.newStringLiteral();
    annotationValue.setLiteralValue(StaticPreferences.PLUGIN_GENERATED_ANNOTATION_NAME);
    generatedAnnotation.setValue(annotationValue);
    return generatedAnnotation;
}
项目:SparkBuilderGenerator    文件:GeneratedAnnotationPredicate.java   
@Override
public boolean test(BodyDeclaration bodyDeclaration) {
    return ((List<IExtendedModifier>) bodyDeclaration.modifiers())
            .stream()
            .filter(modifier -> modifier instanceof SingleMemberAnnotation)
            .map(modifier -> (SingleMemberAnnotation) modifier)
            .filter(modifier -> isGeneratedAnnotation(modifier))
            .filter(modifier -> modifier.getValue() instanceof StringLiteral)
            .filter(annotation -> ((StringLiteral) annotation.getValue()).getLiteralValue().equals(PLUGIN_GENERATED_ANNOTATION_NAME))
            .findFirst()
            .isPresent();
}
项目:eclipse.jdt.ls    文件:FlowAnalyzer.java   
@Override
public void endVisit(SingleMemberAnnotation node) {
    if (skipNode(node)) {
        return;
    }
    assignFlowInfo(node, node.getValue());
}
项目:code    文件:AnnotatMetrics.java   
private void traverseMethodParams(MethodDeclaration methodDeclaration) throws IOException {
    List parameters = methodDeclaration.parameters();
    for (Iterator itParams = parameters.iterator(); itParams.hasNext();) {
        SingleVariableDeclaration param = (SingleVariableDeclaration) itParams.next();

        ITypeBinding type = param.resolveBinding().getType();
        if (hasAnnotation(param.modifiers()) && !type.isPrimitive()) {
            SingleMemberAnnotation annotation = getAnnotation(param.modifiers());
            Expression value = annotation.getValue();
            if (value instanceof StringLiteral) { //@Domain("D")
                StringLiteral annotValue = (StringLiteral)value;
                String parserInput = annotValue.getLiteralValue();
                AnnotationInfo annotInfo = AnnotationInfo.parseAnnotation(parserInput); 
                DomainParams annot = annotInfo.getAnnotation(); 
            boolean isDom = isDomain(methodDeclaration.resolveBinding().getDeclaringClass(), annot);
            boolean isDomPars = isDomainParams(methodDeclaration.resolveBinding().getDeclaringClass(), annot);

            ObjectMetricItem archMetricItem = new ObjectMetricItem(param.resolveBinding().getKey(),
                        param.getName().getFullyQualifiedName(),
                        param.getType().resolveBinding().getQualifiedName(),
                        parserInput,
                        methodDeclaration.resolveBinding().getDeclaringClass().getQualifiedName(),
                        param.toString(),
                        Modifier.isStatic(param.getModifiers()),
                        "MethodParams",
                        param.resolveBinding().getType().isArray(),
                        param.resolveBinding().getType().isEnum(),
                        param.resolveBinding().getType().isParameterizedType(),
                        isDom,
                        isDomPars,
                        annot.isObjectPublicDomain());
            if (!objectsHashtable.containsKey(archMetricItem.toString())) {
                objectsHashtable.put(archMetricItem.toString(), archMetricItem);
                }
                // TODO: src.triplets for Method Params
            }
        }
    }
}
项目:code    文件:AnnotatMetrics.java   
private boolean hasAnnotation(List<IExtendedModifier> paramModifiers) {
    boolean found = false;
    for (Iterator<IExtendedModifier> itParamModifiers = paramModifiers.iterator(); itParamModifiers.hasNext();) {
        Object o = itParamModifiers.next();
        if (o instanceof SingleMemberAnnotation) {
            SingleMemberAnnotation annot = (SingleMemberAnnotation) o;
            String name = annot.getTypeName().toString();
            if (name.compareTo("Domain") == 0) {
                found = true;
            }
        }
    }
    return found;
}
项目:code    文件:AnnotatMetrics.java   
public List<String> getAnnotationList(List<IExtendedModifier> paramModifiers, String annotation) {  
    List<String> found = new ArrayList<String>();

    for (IExtendedModifier o:paramModifiers){
        if (o instanceof SingleMemberAnnotation) {
            SingleMemberAnnotation annot = (SingleMemberAnnotation) o;
            if (annot.getTypeName().toString().equals(annotation)) {

                Expression value = annot.getValue();
                if (value instanceof ArrayInitializer) { //@Domains( {"D", "U"})
                    ArrayInitializer annotValueArray = (ArrayInitializer)value;
                    found = new ArrayList<String>();
                    for (Object s:annotValueArray.expressions()){
                        if (s instanceof StringLiteral) {
                            StringLiteral sLiteral = (StringLiteral)s;
                            found.add(sLiteral.getLiteralValue());
                        }
                    }
                    return found;
                }
                if (value instanceof StringLiteral) { //@Domains ("D")
                    StringLiteral annotValue = (StringLiteral)value;
                    String parserInput = annotValue.getLiteralValue();
                    found = new ArrayList<String>();
                    found.add(parserInput);
                    return found;
                }
            }
        }
    }
    return found;
}
项目:code    文件:AnnotatMetrics.java   
@Override
        public boolean visit(VariableDeclarationStatement param) {

            ITypeBinding type = param.getType().resolveBinding();
            if (hasAnnotation(param.modifiers()) && !type.isPrimitive()) {
                List<VariableDeclarationFragment> L = param.fragments();
                for (VariableDeclarationFragment oo : L) {

                    SingleMemberAnnotation annotation = getAnnotation(param.modifiers());
                    Expression value = annotation.getValue();
                    if (value instanceof StringLiteral) { //@Domain("D")
                        StringLiteral annotValue = (StringLiteral)value;
                        String parserInput = annotValue.getLiteralValue();
                        AnnotationInfo annotInfo = AnnotationInfo.parseAnnotation(parserInput); 
                        DomainParams annot = annotInfo.getAnnotation(); 
                        boolean b = annot.isObjectPublicDomain();
                        if (b)
                        {
                            b = true;
                        }


                        boolean isDom = false;
                        boolean isDomPars = false;
                        String qualifiedName = "";

//                      if (oo.resolveBinding().getDeclaringMethod() != null) {
//                          qualifiedName = oo.resolveBinding().getDeclaringMethod().getDeclaringClass().getQualifiedName();
//
//                          isDom = isDomain(oo.resolveBinding().getDeclaringMethod().getDeclaringClass(), annot);
//                          isDomPars = isDomainParams(oo.resolveBinding().getDeclaringMethod().getDeclaringClass(),annot);
//
//
//                      }
//                      else 
                        {

                            qualifiedName = currentType.resolveBinding().getQualifiedName();

                            isDom = isDomain(currentType.resolveBinding(), annot);
                            isDomPars = isDomainParams(currentType.resolveBinding() , annot);       

                        }

                        ObjectMetricItem archMetricItem = new ObjectMetricItem(oo.resolveBinding().getKey(),oo.resolveBinding().getName().toString(),
                                param.getType().resolveBinding().getQualifiedName().toString(),
                                parserInput,
                                qualifiedName,
                                oo.toString(),
                                Modifier.isStatic(param.getModifiers()),
                                "LocalVariable",
                                type.isArray(),
                                type.isEnum(),
                                type.isParameterizedType(),
                                isDom,
                                isDomPars,
                                annot.isObjectPublicDomain()
                            );



                        if (!objectsHashtable.containsKey(archMetricItem.toString())) {
                            objectsHashtable.put(archMetricItem.toString(), archMetricItem);
                        }

                        // TODO: src.triplets for Local variables
                    }
                }
            }
                return super.visit(param);
        }
项目:code    文件:DefaultingVisitor.java   
private void setParameterAnnotation(ASTRewrite rewrite, SingleVariableDeclaration param, String annotation) {
    SingleMemberAnnotation newParamAnnotation = param.getAST().newSingleMemberAnnotation();
    newParamAnnotation.setTypeName(rewrite.getAST().newSimpleName("Domain"));
    StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral();
    newStringLiteral.setLiteralValue(annotation);
    newParamAnnotation.setValue(newStringLiteral);
    ListRewrite paramRewrite = rewrite.getListRewrite(param, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
    paramRewrite.insertFirst(newParamAnnotation, null);
}
项目:code    文件:DefaultingVisitor.java   
private boolean hasAnnotation(List paramModifiers) {
    boolean found = false;
    for (Iterator itParamModifiers = paramModifiers.iterator(); itParamModifiers.hasNext();) {
        Object o = itParamModifiers.next();
        if (o instanceof SingleMemberAnnotation) {
            SingleMemberAnnotation annot = (SingleMemberAnnotation) o;
            String name = annot.getTypeName().toString();
            if (name.compareTo("Domain") == 0) {
                found = true;
            }
        }
    }
    return found;
}
项目:code    文件:RemoveAnnotationsVisitor.java   
@Override
public boolean visit(CatchClause node) {

    SingleVariableDeclaration param = node.getException();

    ITypeBinding type = param.resolveBinding().getType();
    SingleMemberAnnotation annot = hasAnnotation(param.modifiers());
    if (annot != null) {
        ListRewrite paramRewrite = rewrite.getListRewrite(param, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
        paramRewrite.remove(annot, null);
    }


    return super.visit(node);
}
项目:code    文件:RemoveAnnotationsVisitor.java   
private SingleMemberAnnotation hasAnnotation(List paramModifiers) {
    for (Iterator itParamModifiers = paramModifiers.iterator(); itParamModifiers.hasNext();) {
        Object o = itParamModifiers.next();
        if (o instanceof SingleMemberAnnotation) {
            SingleMemberAnnotation annot = (SingleMemberAnnotation) o;
            String name = annot.getTypeName().toString();
            if (name.compareTo("Domain") == 0) {
                return annot;
            }
        }
    }
    return null;
}
项目:code    文件:RemoveAnnotations.java   
private ASTNode hasTypeAnnotation(List paramModifiers, String annotation) {
    ASTNode found = null;
    for (Iterator itParamModifiers = paramModifiers.iterator(); itParamModifiers.hasNext();) {
        Object o = itParamModifiers.next();
        if (o instanceof SingleMemberAnnotation) {
            SingleMemberAnnotation annot = (SingleMemberAnnotation) o;
            String name = annot.getTypeName().toString();
            if (name.compareTo(annotation) == 0) {
                found = annot;
            }
        }
    }
    return found;
}
项目:code    文件:RemoveAnnotations.java   
private void setParameterAnnotation(ASTRewrite rewrite, SingleVariableDeclaration param, String annotation) {
    SingleMemberAnnotation newParamAnnotation = param.getAST().newSingleMemberAnnotation();
    newParamAnnotation.setTypeName(rewrite.getAST().newSimpleName("Domain"));
    StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral();
    newStringLiteral.setLiteralValue(annotation);
    newParamAnnotation.setValue(newStringLiteral);
    ListRewrite paramRewrite = rewrite.getListRewrite(param, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
    paramRewrite.insertFirst(newParamAnnotation, null);
}
项目:code    文件:RemoveAnnotations.java   
private boolean hasAnnotation(List paramModifiers) {
    boolean found = false;
    for (Iterator itParamModifiers = paramModifiers.iterator(); itParamModifiers.hasNext();) {
        Object o = itParamModifiers.next();
        if (o instanceof SingleMemberAnnotation) {
            SingleMemberAnnotation annot = (SingleMemberAnnotation) o;
            String name = annot.getTypeName().toString();
            if (name.compareTo("Domain") == 0) {
                found = true;
            }
        }
    }
    return found;
}
项目:code    文件:SaveAnnotations.java   
/**
 * @param rewrite
 * @param methodDeclaration
 */
private void annotateMethodReturnType(ASTRewrite rewrite, MethodDeclaration methodDeclaration) {
    Type returnType2 = methodDeclaration.getReturnType2();
    if (returnType2 != null) {
        ITypeBinding resolveBinding = returnType2.resolveBinding();
        if ( !resolveBinding.isPrimitive()) {
            String annotation = "";
            if (HARD_CODE_STATICS && Modifier.isStatic(methodDeclaration.getModifiers())) {
                annotation = "shared<shared>"; // only thing a static can be
            }
            else {
                annotation = strategy.getAnnotationForMethodReturn(methodDeclaration);
            }

            SingleMemberAnnotation currentAnnotation = getCurrentAnnotation(methodDeclaration.modifiers());
            if(currentAnnotation == null ) {
                setReturnTypeAnnotation(rewrite, methodDeclaration, annotation);
            }
            else {
                updateReturnTypeAnnotation(rewrite, methodDeclaration, annotation, currentAnnotation);
            }       

            String srcType = resolveBinding.getQualifiedName();
            String dstType = methodDeclaration.resolveBinding().getDeclaringClass().getQualifiedName();
            // XXX. Come up with a better key
            trackChanges(returnType2.toString(), annotation, getValue(currentAnnotation), CSVConst.METHOD_RETURN, srcType, dstType);
        }
    }
}
项目:code    文件:SaveAnnotations.java   
private String getValue(SingleMemberAnnotation currentAnnotation) {
 String value = "";
 if (currentAnnotation != null ) {
    Expression value2 = currentAnnotation.getValue();
    if (value2 instanceof StringLiteral ) {
        return ((StringLiteral)value2).getLiteralValue();
    }
 }
 return value;
}
项目:code    文件:SaveAnnotations.java   
private void annotateFieldDeclarations(ASTRewrite rewrite, TypeDeclaration declaration) {

        FieldDeclaration[] fieldDeclarations = declaration.getFields();
        for (int i = 0; i < fieldDeclarations.length; i++) {
            FieldDeclaration fieldDeclaration = fieldDeclarations[i];
            ITypeBinding type = fieldDeclaration.getType().resolveBinding();

            if (!type.isPrimitive()) {
                String annotation = "";

                if (HARD_CODE_STATICS && Modifier.isStatic(fieldDeclaration.getModifiers())) {
                    // XXX. Avoid unique fields. Use shared. 
                    annotation = "shared<shared>";
                }
                else {
                    annotation = strategy.getAnnotationForFieldDeclaration(fieldDeclaration);
                }

                SingleMemberAnnotation currentAnnotation = getCurrentAnnotation(fieldDeclaration.modifiers());
                if (currentAnnotation == null) {
                    setFieldAnnotation(rewrite, fieldDeclaration, annotation);
                }
                else {
                    updateFieldAnnotation(rewrite, fieldDeclaration, annotation, currentAnnotation);
                }       

                String srcType = type.getQualifiedName();
                String dstType = declaration.getName().getFullyQualifiedName();
                // XXX. Come up with a better key
                trackChanges(fieldDeclaration.toString(), annotation, getValue(currentAnnotation), CSVConst.FIELD, srcType, dstType);
            }
        }
    }
项目:code    文件:SaveAnnotations.java   
private SingleMemberAnnotation setParameterAnnotation(ASTRewrite rewrite, SingleVariableDeclaration param, String annotation) {
    SingleMemberAnnotation newParamAnnotation = getParameterAnnotation(rewrite, param, annotation);
    ListRewrite paramRewrite = rewrite.getListRewrite(param, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
    paramRewrite.insertFirst(newParamAnnotation, null);

    return newParamAnnotation;
}
项目:code    文件:SaveAnnotations.java   
private SingleMemberAnnotation getParameterAnnotation(ASTRewrite rewrite, SingleVariableDeclaration param,
          String annotation) {
   SingleMemberAnnotation newParamAnnotation = param.getAST().newSingleMemberAnnotation();
newParamAnnotation.setTypeName(rewrite.getAST().newSimpleName("Domain"));
StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral();
newStringLiteral.setLiteralValue(annotation);
newParamAnnotation.setValue(newStringLiteral);
   return newParamAnnotation;
  }
项目:code    文件:SaveAnnotations.java   
private SingleMemberAnnotation setFieldAnnotation(ASTRewrite rewrite, FieldDeclaration fieldDeclaration, String annotation) {
    SingleMemberAnnotation newFieldAnnotation = getFieldAnnotation(rewrite, fieldDeclaration, annotation);
    ASTNode modifier = getModifier(fieldDeclaration.modifiers());
    if (modifier != null) {
        ListRewrite paramRewrite = rewrite.getListRewrite(fieldDeclaration, FieldDeclaration.MODIFIERS2_PROPERTY);
        paramRewrite.insertAfter(newFieldAnnotation, modifier, null);
    }
    else {
        ListRewrite fieldRewrite = rewrite.getListRewrite(fieldDeclaration, FieldDeclaration.MODIFIERS2_PROPERTY);
        fieldRewrite.insertFirst(newFieldAnnotation, null);
    }

    return newFieldAnnotation;
}
项目:code    文件:SaveAnnotations.java   
private void updateFieldAnnotation(ASTRewrite rewrite, FieldDeclaration fieldDeclaration, String annotation, SingleMemberAnnotation currentAnnotation) {
    SingleMemberAnnotation newFieldAnnotation = getFieldAnnotation(rewrite, fieldDeclaration, annotation);
    ASTNode modifier = getModifier(fieldDeclaration.modifiers());
    if (modifier != null) {
        ListRewrite paramRewrite = rewrite.getListRewrite(fieldDeclaration, FieldDeclaration.MODIFIERS2_PROPERTY);
        paramRewrite.replace(currentAnnotation, newFieldAnnotation, null);
    }
    else {
        ListRewrite fieldRewrite = rewrite.getListRewrite(fieldDeclaration, FieldDeclaration.MODIFIERS2_PROPERTY);
        fieldRewrite.replace(currentAnnotation, newFieldAnnotation, null);
    }
}
项目:code    文件:SaveAnnotations.java   
private SingleMemberAnnotation getFieldAnnotation(ASTRewrite rewrite, FieldDeclaration fieldDeclaration,
        String annotation) {
    SingleMemberAnnotation newFieldAnnotation = fieldDeclaration.getAST().newSingleMemberAnnotation();
    newFieldAnnotation.setTypeName(rewrite.getAST().newSimpleName("Domain"));
    StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral();
    newStringLiteral.setLiteralValue(annotation);
    newFieldAnnotation.setValue(newStringLiteral);
    return newFieldAnnotation;
}
项目:code    文件:SaveAnnotations.java   
private void setTypeAnnotationDomainAssumes(ASTRewrite rewrite, TypeDeclaration typeDeclaration, String annotation, String domainName, ASTNode after) {

        SingleMemberAnnotation newParamAnnotation = getTypeAnnotationDomainAssumes(rewrite,typeDeclaration, annotation, domainName);

        ListRewrite paramRewrite = rewrite.getListRewrite(typeDeclaration, TypeDeclaration.MODIFIERS2_PROPERTY);
        if (after == null) {
            paramRewrite.insertFirst(newParamAnnotation, null);
        }
        else {
            paramRewrite.insertAfter(newParamAnnotation, after, null);
        }
    }
项目:code    文件:SaveAnnotations.java   
private void updateTypeAnnotationDomains(ASTRewrite rewrite, TypeDeclaration typeDeclaration, String annotation,
        String domainName, ASTNode after, ASTNode current) {

    SingleMemberAnnotation newParamAnnotation = getTypeAnnotationDomain(rewrite, typeDeclaration, annotation, domainName);

    ListRewrite paramRewrite = rewrite.getListRewrite(typeDeclaration, TypeDeclaration.MODIFIERS2_PROPERTY);
    paramRewrite.replace(current, newParamAnnotation, null);
}