use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-eclipse by eclipse.
the class StratumBreakpointAdapterFactory method getClassNamePattern.
protected String getClassNamePattern(XtextResource state) {
TreeIterator<Object> contents = EcoreUtil.getAllContents(state, false);
StringBuilder sb = new StringBuilder();
while (contents.hasNext()) {
Object next = contents.next();
if (next instanceof JvmDeclaredType) {
JvmDeclaredType type = (JvmDeclaredType) next;
sb.append(type.getQualifiedName()).append("*");
sb.append(",");
}
}
if (sb.length() == 0)
return null;
else
return sb.substring(0, sb.length() - 1);
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-eclipse by eclipse.
the class JdtTypeProvider method findTypeBySignature.
private JvmType findTypeBySignature(String signature, TypeResource resource, boolean traverseNestedTypes) {
// TODO: Maybe iterate the resource without computing a fragment
String fragment = typeUriHelper.getFragment(signature);
JvmType result = (JvmType) resource.getEObject(fragment);
if (result != null || !traverseNestedTypes)
return result;
List<EObject> contents = resource.getContents();
if (contents.isEmpty()) {
return null;
}
String rootTypeName = resource.getURI().segment(1);
String nestedTypeName = fragment.substring(rootTypeName.length() + 1);
List<String> segments = Strings.split(nestedTypeName, "$");
EObject rootType = contents.get(0);
if (rootType instanceof JvmDeclaredType) {
result = findNestedType((JvmDeclaredType) rootType, segments, 0);
}
return result;
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-eclipse by eclipse.
the class JvmMemberRenameStrategy method setName.
protected JvmMember setName(URI targetURI, ResourceSet resourceSet, final String newName) {
final JvmMember member = (JvmMember) resourceSet.getEObject(targetURI, true);
// clear all cached identifiers of contained members
for (JvmMember containedMember : EcoreUtil2.eAllOfType(member, JvmMember.class)) containedMember.internalSetIdentifier(null);
member.setSimpleName(newName);
if (member instanceof JvmDeclaredType && ((InternalEObject) member).eDirectResource() != null) {
Resource typeResource = member.eResource();
if (typeResource instanceof TypeResource) {
// rename the resource
String originalURI = typeResource.getURI().toString();
int lastIndexOf = Math.max(originalURI.lastIndexOf('.'), originalURI.lastIndexOf('/')) + 1;
URI typeResourceNewURI = URI.createURI(originalURI.substring(0, lastIndexOf) + newName);
typeResource.setURI(typeResourceNewURI);
// disconnect the mirrored IJavaElement as it is invalid now
((TypeResource) typeResource).setMirror(new AbstractClassMirror() {
@Override
public boolean isSealed() {
return false;
}
@Override
public void initialize(TypeResource typeResource) {
}
@Override
protected String getTypeName() {
return member.getIdentifier();
}
});
}
}
return member;
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-eclipse by eclipse.
the class JdtBasedTypeFactory method createType.
/**
* @since 2.4
*/
protected JvmDeclaredType createType(ITypeBinding typeBinding, String handleIdentifier, List<String> path, StringBuilder fqn) {
if (typeBinding.isAnonymous() || typeBinding.isSynthetic())
throw new IllegalStateException("Cannot create type for anonymous or synthetic classes");
// Creates the right type of instance based on the type of binding.
//
JvmGenericType jvmGenericType;
JvmDeclaredType result;
if (typeBinding.isAnnotation()) {
jvmGenericType = null;
result = TypesFactory.eINSTANCE.createJvmAnnotationType();
} else if (typeBinding.isEnum()) {
jvmGenericType = null;
result = TypesFactory.eINSTANCE.createJvmEnumerationType();
} else {
result = jvmGenericType = TypesFactory.eINSTANCE.createJvmGenericType();
jvmGenericType.setInterface(typeBinding.isInterface());
}
// Populate the information computed from the modifiers.
//
int modifiers = typeBinding.getModifiers();
setTypeModifiers(result, modifiers);
result.setDeprecated(typeBinding.isDeprecated());
setVisibility(result, modifiers);
// Determine the simple name and compose the fully qualified name and path, remembering the fqn length and path size so we can reset them.
//
String simpleName = typeBinding.getName();
fqn.append(simpleName);
int length = fqn.length();
int size = path.size();
path.add(simpleName);
String qualifiedName = fqn.toString();
result.internalSetIdentifier(qualifiedName);
result.setSimpleName(simpleName);
// Traverse the nested types using '$' as the qualified name separator.
//
fqn.append('$');
createNestedTypes(typeBinding, result, handleIdentifier, path, fqn);
// Traverse the methods using '.'as the qualifed name separator.
//
fqn.setLength(length);
fqn.append('.');
createMethods(typeBinding, handleIdentifier, path, fqn, result);
createFields(typeBinding, fqn, result);
// Set the super types.
//
setSuperTypes(typeBinding, qualifiedName, result);
//
if (jvmGenericType != null) {
ITypeBinding[] typeParameterBindings = typeBinding.getTypeParameters();
if (typeParameterBindings.length > 0) {
InternalEList<JvmTypeParameter> typeParameters = (InternalEList<JvmTypeParameter>) jvmGenericType.getTypeParameters();
for (ITypeBinding variable : typeParameterBindings) {
typeParameters.addUnique(createTypeParameter(variable, result));
}
}
}
// Populate the annotation values.
//
createAnnotationValues(typeBinding, result);
// Restore the path.
//
path.remove(size);
return result;
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-eclipse by eclipse.
the class JdtBasedTypeFactory method createType.
/**
* @since 2.7
*/
protected JvmDeclaredType createType(IType jdtType, IJavaProject javaProject) {
if (jdtType.getDeclaringType() != null)
throw new IllegalArgumentException("Cannot create type from non-toplevel-type: '" + jdtType.getFullyQualifiedName() + "'.");
IBinding binding = null;
IllegalArgumentException cause = null;
try {
binding = resolveBindings(jdtType, javaProject);
} catch (IllegalArgumentException e) {
// might be caused by missing source content in ASTNode#setSourceRange
cause = e;
}
if (binding == null) {
IJavaProject fallbackProject = jdtType.getJavaProject();
// fallback to the project of the given jdtType if it is different from the explicitly given project
if (!fallbackProject.equals(javaProject)) {
try {
binding = resolveBindings(jdtType, fallbackProject);
} catch (IllegalArgumentException e) {
cause = e;
}
if (binding == null) {
throw new IllegalStateException("Could not create binding for '" + jdtType.getFullyQualifiedName() + "' in context of projects '" + javaProject.getElementName() + "' and '" + fallbackProject.getElementName() + "'.", cause);
}
} else {
throw new IllegalStateException("Could not create binding for '" + jdtType.getFullyQualifiedName() + "' in context of project '" + javaProject.getElementName() + "'.");
}
}
if (binding instanceof ITypeBinding) {
createType.start();
ITypeBinding typeBinding = (ITypeBinding) binding;
setMayTolerateMissingType(typeBinding);
JvmDeclaredType result = createType(jdtType, typeBinding);
// Clear the cached information.
//
clearCache();
createType.stop();
return result;
} else {
throw new IllegalStateException("Expected ITypeBinding for '" + jdtType.getFullyQualifiedName() + "', but got '" + binding.toString() + "'.");
}
}
Aggregations