Java 类org.eclipse.jdt.core.IMemberValuePair 实例源码

项目:codelens-eclipse    文件:JDTUtils.java   
private static boolean isSilencedGeneratedAnnotation(IAnnotation annotation) throws JavaModelException {
    if ("javax.annotation.Generated".equals(annotation.getElementName())) {
        IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs();
        for (IMemberValuePair m : memberValuePairs) {
            if ("value".equals(m.getMemberName()) && IMemberValuePair.K_STRING == m.getValueKind()) {
                if (m.getValue() instanceof String) {
                    return SILENCED_CODEGENS.contains(m.getValue());
                } else if (m.getValue() instanceof Object[]) {
                    for (Object val : (Object[]) m.getValue()) {
                        if (SILENCED_CODEGENS.contains(val)) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
项目:eclipse.jdt.ls    文件:JDTUtils.java   
private static boolean isSilencedGeneratedAnnotation(IAnnotation annotation) throws JavaModelException {
    if ("javax.annotation.Generated".equals(annotation.getElementName())) {
        IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs();
        for (IMemberValuePair m : memberValuePairs) {
            if ("value".equals(m.getMemberName())
                    && IMemberValuePair.K_STRING == m.getValueKind()) {
                if (m.getValue() instanceof String) {
                    return SILENCED_CODEGENS.contains(m.getValue());
                } else if (m.getValue() instanceof Object[]) {
                    for (Object val : (Object[])m.getValue()) {
                        if(SILENCED_CODEGENS.contains(val)) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
项目:eclipse.jdt.ls    文件:JavaElementLabelComposer.java   
public void appendAnnotationLabel(IAnnotation annotation, long flags) throws JavaModelException {
    fBuilder.append('@');
    appendTypeSignatureLabel(annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags);
    IMemberValuePair[] memberValuePairs= annotation.getMemberValuePairs();
    if (memberValuePairs.length == 0) {
        return;
    }
    fBuilder.append('(');
    for (int i= 0; i < memberValuePairs.length; i++) {
        if (i > 0) {
            fBuilder.append(JavaElementLabels.COMMA_STRING);
        }
        IMemberValuePair memberValuePair= memberValuePairs[i];
        fBuilder.append(getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName()));
        fBuilder.append('=');
        appendAnnotationValue(annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags);
    }
    fBuilder.append(')');
}
项目:che    文件:SourcesFromBytecodeGenerator.java   
public void appendAnnotationLabel(IAnnotation annotation, long flags, StringBuilder builder)
    throws JavaModelException {
  builder.append('@');
  appendTypeSignatureLabel(
      annotation,
      Signature.createTypeSignature(annotation.getElementName(), false),
      flags,
      builder);
  IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs();
  if (memberValuePairs.length == 0) return;
  builder.append('(');
  for (int i = 0; i < memberValuePairs.length; i++) {
    if (i > 0) builder.append(JavaElementLabels.COMMA_STRING);
    IMemberValuePair memberValuePair = memberValuePairs[i];
    builder.append(
        getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName()));
    builder.append('=');
    appendAnnotationValue(
        annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags, builder);
  }
  builder.append(')');
}
项目:che    文件:StubCreator.java   
private void appendAnnotation(IAnnotation annotation) throws JavaModelException {
  String name = annotation.getElementName();
  if (!fStubInvisible && name.startsWith("sun.")) // $NON-NLS-1$
  return; // skip Sun-internal annotations

  fBuffer.append('@');
  fBuffer.append(name);
  fBuffer.append('(');

  IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs();
  for (IMemberValuePair pair : memberValuePairs) {
    fBuffer.append(pair.getMemberName());
    fBuffer.append('=');
    appendAnnotationValue(pair.getValue(), pair.getValueKind());
    fBuffer.append(',');
  }
  if (memberValuePairs.length > 0) fBuffer.deleteCharAt(fBuffer.length() - 1);

  fBuffer.append(')').append('\n');
}
项目:che    文件:StubCreator.java   
private void appendAnnotationValue(Object value, int valueKind) throws JavaModelException {
  if (value instanceof Object[]) {
    Object[] objects = (Object[]) value;
    fBuffer.append('{');
    for (Object object : objects) {
      appendAnnotationValue(object, valueKind);
      fBuffer.append(',');
    }
    if (objects.length > 0) fBuffer.deleteCharAt(fBuffer.length() - 1);
    fBuffer.append('}');

  } else {
    switch (valueKind) {
      case IMemberValuePair.K_ANNOTATION:
        appendAnnotation((IAnnotation) value);
        break;
      case IMemberValuePair.K_STRING:
        fBuffer.append('"').append(value).append('"');
        break;

      default:
        fBuffer.append(value);
        break;
    }
  }
}
项目:che    文件:JavaElementLabelComposer.java   
public void appendAnnotationLabel(IAnnotation annotation, long flags) throws JavaModelException {
  fBuffer.append('@');
  appendTypeSignatureLabel(
      annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags);
  IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs();
  if (memberValuePairs.length == 0) return;
  fBuffer.append('(');
  for (int i = 0; i < memberValuePairs.length; i++) {
    if (i > 0) fBuffer.append(JavaElementLabels.COMMA_STRING);
    IMemberValuePair memberValuePair = memberValuePairs[i];
    fBuffer.append(
        getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName()));
    fBuffer.append('=');
    appendAnnotationValue(
        annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags);
  }
  fBuffer.append(')');
}
项目:che    文件:Util.java   
public static Object getNegativeAnnotationMemberValue(
    MemberValuePair memberValuePair, Constant constant) {
  if (constant == null) {
    memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
    return null;
  }
  switch (constant.typeID()) {
    case TypeIds.T_int:
      memberValuePair.valueKind = IMemberValuePair.K_INT;
      return new Integer(constant.intValue() * -1);
    case TypeIds.T_float:
      memberValuePair.valueKind = IMemberValuePair.K_FLOAT;
      return new Float(constant.floatValue() * -1.0f);
    case TypeIds.T_double:
      memberValuePair.valueKind = IMemberValuePair.K_DOUBLE;
      return new Double(constant.doubleValue() * -1.0);
    case TypeIds.T_long:
      memberValuePair.valueKind = IMemberValuePair.K_LONG;
      return new Long(constant.longValue() * -1L);
    default:
      memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
      return null;
  }
}
项目:vsminecraft    文件:JavaElementLabelComposer.java   
public void appendAnnotationLabel(IAnnotation annotation, long flags) throws JavaModelException {
    fBuffer.append('@');
    appendTypeSignatureLabel(annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags);
    IMemberValuePair[] memberValuePairs= annotation.getMemberValuePairs();
    if (memberValuePairs.length == 0)
        return;
    fBuffer.append('(');
    for (int i= 0; i < memberValuePairs.length; i++) {
        if (i > 0)
            fBuffer.append(COMMA_STRING);
        IMemberValuePair memberValuePair= memberValuePairs[i];
        fBuffer.append(getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName()));
        fBuffer.append('=');
        appendAnnotationValue(annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags);
    }
    fBuffer.append(')');
}
项目:strutsclipse    文件:AnnotationParser.java   
private boolean sameAnnotationStringValue(IAnnotation annotation,
        String actionValue) throws JavaModelException {
    boolean res = false;
    if (annotation.exists()) {
        IMemberValuePair[] valuePairs = annotation.getMemberValuePairs();
        for (IMemberValuePair valuePair : valuePairs) {
            res = valuePair.getValueKind() == IMemberValuePair.K_STRING
                    && valuePair.getValue() instanceof String
                    && ANNOTATION_VALUE.equals(valuePair.getMemberName())
                    && actionValue.equals(valuePair.getValue());
            if (res) {
                break;
            }
        }
    }
    return res;
}
项目:Eclipse-Postfix-Code-Completion    文件:StubCreator.java   
private void appendAnnotation(IAnnotation annotation) throws JavaModelException {
    String name= annotation.getElementName();
    if (!fStubInvisible && name.startsWith("sun.")) //$NON-NLS-1$
        return; // skip Sun-internal annotations 

    fBuffer.append('@');
    fBuffer.append(name);
    fBuffer.append('(');

    IMemberValuePair[] memberValuePairs= annotation.getMemberValuePairs();
    for (IMemberValuePair pair : memberValuePairs) {
        fBuffer.append(pair.getMemberName());
        fBuffer.append('=');
        appendAnnotationValue(pair.getValue(), pair.getValueKind());
        fBuffer.append(',');
    }
    if (memberValuePairs.length > 0)
        fBuffer.deleteCharAt(fBuffer.length() - 1);

    fBuffer.append(')').append('\n');
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaElementLabelComposer.java   
public void appendAnnotationLabel(IAnnotation annotation, long flags) throws JavaModelException {
    fBuffer.append('@');
    appendTypeSignatureLabel(annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags);
    IMemberValuePair[] memberValuePairs= annotation.getMemberValuePairs();
    if (memberValuePairs.length == 0)
        return;
    fBuffer.append('(');
    for (int i= 0; i < memberValuePairs.length; i++) {
        if (i > 0)
            fBuffer.append(JavaElementLabels.COMMA_STRING);
        IMemberValuePair memberValuePair= memberValuePairs[i];
        fBuffer.append(getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName()));
        fBuffer.append('=');
        appendAnnotationValue(annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags);
    }
    fBuffer.append(')');
}
项目:mybatipse    文件:JavaMapperUtil.java   
public static String getAnnotationMemberValue(IAnnotation annotation, String memberName)
{
    try
    {
        IMemberValuePair[] valuePairs = annotation.getMemberValuePairs();
        for (IMemberValuePair valuePair : valuePairs)
        {
            if (memberName.equals(valuePair.getMemberName()))
            {
                return (String)valuePair.getValue();
            }
        }
    }
    catch (JavaModelException e)
    {
        Activator.log(Status.ERROR, "Failed to get member value pairs.", e);
    }
    return null;
}
项目:mybatipse    文件:JavaMapperUtil.java   
@Override
public boolean matches(IMethod method) throws JavaModelException
{
    for (IAnnotation annotation : method.getAnnotations())
    {
        String annotationName = annotation.getElementName();
        if (MybatipseConstants.ANNOTATION_RESULTS.equals(annotationName))
        {
            IMemberValuePair[] valuePairs = annotation.getMemberValuePairs();
            for (IMemberValuePair valuePair : valuePairs)
            {
                if ("id".equals(valuePair.getMemberName()))
                {
                    String resultsId = (String)valuePair.getValue();
                    return nameMatches(resultsId, matchString, exactMatch);
                }
            }
        }
    }
    return false;
}
项目:mybatipse    文件:TypeAliasCache.java   
private String getAliasAnnotationValue(IType foundType) throws JavaModelException
{
    String alias = null;
    IAnnotation[] annotations = foundType.getAnnotations();
    for (IAnnotation annotation : annotations)
    {
        if ("Alias".equals(annotation.getElementName()))
        {
            IMemberValuePair[] params = annotation.getMemberValuePairs();
            if (params.length > 0)
            {
                alias = (String)params[0].getValue();
            }
        }
    }
    return alias;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:StubCreator.java   
private void appendAnnotation(IAnnotation annotation) throws JavaModelException {
    fBuffer.append('@');
    fBuffer.append(annotation.getElementName());
    fBuffer.append('(');

    IMemberValuePair[] memberValuePairs= annotation.getMemberValuePairs();
    for (IMemberValuePair pair : memberValuePairs) {
        fBuffer.append(pair.getMemberName());
        fBuffer.append('=');
        appendAnnotationValue(pair.getValue(), pair.getValueKind());
        fBuffer.append(',');
    }
    if (memberValuePairs.length > 0)
        fBuffer.deleteCharAt(fBuffer.length() - 1);

    fBuffer.append(')').append('\n');
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaElementLabelComposer.java   
public void appendAnnotationLabel(IAnnotation annotation, long flags) throws JavaModelException {
    fBuffer.append('@');
    appendTypeSignatureLabel(annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags);
    IMemberValuePair[] memberValuePairs= annotation.getMemberValuePairs();
    if (memberValuePairs.length == 0)
        return;
    fBuffer.append('(');
    for (int i= 0; i < memberValuePairs.length; i++) {
        if (i > 0)
            fBuffer.append(JavaElementLabels.COMMA_STRING);
        IMemberValuePair memberValuePair= memberValuePairs[i];
        fBuffer.append(getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName()));
        fBuffer.append('=');
        appendAnnotationValue(annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags);
    }
    fBuffer.append(')');
}
项目:eclipse-tapestry5-plugin    文件:TapestryComponentSpecification.java   
private Component createComponentFromInjection(IType type, final IField field, IAnnotation annotation) throws JavaModelException
{
    Component component = new Component();
    component.setSpecification(this);
    component.setName(field.getElementName());
    component.setNameRange(field.getNameRange());
    component.setJavadocValue(new LazyValue<String>()
    {
        @Override
        protected String eval() throws CoreException
        {
            return JavadocContentAccess2.getHTMLContent(field, true);
        }
    });

    for (IMemberValuePair pair : annotation.getMemberValuePairs())
    {
        component.setId(String.valueOf(pair.getValue()));
    }

    setComponentDefaults(type, field, component);

    return component;
}
项目:eclipse-tapestry5-plugin    文件:TapestryComponentSpecification.java   
protected Property createProperty(IType type, IField field, IAnnotation annotation) throws JavaModelException
{
    Property property = createProperty(field, field.getElementName());

    for (IMemberValuePair pair : annotation.getMemberValuePairs())
    {
        if ("read".equals(pair.getMemberName()))
        {
            property.setRead("true".equals(String.valueOf(pair.getValue())));
        }
        else if ("write".equals(pair.getMemberName()))
        {
            property.setWrite("true".equals(String.valueOf(pair.getValue())));
        }
    }

    return property;
}
项目:srcrepo    文件:ClassFileParser.java   
protected AnnotationTypeMemberDeclaration visitAnnotationTypeMemberDeclaration(
        final IMethod method) throws JavaModelException {
    AnnotationTypeMemberDeclaration element = getFactory()
            .createAnnotationTypeMemberDeclaration();
    initializeNode(element);

    element.setName(method.getElementName());
    element.setType(getRefOnType(method.getReturnType()));

    // the default value of this annotation member
    IMemberValuePair defaultValue = method.getDefaultValue();
    if (defaultValue != null) {
        Expression result = manageMemberValuePair(defaultValue);
        element.setDefault(result);
    }

    Modifier m = getFactory().createModifier();
    m.setBodyDeclaration(element);
    element.setModifier(m);
    manageModifier(m, method.getFlags(), method);

    ClassFileParserUtils.manageBindingDeclaration(element, method, this);

    return element;
}
项目:vertigo-chroma-kspplugin    文件:JdtUtils.java   
/**
 * Retourne la valeur du membre d'une annotation donnée.
 * 
 * @param annotation Annotation.
 * @param memberName Nom du membre.
 * @return Valeur du membre.
 */
public static Object getMemberValue(IAnnotation annotation, String memberName) {
    try {
        for (IMemberValuePair pair : annotation.getMemberValuePairs()) {
            if (memberName.equals(pair.getMemberName())) {
                return pair.getValue();
            }
        }
    } catch (JavaModelException e) {
        ErrorUtils.handle(e);
    }
    return null;
}
项目:vertigo-chroma-kspplugin    文件:JdtUtils.java   
/**
 * Retourne la valeur du membre par défaut d'une annotation donnée.
 * 
 * @param annotation Annotation.
 * @return Valeur du membre.
 */
public static String getMemberValue(IAnnotation annotation) {
    try {
        IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs();
        if (memberValuePairs.length == 0) {
            return null;
        }
        return (String) memberValuePairs[0].getValue();
    } catch (JavaModelException e) {
        ErrorUtils.handle(e);
    }
    return null;
}
项目:google-cloud-eclipse    文件:PipelineOptionsPropertyTest.java   
@Test
public void testFromMethodWithValidationRequiredWithNoGroupsIsRequiredWithNoGroups()
    throws JavaModelException {
  IMethod method = mock(IMethod.class);
  when(method.getElementName()).thenReturn("getFoo");

  IAnnotation required = mock(IAnnotation.class);
  when(method.getAnnotation(PipelineOptionsNamespaces.validationRequired(version)))
      .thenReturn(required);
  when(required.exists()).thenReturn(true);
  when(required.getElementName())
      .thenReturn(PipelineOptionsNamespaces.validationRequired(version));
  when(method.getAnnotations()).thenReturn(new IAnnotation[] {required});

  IMemberValuePair[] memberValuePairs = new IMemberValuePair[0];
  when(required.getMemberValuePairs()).thenReturn(memberValuePairs);

  IAnnotation description = mock(IAnnotation.class);
  when(description.exists()).thenReturn(false);
  when(method.getAnnotation(PipelineOptionsNamespaces.descriptionAnnotation(version)))
      .thenReturn(description);

  PipelineOptionsProperty property = PipelineOptionsProperty.fromMethod(method, version);

  assertEquals("foo", property.getName());
  assertTrue(property.isRequired());
  assertTrue(property.getGroups().isEmpty());
}
项目:google-cloud-eclipse    文件:PipelineOptionsPropertyTest.java   
@Test
public void testFromMethodWithValidationRequiredAndGroupsIsRequiredWithGroups()
    throws JavaModelException {
  IMethod method = mock(IMethod.class);
  when(method.getElementName()).thenReturn("getFoo");

  IAnnotation required = mock(IAnnotation.class);
  when(method.getAnnotation(PipelineOptionsNamespaces.validationRequired(version)))
      .thenReturn(required);
  when(required.exists()).thenReturn(true);
  when(required.getElementName())
      .thenReturn(PipelineOptionsNamespaces.validationRequired(version));
  when(method.getAnnotations()).thenReturn(new IAnnotation[] {required});

  String firstGroup = "bar";
  String secondGroup = "baz";
  String[] groups = new String[] {firstGroup, secondGroup};

  IMemberValuePair groupPair = mock(IMemberValuePair.class);
  when(groupPair.getMemberName())
      .thenReturn(PipelineOptionsNamespaces.validationRequiredGroupField(version));
  when(groupPair.getValue()).thenReturn(groups);
  when(groupPair.getValueKind()).thenReturn(IMemberValuePair.K_STRING);

  IMemberValuePair[] memberValuePairs = new IMemberValuePair[] {groupPair};
  when(required.getMemberValuePairs()).thenReturn(memberValuePairs);

  IAnnotation description = mock(IAnnotation.class);
  when(description.exists()).thenReturn(false);
  when(method.getAnnotation(PipelineOptionsNamespaces.descriptionAnnotation(version)))
      .thenReturn(description);

  PipelineOptionsProperty property = PipelineOptionsProperty.fromMethod(method, version);

  assertEquals("foo", property.getName());
  assertTrue(property.isRequired());
  assertTrue(property.getGroups().contains(firstGroup));
  assertTrue(property.getGroups().contains(secondGroup));
}
项目:google-cloud-eclipse    文件:PipelineOptionsPropertyTest.java   
@Test
public void testFromMethodWithDefaultHasDefaultProvided() throws JavaModelException {
  IMethod method = mock(IMethod.class);
  when(method.getElementName()).thenReturn("getFoo");

  IAnnotation required = mock(IAnnotation.class);
  when(method.getAnnotation(PipelineOptionsNamespaces.validationRequired(version)))
      .thenReturn(required);
  when(required.exists()).thenReturn(true);
  when(required.getElementName())
      .thenReturn(PipelineOptionsNamespaces.validationRequired(version));

  IMemberValuePair[] memberValuePairs = new IMemberValuePair[0];
  when(required.getMemberValuePairs()).thenReturn(memberValuePairs);

  IAnnotation defaultAnnotation = mock(IAnnotation.class);
  when(defaultAnnotation.getElementName())
      .thenReturn(PipelineOptionsNamespaces.defaultProvider(version) + ".String");
  when(method.getAnnotations()).thenReturn(new IAnnotation[] {required, defaultAnnotation});

  IAnnotation description = mock(IAnnotation.class);
  when(description.exists()).thenReturn(false);
  when(method.getAnnotation(PipelineOptionsNamespaces.descriptionAnnotation(version)))
      .thenReturn(description);

  PipelineOptionsProperty property = PipelineOptionsProperty.fromMethod(method, version);

  assertEquals("foo", property.getName());
  assertTrue(property.isRequired());
  assertTrue(property.isDefaultProvided());
  assertFalse(property.isUserValueRequired());
}
项目:google-cloud-eclipse    文件:PipelineOptionsPropertyTest.java   
@Test
public void testFromMethodWithDescriptionHasDescription() throws Exception {
  IMethod method = mock(IMethod.class);
  when(method.getElementName()).thenReturn("getFoo");

  IAnnotation required = mock(IAnnotation.class);
  when(method.getAnnotation(PipelineOptionsNamespaces.validationRequired(version)))
      .thenReturn(required);
  when(required.exists()).thenReturn(false);
  when(required.getElementName())
      .thenReturn(PipelineOptionsNamespaces.validationRequired(version));
  when(method.getAnnotations()).thenReturn(new IAnnotation[] {required});

  IAnnotation description = mock(IAnnotation.class);
  when(description.exists()).thenReturn(true);
  when(method.getAnnotation(PipelineOptionsNamespaces.descriptionAnnotation(version)))
      .thenReturn(description);
  IMemberValuePair memberValuePair = mock(IMemberValuePair.class);
  String descriptionValue = "My_description exists";
  when(memberValuePair.getValue()).thenReturn(descriptionValue);
  when(memberValuePair.getValueKind()).thenReturn(IMemberValuePair.K_STRING);
  IMemberValuePair[] memberValuePairs = new IMemberValuePair[] {memberValuePair};
  when(description.getMemberValuePairs()).thenReturn(memberValuePairs);

  PipelineOptionsProperty property = PipelineOptionsProperty.fromMethod(method, version);

  assertEquals(descriptionValue, property.getDescription());
}
项目:google-cloud-eclipse    文件:PipelineOptionsPropertyTest.java   
@Test
public void testFromMethodWithNonStringDescriptionHasAbsentOptional() throws Exception {
  IMethod method = mock(IMethod.class);
  when(method.getElementName()).thenReturn("getFoo");

  IAnnotation required = mock(IAnnotation.class);
  when(method.getAnnotation(PipelineOptionsNamespaces.validationRequired(version)))
      .thenReturn(required);
  when(required.exists()).thenReturn(false);
  when(required.getElementName())
      .thenReturn(PipelineOptionsNamespaces.validationRequired(version));
  when(method.getAnnotations()).thenReturn(new IAnnotation[] {required});

  IAnnotation description = mock(IAnnotation.class);
  when(description.exists()).thenReturn(true);
  when(method.getAnnotation(PipelineOptionsNamespaces.descriptionAnnotation(version)))
      .thenReturn(description);
  IMemberValuePair memberValuePair = mock(IMemberValuePair.class);
  when(memberValuePair.getValue()).thenReturn(3);
  when(memberValuePair.getValueKind()).thenReturn(IMemberValuePair.K_INT);
  IMemberValuePair[] memberValuePairs = new IMemberValuePair[] {memberValuePair};
  when(description.getMemberValuePairs()).thenReturn(memberValuePairs);

  PipelineOptionsProperty property = PipelineOptionsProperty.fromMethod(method, version);

  assertNull(property.getDescription());
}
项目:google-cloud-eclipse    文件:PipelineOptionsProperty.java   
private static Requirement fromAnnotation(
    IAnnotation requiredAnnotation, MajorVersion majorVersion) {
  if (!requiredAnnotation.exists()) {
    return new Requirement(false, Collections.<String>emptySet());
  }
  IMemberValuePair[] memberValuePairs;
  try {
    memberValuePairs = requiredAnnotation.getMemberValuePairs();
  } catch (JavaModelException e) {
    DataflowCorePlugin.logError(e, "Error while retrieving Member Value Pairs for"
        + " Validation.Required annotation %s in Java Element %s", requiredAnnotation,
        requiredAnnotation.getParent());
    return new Requirement(true, Collections.<String>emptySet());
  }
  for (IMemberValuePair memberValuePair : memberValuePairs) {
    String memberName = memberValuePair.getMemberName();
    Object memberValueObj = memberValuePair.getValue();
    if (memberName.equals(PipelineOptionsNamespaces.validationRequiredGroupField(majorVersion))
        && memberValueObj instanceof Object[]
        && memberValuePair.getValueKind() == IMemberValuePair.K_STRING) {
      Set<String> groups = new HashSet<>();
      for (Object group : (Object[]) memberValueObj) {
        groups.add(group.toString());
      }
      return new Requirement(true, groups);
    }
  }
  return new Requirement(true, Collections.<String>emptySet());
}
项目:junit-tools    文件:TestSuitesGenerator.java   
/**
 * Creates the test suite frame.
 * 
 * @param testSuiteName
 * @param testSuite
 * @param testClasses
 * @param newTestSuiteElementName
 * @param generatedTestSuites
 * @param createNew
 * @return the test-suite
 * @throws JavaModelException
 */
protected IType createTestSuiteFrame(String testSuiteName, ICompilationUnit testSuite,
        ICompilationUnit[] testClasses, String newTestSuiteElementName, HashSet<String> generatedTestSuites,
        boolean createNew) throws JavaModelException {
    IType type = testSuite.getType(testSuiteName);

    String testElementList;

    if (type.exists()) {
        if (!createNew) {
            for (IAnnotation annotation : type.getAnnotations()) {
                if ("Suite.SuiteClasses".equals(annotation.getElementName())) {
                    for (IMemberValuePair memberValuePairs : annotation.getMemberValuePairs()) {
                        Object value = memberValuePairs.getValue();
                        String suiteClassName;

                        if (value instanceof Object[]) {
                            for (Object testSuiteObject : (Object[]) value) {
                                suiteClassName = testSuiteObject.toString();
                                if (suiteClassName.startsWith(TESTSUITE_PREFIX)) {
                                    generatedTestSuites.add(suiteClassName + ".class");
                                }
                                if (suiteClassName.equals(newTestSuiteElementName)) {
                                    return null;
                                }
                            }
                        }
                    }

                }
            }
        }

    }

    testElementList = createCommaSeparatedClassList(testClasses, generatedTestSuites);

    return refreshTestSuiteElements(testSuite, testSuiteName, testElementList);
}
项目:junit-tools    文件:GeneratorUtils.java   
public static MethodRef getMethodRef(IMethod method)
        throws JavaModelException {
    if (method == null) {
        return null;
    }

    IAnnotation annotation = method.getAnnotation("MethodRef");

    if (annotation != null && annotation.exists()) {

        boolean found = false;

        String methodName = "", methodSignature = "";

        for (IMemberValuePair valuePair : annotation.getMemberValuePairs()) {
            String valueName = valuePair.getMemberName();
            String value = valuePair.getValue().toString();

            if ("name".equals(valueName)) {
                methodName = value;
                found = true;
            } else if ("signature".equals(valueName)) {
                methodSignature = value;
            }

        }

        if (found) {
            MethodRef methodRef = new MethodRef(methodName, methodSignature);
            return methodRef;
        }
    }

    return null;
}
项目:junit-tools    文件:GeneratorUtils.java   
public static boolean checkMethodReference(String baseMethodName,
        String baseMethodSignature, IMethod methodToCheck)
        throws JavaModelException {
    IAnnotation anno = methodToCheck.getAnnotation("MethodRef");

    if (anno == null || !anno.exists()) {
        return false;
    }

    IMemberValuePair[] valuePair = anno.getMemberValuePairs();
    boolean signatureFound = false, nameFound = false;

    for (IMemberValuePair vP : valuePair) {
        Object o = vP.getValue();
        if (o != null) {
            String methodRefValue = o.toString();

            if ("signature".equals(vP.getMemberName())) {
                if (methodRefValue.equals(baseMethodSignature)) {
                    signatureFound = true;
                } else {
                    return false;
                }
            } else if ("name".equals(vP.getMemberName())) {
                if (methodRefValue.equals(baseMethodName)) {
                    nameFound = true;
                } else {
                    return false;
                }
            }
        }
    }

    return signatureFound && nameFound;

}
项目:che    文件:Util.java   
public static Object getAnnotationMemberValue(
    MemberValuePair memberValuePair, Constant constant) {
  if (constant == null) {
    memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
    return null;
  }
  switch (constant.typeID()) {
    case TypeIds.T_int:
      memberValuePair.valueKind = IMemberValuePair.K_INT;
      return new Integer(constant.intValue());
    case TypeIds.T_byte:
      memberValuePair.valueKind = IMemberValuePair.K_BYTE;
      return new Byte(constant.byteValue());
    case TypeIds.T_short:
      memberValuePair.valueKind = IMemberValuePair.K_SHORT;
      return new Short(constant.shortValue());
    case TypeIds.T_char:
      memberValuePair.valueKind = IMemberValuePair.K_CHAR;
      return new Character(constant.charValue());
    case TypeIds.T_float:
      memberValuePair.valueKind = IMemberValuePair.K_FLOAT;
      return new Float(constant.floatValue());
    case TypeIds.T_double:
      memberValuePair.valueKind = IMemberValuePair.K_DOUBLE;
      return new Double(constant.doubleValue());
    case TypeIds.T_boolean:
      memberValuePair.valueKind = IMemberValuePair.K_BOOLEAN;
      return Boolean.valueOf(constant.booleanValue());
    case TypeIds.T_long:
      memberValuePair.valueKind = IMemberValuePair.K_LONG;
      return new Long(constant.longValue());
    case TypeIds.T_JavaLangString:
      memberValuePair.valueKind = IMemberValuePair.K_STRING;
      return constant.stringValue();
    default:
      memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
      return null;
  }
}
项目:gwt-eclipse-plugin    文件:ResourceTypeDefaultExtensions.java   
/**
 * Find the default extensions declared directly by this type.
 */
private static String[] getDeclaredDefaultExtensions(IType resourceType)
    throws JavaModelException {
  // Find the @DefaultExtensions annotation
  IAnnotation[] annotations = resourceType.getAnnotations();
  for (IAnnotation annotation : annotations) {
    if (isDefaultExtensionsAnnotation(annotation)) {
      // @DefaultExtensions should have single member-value pair: "value"
      IMemberValuePair[] values = annotation.getMemberValuePairs();
      if (values.length == 1) {
        if (values[0].getMemberName().equals("value")) {
          Object value = values[0].getValue();
          // The extensions will be stored as Object[] of strings
          if (value instanceof Object[]) {
            List<String> extensions = new ArrayList<String>();
            for (Object extension : (Object[]) value) {
              assert (extension instanceof String);
              extensions.add((String) extension);
            }
            return extensions.toArray(new String[0]);
          }
        }
      }
    }
  }
  return new String[0];
}
项目:gwt-eclipse-plugin    文件:PlatformJavaModelUtilities.java   
/**
 * Gets the value of an annotation, if the value is of the given type.
 *
 * @param annotation the IAnnotation from which the value will be returned
 * @param type the type of value expected (if the type does not match this,
 *          null will be returned)
 * @return the value of the annotation, or null
 * @throws JavaModelException
 */
@SuppressWarnings("unchecked")
public static <T> T getSingleMemberAnnotationValue(Object annotation, Class<T> type)
    throws JavaModelException {
  IMemberValuePair[] pairs = ((IAnnotation) annotation).getMemberValuePairs();
  if (pairs.length == 0) {
    return null;
  }

  Object value = pairs[0].getValue();
  return type.isInstance(value) ? (T) value : null;
}
项目:strutsclipse    文件:AnnotationParser.java   
private String fetchAnnotationStringValue(IAnnotation annotation)
        throws JavaModelException {
    if (annotation.exists()) {
        IMemberValuePair[] valuePairs = annotation.getMemberValuePairs();
        for (IMemberValuePair valuePair : valuePairs) {
            if (valuePair.getValueKind() == IMemberValuePair.K_STRING
                    && valuePair.getValue() instanceof String
                    && ANNOTATION_VALUE.equals(valuePair.getMemberName())) {
                return (String) valuePair.getValue();
            }
        }
    }
    return null;
}
项目:txtUML    文件:WizardUtils.java   
/**
 * @return an empty optional if the given type is not annotated, otherwise
 *         the name of the model package and its java project respectively,
 *         which contains the types of the given annotation
 */
public static Optional<Pair<String, String>> getModelByAnnotations(IType annotatedType) {
    try {
        List<String> referencedProjects = new ArrayList<>(
                Arrays.asList(annotatedType.getJavaProject().getRequiredProjectNames()));
        referencedProjects.add(annotatedType.getJavaProject().getElementName());
        for (IAnnotation annot : annotatedType.getAnnotations()) {
            List<Object> annotValues = Stream.of(annot.getMemberValuePairs())
                    .filter(mvp -> mvp.getValueKind() == IMemberValuePair.K_CLASS)
                    .flatMap(mvp -> Stream.of(mvp.getValue())).collect(Collectors.toList());

            for (Object val : annotValues) {
                List<Object> annotations = new ArrayList<>();
                if (val instanceof String) {
                    annotations.add(val);
                } else {
                    annotations.addAll(Arrays.asList((Object[]) val));
                }

                for (Object v : annotations) {
                    String[][] resolvedTypes = resolveType(annotatedType, (String) v);
                    List<String[]> resolvedTypeList = new ArrayList<>(Arrays.asList(resolvedTypes));
                    for (String[] type : resolvedTypeList) {
                        Optional<Pair<String, String>> model = ModelUtils.getModelOf(type[0], referencedProjects);
                        if (model.isPresent()) {
                            return model;
                        }
                    }
                }
            }
        }
    } catch (JavaModelException | NoSuchElementException e) {
    }

    return Optional.empty();
}
项目:Eclipse-Postfix-Code-Completion    文件:StubCreator.java   
private void appendAnnotationValue(Object value, int valueKind) throws JavaModelException {
    if (value instanceof Object[]) {
        Object[] objects= (Object[]) value;
        fBuffer.append('{');
        for (Object object : objects) {
            appendAnnotationValue(object, valueKind);
            fBuffer.append(',');
        }
        if (objects.length > 0)
            fBuffer.deleteCharAt(fBuffer.length() - 1);
        fBuffer.append('}');

    } else {
        switch (valueKind) {
            case IMemberValuePair.K_ANNOTATION:
                appendAnnotation((IAnnotation) value);
                break;
            case IMemberValuePair.K_STRING:
                fBuffer.append('"').append(value).append('"');
                break;

            default:
                fBuffer.append(value);
                break;
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:CompletionUnitStructureRequestor.java   
protected IMemberValuePair[] getMemberValuePairs(MemberValuePair[] memberValuePairs) {
    int membersLength = memberValuePairs.length;
    int membersCount = 0;
    IMemberValuePair[] members = new IMemberValuePair[membersLength];
    next : for (int j = 0; j < membersLength; j++) {
        if (memberValuePairs[j] instanceof CompletionOnMemberValueName) continue next;

        members[membersCount++] = getMemberValuePair(memberValuePairs[j]);
    }

    if (membersCount > membersLength) {
        System.arraycopy(members, 0, members, 0, membersCount);
    }
    return members;
}
项目:Eclipse-Postfix-Code-Completion    文件:CompilationUnitStructureRequestor.java   
protected IMemberValuePair[] getMemberValuePairs(MemberValuePair[] memberValuePairs) {
    int membersLength = memberValuePairs.length;
    IMemberValuePair[] members = new IMemberValuePair[membersLength];
    for (int j = 0; j < membersLength; j++) {
        members[j] = getMemberValuePair(memberValuePairs[j]);
    }
    return members;
}
项目:Eclipse-Postfix-Code-Completion    文件:Annotation.java   
public IMemberValuePair[] getMemberValuePairs() throws JavaModelException {
    Object info = getElementInfo();
    if (info instanceof AnnotationInfo)
        return ((AnnotationInfo) info).members;
    IBinaryElementValuePair[] binaryAnnotations = ((IBinaryAnnotation) info).getElementValuePairs();
    int length = binaryAnnotations.length;
    IMemberValuePair[] result = new IMemberValuePair[length];
    for (int i = 0; i < length; i++) {
        IBinaryElementValuePair binaryAnnotation = binaryAnnotations[i];
        MemberValuePair memberValuePair = new MemberValuePair(new String(binaryAnnotation.getName()));
        memberValuePair.value = Util.getAnnotationMemberValue(this, memberValuePair, binaryAnnotation.getValue());
        result[i] = memberValuePair;
    }
    return result;
}