org.eclipse.jdt.core.IMemberValuePair Java Examples
The following examples show how to use
org.eclipse.jdt.core.IMemberValuePair.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaElementLabelComposer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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(')'); }
Example #2
Source File: JDTUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private static boolean isSilencedGeneratedAnnotation(IAnnotation annotation) throws JavaModelException { if ("javax.annotation.Generated".equals(annotation.getElementName()) || "javax.annotation.processing.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; }
Example #3
Source File: JavaElementLabelComposer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
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(')'); }
Example #4
Source File: StubCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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'); }
Example #5
Source File: PipelineOptionsPropertyTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@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()); }
Example #6
Source File: BinaryMethod.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public IMemberValuePair getDefaultValue() throws JavaModelException { IBinaryMethod info = (IBinaryMethod) getElementInfo(); Object defaultValue = info.getDefaultValue(); if (defaultValue == null) return null; MemberValuePair memberValuePair = new MemberValuePair(getElementName()); memberValuePair.value = Util.getAnnotationMemberValue(this, memberValuePair, defaultValue); return memberValuePair; }
Example #7
Source File: Annotation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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; }
Example #8
Source File: CompilationUnitStructureRequestor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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; }
Example #9
Source File: CompletionUnitStructureRequestor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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; }
Example #10
Source File: StubCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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; } } }
Example #11
Source File: WizardUtils.java From txtUML with Eclipse Public License 1.0 | 5 votes |
/** * @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()); if (annotValues.isEmpty()) { throw new NoSuchElementException("Group is empty."); } 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 e) { } return Optional.empty(); }
Example #12
Source File: PlatformJavaModelUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * 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; }
Example #13
Source File: ResourceTypeDefaultExtensions.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * 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]; }
Example #14
Source File: PipelineOptionsProperty.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
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()); }
Example #15
Source File: PipelineOptionsPropertyTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@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()); }
Example #16
Source File: PipelineOptionsPropertyTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@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()); }
Example #17
Source File: PipelineOptionsPropertyTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@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()); }
Example #18
Source File: PipelineOptionsPropertyTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@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)); }
Example #19
Source File: JavaElementLabelComposer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public void appendAnnotationValue(IAnnotation annotation, Object value, int valueKind, long flags) throws JavaModelException { // Note: To be bug-compatible with Javadoc from Java 5/6/7, we currently don't escape HTML tags in String-valued annotations. if (value instanceof Object[]) { fBuilder.append('{'); Object[] values= (Object[]) value; for (int j= 0; j < values.length; j++) { if (j > 0) { fBuilder.append(JavaElementLabels.COMMA_STRING); } value= values[j]; appendAnnotationValue(annotation, value, valueKind, flags); } fBuilder.append('}'); } else { switch (valueKind) { case IMemberValuePair.K_CLASS: appendTypeSignatureLabel(annotation, Signature.createTypeSignature((String) value, false), flags); fBuilder.append(".class"); //$NON-NLS-1$ break; case IMemberValuePair.K_QUALIFIED_NAME: String name = (String) value; int lastDot= name.lastIndexOf('.'); if (lastDot != -1) { String type= name.substring(0, lastDot); String field= name.substring(lastDot + 1); appendTypeSignatureLabel(annotation, Signature.createTypeSignature(type, false), flags); fBuilder.append('.'); fBuilder.append(getMemberName(annotation, type, field)); break; } // case IMemberValuePair.K_SIMPLE_NAME: // can't implement, since parent type is not known //$FALL-THROUGH$ case IMemberValuePair.K_ANNOTATION: appendAnnotationLabel((IAnnotation) value, flags); break; case IMemberValuePair.K_STRING: fBuilder.append(ASTNodes.getEscapedStringLiteral((String) value)); break; case IMemberValuePair.K_CHAR: fBuilder.append(ASTNodes.getEscapedCharacterLiteral(((Character) value).charValue())); break; default: fBuilder.append(String.valueOf(value)); break; } } }
Example #20
Source File: JavaElementLabelComposer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void appendAnnotationValue(IAnnotation annotation, Object value, int valueKind, long flags) throws JavaModelException { // Note: To be bug-compatible with Javadoc from Java 5/6/7, we currently don't escape HTML tags in String-valued annotations. if (value instanceof Object[]) { fBuffer.append('{'); Object[] values= (Object[]) value; for (int j= 0; j < values.length; j++) { if (j > 0) fBuffer.append(JavaElementLabels.COMMA_STRING); value= values[j]; appendAnnotationValue(annotation, value, valueKind, flags); } fBuffer.append('}'); } else { switch (valueKind) { case IMemberValuePair.K_CLASS: appendTypeSignatureLabel(annotation, Signature.createTypeSignature((String) value, false), flags); fBuffer.append(".class"); //$NON-NLS-1$ break; case IMemberValuePair.K_QUALIFIED_NAME: String name = (String) value; int lastDot= name.lastIndexOf('.'); if (lastDot != -1) { String type= name.substring(0, lastDot); String field= name.substring(lastDot + 1); appendTypeSignatureLabel(annotation, Signature.createTypeSignature(type, false), flags); fBuffer.append('.'); fBuffer.append(getMemberName(annotation, type, field)); break; } // case IMemberValuePair.K_SIMPLE_NAME: // can't implement, since parent type is not known //$FALL-THROUGH$ case IMemberValuePair.K_ANNOTATION: appendAnnotationLabel((IAnnotation) value, flags); break; case IMemberValuePair.K_STRING: fBuffer.append(ASTNodes.getEscapedStringLiteral((String) value)); break; case IMemberValuePair.K_CHAR: fBuffer.append(ASTNodes.getEscapedCharacterLiteral(((Character) value).charValue())); break; default: fBuffer.append(String.valueOf(value)); break; } } }
Example #21
Source File: CompilationUnitStructureRequestor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
protected IMemberValuePair getMemberValuePair(MemberValuePair memberValuePair) { String memberName = new String(memberValuePair.name); org.eclipse.jdt.internal.core.MemberValuePair result = new org.eclipse.jdt.internal.core.MemberValuePair(memberName); result.value = getMemberValue(result, memberValuePair.value); return result; }
Example #22
Source File: CompilationUnitStructureRequestor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
protected Object getMemberValue(org.eclipse.jdt.internal.core.MemberValuePair memberValuePair, Expression expression) { if (expression instanceof NullLiteral) { return null; } else if (expression instanceof Literal) { ((Literal) expression).computeConstant(); return Util.getAnnotationMemberValue(memberValuePair, expression.constant); } else if (expression instanceof org.eclipse.jdt.internal.compiler.ast.Annotation) { org.eclipse.jdt.internal.compiler.ast.Annotation annotation = (org.eclipse.jdt.internal.compiler.ast.Annotation) expression; Object handle = acceptAnnotation(annotation, null, (JavaElement) this.handleStack.peek()); memberValuePair.valueKind = IMemberValuePair.K_ANNOTATION; return handle; } else if (expression instanceof ClassLiteralAccess) { ClassLiteralAccess classLiteral = (ClassLiteralAccess) expression; char[] name = CharOperation.concatWith(classLiteral.type.getTypeName(), '.'); memberValuePair.valueKind = IMemberValuePair.K_CLASS; return new String(name); } else if (expression instanceof QualifiedNameReference) { char[] qualifiedName = CharOperation.concatWith(((QualifiedNameReference) expression).tokens, '.'); memberValuePair.valueKind = IMemberValuePair.K_QUALIFIED_NAME; return new String(qualifiedName); } else if (expression instanceof SingleNameReference) { char[] simpleName = ((SingleNameReference) expression).token; if (simpleName == RecoveryScanner.FAKE_IDENTIFIER) { memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN; return null; } memberValuePair.valueKind = IMemberValuePair.K_SIMPLE_NAME; return new String(simpleName); } else if (expression instanceof ArrayInitializer) { memberValuePair.valueKind = -1; // modified below by the first call to getMemberValue(...) Expression[] expressions = ((ArrayInitializer) expression).expressions; int length = expressions == null ? 0 : expressions.length; Object[] values = new Object[length]; for (int i = 0; i < length; i++) { int previousValueKind = memberValuePair.valueKind; Object value = getMemberValue(memberValuePair, expressions[i]); if (previousValueKind != -1 && memberValuePair.valueKind != previousValueKind) { // values are heterogeneous, value kind is thus unknown memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN; } values[i] = value; } if (memberValuePair.valueKind == -1) memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN; return values; } else if (expression instanceof UnaryExpression) { // to deal with negative numerals (see bug - 248312) UnaryExpression unaryExpression = (UnaryExpression) expression; if ((unaryExpression.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT == OperatorIds.MINUS) { if (unaryExpression.expression instanceof Literal) { Literal subExpression = (Literal) unaryExpression.expression; subExpression.computeConstant(); return Util.getNegativeAnnotationMemberValue(memberValuePair, subExpression.constant); } } memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN; return null; } else { memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN; return null; } }
Example #23
Source File: MockMethod.java From jdt-codemining with Eclipse Public License 1.0 | 4 votes |
@Override public IMemberValuePair getDefaultValue() throws JavaModelException { // TODO Auto-generated method stub return null; }
Example #24
Source File: GroovyFieldAccessorMethod.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public IMemberValuePair getDefaultValue() throws JavaModelException { return null; }