use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-eclipse by eclipse.
the class SourceBasedJdtTypeProviderTest method testClassAnnotationValue_08.
@Test
public void testClassAnnotationValue_08() throws Exception {
IJavaProject project = projectProvider.getJavaProject(null);
String typeName = EmptyAbstractClass.class.getName();
IFile javaFile = (IFile) project.getProject().findMember(new Path("src/" + typeName.replace('.', '/') + ".java"));
assertNotNull(javaFile);
String content = Files.readStreamIntoString(javaFile.getContents());
try {
String newContent = content.replace("public abstract ", "@TestAnnotation( classArray = { String.class, DoesNotExist.class, String.class } ) public abstract ");
javaFile.setContents(new StringInputStream(newContent), IResource.NONE, new NullProgressMonitor());
JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
List<JvmAnnotationReference> annotations = type.getAnnotations();
assertEquals(1, annotations.size());
JvmAnnotationReference annotation = annotations.get(0);
assertEquals(1, annotation.getExplicitValues().size());
JvmAnnotationValue value = annotation.getExplicitValues().get(0);
assertTrue(value instanceof JvmTypeAnnotationValue);
List<JvmTypeReference> typeLiterals = ((JvmTypeAnnotationValue) value).getValues();
assertEquals(2, typeLiterals.size());
} finally {
javaFile.setContents(new StringInputStream(content), IResource.NONE, new NullProgressMonitor());
}
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-eclipse by eclipse.
the class AbstractTypeProviderPerformanceTest method testLoadTypesAndResolveAllParameterNames.
@Test
public void testLoadTypesAndResolveAllParameterNames() throws Exception {
for (String name : getClassNamesToLoad()) {
JvmDeclaredType type = loadAndResolve(name, true, true, true, true, true);
TreeIterator<Object> iterator = EcoreUtil.getAllContents(type.eResource().getResourceSet(), true);
while (iterator.hasNext()) {
Object next = iterator.next();
if (next instanceof JvmFormalParameter) {
((JvmFormalParameter) next).getName();
}
}
}
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-eclipse by eclipse.
the class AbstractTypeProviderPerformanceTest method loadAndResolve.
protected JvmDeclaredType loadAndResolve(String name, boolean accessMembers, boolean accessAnnotations, boolean accessTypeParams, boolean accessParameter, boolean accessParameterNames) {
JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(name);
EcoreUtil.resolveAll(type.eResource());
EcoreUtil.resolveAll(type.eResource().getResourceSet());
Assert.assertNotNull(name, type);
if (accessAnnotations) {
type.getAnnotations();
}
if (accessMembers) {
EList<JvmMember> members = type.getMembers();
for (JvmMember member : members) {
if (accessAnnotations) {
member.getAnnotations();
}
if (member instanceof JvmExecutable) {
JvmExecutable operation = (JvmExecutable) member;
if (accessParameter) {
EList<JvmFormalParameter> parameters = operation.getParameters();
for (JvmFormalParameter jvmFormalParameter : parameters) {
if (accessAnnotations) {
jvmFormalParameter.getAnnotations();
}
if (accessParameterNames) {
jvmFormalParameter.getName();
}
}
}
}
}
}
return type;
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-eclipse by eclipse.
the class XbaseReferenceUpdater method resolveNameConflict.
@Override
protected String resolveNameConflict(EObject referringElement, EReference reference, EObject newTargetElement, IRefactoringUpdateAcceptor updateAcceptor) {
if (EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_IDENTIFIABLE_ELEMENT, reference.getEReferenceType())) {
if (newTargetElement instanceof JvmType) {
JvmType type = (JvmType) newTargetElement;
if (canLinkJvmType(referringElement, type)) {
return toString(qualifiedNameProvider.getFullyQualifiedName(type));
}
}
if (newTargetElement instanceof JvmFeature) {
JvmFeature feature = (JvmFeature) newTargetElement;
if (feature.isStatic() && !isStaticExtensionFeatureCall(referringElement, reference, newTargetElement)) {
JvmDeclaredType declaringType = feature.getDeclaringType();
if (canLinkJvmType(referringElement, declaringType)) {
JvmDeclaredType parentType = declaringType;
List<String> segments = new LinkedList<String>();
segments.add(feature.getSimpleName());
segments.add(0, parentType.getSimpleName());
while (!hasImportedType(updateAcceptor, parentType)) {
parentType = parentType.getDeclaringType();
if (parentType == null) {
return toString(qualifiedNameProvider.getFullyQualifiedName(feature));
}
segments.add(0, parentType.getSimpleName());
}
return toString(QualifiedName.create(segments));
}
}
}
}
return super.resolveNameConflict(referringElement, reference, newTargetElement, updateAcceptor);
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-eclipse by eclipse.
the class XbaseReferenceUpdater method getImportedTypeAndRelativeName.
/**
* @return the currently imported type containing the newTargetType and the element's name relative to that import.
*/
protected Pair<JvmDeclaredType, QualifiedName> getImportedTypeAndRelativeName(JvmType newTargetType, RewritableImportSection section) {
if (!(newTargetType instanceof JvmDeclaredType) || !section.isEnabled()) {
return null;
}
JvmDeclaredType importedType = (JvmDeclaredType) newTargetType;
StringBuffer relativeName = new StringBuffer(importedType.getSimpleName());
while (importedType.getDeclaringType() != null && !section.hasImportedType(importedType)) {
importedType = importedType.getDeclaringType();
relativeName.insert(0, ".");
relativeName.insert(0, importedType.getSimpleName());
}
return Tuples.create(importedType, qualifiedNameConverter.toQualifiedName(relativeName.toString()));
}
Aggregations