use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class CompilationUnitImpl method toXtendMemberDeclaration.
public MemberDeclaration toXtendMemberDeclaration(final XtendMember delegate) {
final Function1<XtendMember, XtendMemberDeclarationImpl<? extends XtendMember>> _function = (XtendMember it) -> {
XtendMemberDeclarationImpl<? extends XtendMember> _switchResult = null;
boolean _matched = false;
if (delegate instanceof XtendTypeDeclaration) {
_matched = true;
_switchResult = this.toXtendTypeDeclaration(((XtendTypeDeclaration) delegate));
}
if (!_matched) {
if (delegate instanceof XtendFunction) {
_matched = true;
XtendMethodDeclarationImpl _xtendMethodDeclarationImpl = new XtendMethodDeclarationImpl();
final Procedure1<XtendMethodDeclarationImpl> _function_1 = (XtendMethodDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendFunction) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<XtendMethodDeclarationImpl>operator_doubleArrow(_xtendMethodDeclarationImpl, _function_1);
}
}
if (!_matched) {
if (delegate instanceof XtendConstructor) {
_matched = true;
XtendConstructorDeclarationImpl _xtendConstructorDeclarationImpl = new XtendConstructorDeclarationImpl();
final Procedure1<XtendConstructorDeclarationImpl> _function_1 = (XtendConstructorDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendConstructor) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<XtendConstructorDeclarationImpl>operator_doubleArrow(_xtendConstructorDeclarationImpl, _function_1);
}
}
if (!_matched) {
if (delegate instanceof XtendField) {
_matched = true;
XtendMemberDeclarationImpl<XtendField> _xifexpression = null;
EObject _eContainer = ((XtendField) delegate).eContainer();
if ((_eContainer instanceof XtendAnnotationType)) {
XtendAnnotationTypeElementDeclarationImpl _xtendAnnotationTypeElementDeclarationImpl = new XtendAnnotationTypeElementDeclarationImpl();
final Procedure1<XtendAnnotationTypeElementDeclarationImpl> _function_1 = (XtendAnnotationTypeElementDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendField) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<XtendAnnotationTypeElementDeclarationImpl>operator_doubleArrow(_xtendAnnotationTypeElementDeclarationImpl, _function_1);
} else {
XtendFieldDeclarationImpl _xtendFieldDeclarationImpl = new XtendFieldDeclarationImpl();
final Procedure1<XtendFieldDeclarationImpl> _function_2 = (XtendFieldDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendField) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<XtendFieldDeclarationImpl>operator_doubleArrow(_xtendFieldDeclarationImpl, _function_2);
}
_switchResult = _xifexpression;
}
}
if (!_matched) {
if (delegate instanceof XtendEnumLiteral) {
_matched = true;
XtendEnumerationValueDeclarationImpl _xtendEnumerationValueDeclarationImpl = new XtendEnumerationValueDeclarationImpl();
final Procedure1<XtendEnumerationValueDeclarationImpl> _function_1 = (XtendEnumerationValueDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendEnumLiteral) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<XtendEnumerationValueDeclarationImpl>operator_doubleArrow(_xtendEnumerationValueDeclarationImpl, _function_1);
}
}
return _switchResult;
};
return this.<XtendMember, XtendMemberDeclarationImpl<? extends XtendMember>>getOrCreate(delegate, _function);
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class AbstractMultiModeOutlineTreeProvider method computeDecoratedText.
protected Object computeDecoratedText(final Object modelElement, final int inheritanceDepth) {
Object supertext = super.getText(modelElement);
if (!(supertext instanceof StyledString)) {
return supertext;
}
StyledString styledText = (StyledString) supertext;
if (inheritanceDepth > 0) {
styledText = applyStylerToFirstSegment(styledText, ColoringLabelProvider.INHERITED_STYLER);
}
if (modelElement instanceof JvmIdentifiableElement) {
JvmIdentifiableElement jvmElement = (JvmIdentifiableElement) modelElement;
if (!getAssociations().getSourceElements(jvmElement).isEmpty() && !getAssociations().isPrimaryJvmElement(jvmElement)) {
styledText = applyStylerToFirstSegment(styledText, StyledString.QUALIFIER_STYLER);
}
}
if (isShowInherited()) {
if (modelElement instanceof IResolvedFeature) {
String qualifier = createQualifier((IResolvedFeature) modelElement);
appendQualifier(styledText, qualifier);
} else if (modelElement instanceof JvmMember) {
String qualifier = createQualifier((JvmMember) modelElement);
appendQualifier(styledText, qualifier);
} else if (modelElement instanceof XtendMember) {
XtendMember xtendMember = (XtendMember) modelElement;
if (xtendMember.eContainer() instanceof XtendTypeDeclaration) {
String qualifiedName = createQualifier((XtendTypeDeclaration) xtendMember.eContainer(), '.');
appendQualifier(styledText, qualifiedName);
} else if (xtendMember instanceof XtendTypeDeclaration) {
XtendFile xtendFile = EcoreUtil2.getContainerOfType(xtendMember, XtendFile.class);
String qualifiedName = xtendFile.getPackage() == null ? "(default package)" : xtendFile.getPackage();
appendQualifier(styledText, qualifiedName);
}
}
}
return styledText;
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class AbstractMultiModeOutlineTreeProvider method createQualifier.
private String createQualifier(XtendTypeDeclaration xtendType, char innerClassDelimiter) {
if (xtendType.getName() == null)
return null;
XtendTypeDeclaration declaringType = null;
if (xtendType.eContainer() instanceof XtendTypeDeclaration) {
declaringType = (XtendTypeDeclaration) xtendType.eContainer();
}
if (declaringType == null) {
return xtendType.getName();
}
String qualifier = xtendType.getName();
while (xtendType.eContainer() instanceof XtendTypeDeclaration) {
XtendTypeDeclaration parent = (XtendTypeDeclaration) xtendType.eContainer();
qualifier = parent.getName() + innerClassDelimiter + qualifier;
xtendType = parent;
}
return qualifier;
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class XtendJavaElementDelegateJunitLaunch method getXtendClass.
/**
* @param resource the Xtext resource to parse
* @return if the resource contains exactly one class, returns the IJavaElement associated with that class,
* otherwise returns null
*/
private IJavaElement getXtendClass(XtextResource resource) {
IParseResult parseResult = resource.getParseResult();
if (parseResult == null) {
return null;
}
EObject root = parseResult.getRootASTElement();
if (root instanceof XtendFile) {
XtendFile xtendFile = (XtendFile) root;
EList<XtendTypeDeclaration> xtendTypes = xtendFile.getXtendTypes();
if (xtendTypes.size() == 1) {
XtendTypeDeclaration element = xtendTypes.get(0);
JvmIdentifiableElement jvmElement = findAssociatedJvmElement(element);
if (jvmElement == null) {
return null;
}
IJavaElement javaElement = elementFinder.findElementFor(jvmElement);
return javaElement;
}
}
return null;
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class XtendFileRenameParticipant method createRenameElementContexts.
@Override
protected List<? extends IRenameElementContext> createRenameElementContexts(Object element) {
if (super.getNewName().endsWith(".xtend")) {
IFile file = (IFile) element;
final IPath filePath = file.getFullPath();
final IPath newPath = file.getFullPath().removeLastSegments(1).append(getNewName() + ".xtend");
String className = trimFileExtension(file.getName());
if (className != null) {
ResourceSet resourceSet = resourceSetProvider.get(file.getProject());
URI resourceURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
Resource resource = resourceSet.getResource(resourceURI, true);
if (resource != null && !resource.getContents().isEmpty()) {
for (XtendTypeDeclaration type : EcoreUtil2.eAllOfType(resource.getContents().get(0), XtendTypeDeclaration.class)) {
if (equal(className, type.getName())) {
IRenameElementContext renameElementContext = renameContextFactory.createRenameElementContext(type, null, null, (XtextResource) resource);
if (renameElementContext instanceof IChangeRedirector.Aware)
((IChangeRedirector.Aware) renameElementContext).setChangeRedirector(new IChangeRedirector() {
@Override
public IPath getRedirectedPath(IPath source) {
return source.equals(filePath) ? newPath : source;
}
});
return singletonList(renameElementContext);
}
}
}
}
}
return super.createRenameElementContexts(element);
}
Aggregations