use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class DispatchHelper method getAllDispatchCases.
/**
* Return all the cases that are associated with the given dispatch operation.
*/
public List<JvmOperation> getAllDispatchCases(JvmOperation dispatcherOperation) {
DispatchSignature dispatchSignature = new DispatchSignature(dispatcherOperation.getSimpleName(), dispatcherOperation.getParameters().size());
JvmDeclaredType type = dispatcherOperation.getDeclaringType();
ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, type);
ContextualVisibilityHelper contextualVisibilityHelper = new ContextualVisibilityHelper(visibilityHelper, owner.newParameterizedTypeReference(type));
return getAllDispatchMethods(dispatchSignature, type, contextualVisibilityHelper);
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method infer.
@Override
public void infer(/* @Nullable */
EObject object, final /* @NonNull */
IJvmDeclaredTypeAcceptor acceptor, boolean preIndexingPhase) {
if (!(object instanceof XtendFile))
return;
final Set<JvmDeclaredType> types = new LinkedHashSet<JvmDeclaredType>();
final IJvmDeclaredTypeAcceptor wrapper = new IJvmDeclaredTypeAcceptor() {
@SuppressWarnings("deprecation")
@Override
public <T extends JvmDeclaredType> IPostIndexingInitializing<T> accept(T type) {
types.add(type);
return acceptor.accept(type);
}
@Override
public <T extends JvmDeclaredType> void accept(T type, Procedure1<? super T> lateInitialization) {
types.add(type);
acceptor.accept(type, lateInitialization);
}
};
final XtendFile xtendFile = (XtendFile) object;
generatorConfig = generatorConfigProvider.get(xtendFile);
final List<Runnable> doLater = newArrayList();
for (final XtendTypeDeclaration declaration : xtendFile.getXtendTypes()) {
inferTypeSceleton(declaration, wrapper, preIndexingPhase, xtendFile, doLater, null);
}
ActiveAnnotationContexts contexts = null;
BatchLinkableResource resource = (BatchLinkableResource) xtendFile.eResource();
try {
compilerPhases.setIndexing(xtendFile, true);
try {
contexts = contextProvider.computeContext(xtendFile);
} catch (Throwable t) {
operationCanceledManager.propagateAsErrorIfCancelException(t);
logger.error("Couldn't create annotation contexts", t);
return;
}
try {
contexts.before(ActiveAnnotationContexts.AnnotationCallback.INDEXING);
for (ActiveAnnotationContext ctx : contexts.getContexts().values()) {
try {
annotationProcessor.indexingPhase(ctx, wrapper, CancelIndicator.NullImpl);
} catch (Throwable t) {
operationCanceledManager.propagateAsErrorIfCancelException(t);
ctx.handleProcessingError(xtendFile.eResource(), t);
}
}
} finally {
contexts.after(ActiveAnnotationContexts.AnnotationCallback.INDEXING);
}
} finally {
compilerPhases.setIndexing(xtendFile, false);
resource.getCache().clear(resource);
}
if (!preIndexingPhase) {
final ActiveAnnotationContexts finalContexts = contexts;
Runnable lateInit = new Runnable() {
@Override
public void run() {
for (Runnable runnable : doLater) {
runnable.run();
}
try {
finalContexts.before(ActiveAnnotationContexts.AnnotationCallback.INFERENCE);
for (ActiveAnnotationContext ctx : finalContexts.getContexts().values()) {
try {
annotationProcessor.inferencePhase(ctx, CancelIndicator.NullImpl);
} catch (Throwable t) {
operationCanceledManager.propagateAsErrorIfCancelException(t);
ctx.handleProcessingError(xtendFile.eResource(), t);
}
}
} finally {
finalContexts.after(ActiveAnnotationContexts.AnnotationCallback.INFERENCE);
}
}
};
resource.addJvmMemberInitializer(lateInit);
}
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method initialize.
protected void initialize(XtendClass source, JvmGenericType inferredJvmType) {
inferredJvmType.setVisibility(source.getVisibility());
boolean isStatic = source.isStatic() && !isTopLevel(source);
if (!isStatic) {
JvmDeclaredType declaringType = inferredJvmType.getDeclaringType();
if (declaringType instanceof JvmGenericType) {
if (((JvmGenericType) declaringType).isInterface())
isStatic = true;
} else if (declaringType instanceof JvmAnnotationType) {
isStatic = true;
}
}
inferredJvmType.setStatic(isStatic);
inferredJvmType.setAbstract(source.isAbstract());
inferredJvmType.setStrictFloatingPoint(source.isStrictFloatingPoint());
if (!inferredJvmType.isAbstract()) {
inferredJvmType.setFinal(source.isFinal());
}
translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
JvmTypeReference extendsClause = source.getExtends();
if (extendsClause == null || extendsClause.getType() == null) {
JvmTypeReference typeRefToObject = typeReferences.getTypeForName(Object.class, source);
if (typeRefToObject != null)
inferredJvmType.getSuperTypes().add(typeRefToObject);
} else {
inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(extendsClause));
}
for (JvmTypeReference intf : source.getImplements()) {
inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(intf));
}
fixTypeParameters(inferredJvmType);
addDefaultConstructor(source, inferredJvmType);
for (XtendMember member : source.getMembers()) {
if (member instanceof XtendField || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null) || member instanceof XtendConstructor) {
transform(member, inferredJvmType, true);
}
}
appendSyntheticDispatchMethods(source, inferredJvmType);
jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
nameClashResolver.resolveNameClashes(inferredJvmType);
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method inferTypeSceleton.
protected void inferTypeSceleton(final XtendTypeDeclaration declaration, final IJvmDeclaredTypeAcceptor acceptor, boolean preIndexingPhase, XtendFile xtendFile, List<Runnable> doLater, JvmDeclaredType containerSceleton) {
JvmDeclaredType inferredSceleton = doInferTypeSceleton(declaration, acceptor, preIndexingPhase, xtendFile, doLater);
if (inferredSceleton != null) {
setNameAndAssociate(xtendFile, declaration, inferredSceleton);
if (containerSceleton != null)
containerSceleton.getMembers().add(inferredSceleton);
acceptor.accept(inferredSceleton);
for (XtendMember member : declaration.getMembers()) {
if (member instanceof XtendTypeDeclaration)
inferTypeSceleton((XtendTypeDeclaration) member, acceptor, preIndexingPhase, xtendFile, doLater, inferredSceleton);
}
}
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class XtendCompilerTest method compileAllClassesWithTheSameFileHeader.
@Test
public void compileAllClassesWithTheSameFileHeader() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* Copyright (c) 2011 itemis AG (http://www.itemis.eu) and others.");
_builder.newLine();
_builder.append(" ");
_builder.append("* All rights reserved. This program and the accompanying materials");
_builder.newLine();
_builder.append(" ");
_builder.append("* are made available under the terms of the Eclipse Public License v1.0");
_builder.newLine();
_builder.append(" ");
_builder.append("* which accompanies this distribution, and is available at");
_builder.newLine();
_builder.append(" ");
_builder.append("* http://www.eclipse.org/legal/epl-v10.html");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("class bar {");
_builder.newLine();
_builder.append(" ");
_builder.append("String name = \'foobar\'");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("class baz {");
_builder.newLine();
_builder.append(" ");
_builder.append("String name = \'foobaz\'");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final String input = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("/**");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("* Copyright (c) 2011 itemis AG (http://www.itemis.eu) and others.");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("* All rights reserved. This program and the accompanying materials");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("* are made available under the terms of the Eclipse Public License v1.0");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("* which accompanies this distribution, and is available at");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("* http://www.eclipse.org/legal/epl-v10.html");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("*/");
_builder_1.newLine();
_builder_1.append("package foo;");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("@SuppressWarnings(\"all\")");
_builder_1.newLine();
_builder_1.append("public class bar {");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("private String name = \"foobar\";");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
final String expectedBarClass = _builder_1.toString();
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("/**");
_builder_2.newLine();
_builder_2.append(" ");
_builder_2.append("* Copyright (c) 2011 itemis AG (http://www.itemis.eu) and others.");
_builder_2.newLine();
_builder_2.append(" ");
_builder_2.append("* All rights reserved. This program and the accompanying materials");
_builder_2.newLine();
_builder_2.append(" ");
_builder_2.append("* are made available under the terms of the Eclipse Public License v1.0");
_builder_2.newLine();
_builder_2.append(" ");
_builder_2.append("* which accompanies this distribution, and is available at");
_builder_2.newLine();
_builder_2.append(" ");
_builder_2.append("* http://www.eclipse.org/legal/epl-v10.html");
_builder_2.newLine();
_builder_2.append(" ");
_builder_2.append("*/");
_builder_2.newLine();
_builder_2.append("package foo;");
_builder_2.newLine();
_builder_2.newLine();
_builder_2.append("@SuppressWarnings(\"all\")");
_builder_2.newLine();
_builder_2.append("public class baz {");
_builder_2.newLine();
_builder_2.append(" ");
_builder_2.append("private String name = \"foobaz\";");
_builder_2.newLine();
_builder_2.append("}");
_builder_2.newLine();
final String expectedBazClass = _builder_2.toString();
final XtendFile file = this.file(input.toString(), true);
final JvmDeclaredType barType = IterableExtensions.<JvmDeclaredType>head(Iterables.<JvmDeclaredType>filter(file.eResource().getContents(), JvmDeclaredType.class));
final JvmDeclaredType bazType = IterableExtensions.<JvmDeclaredType>last(Iterables.<JvmDeclaredType>filter(file.eResource().getContents(), JvmDeclaredType.class));
final GeneratorConfig generatorConfig = this.generatorConfigProvider.get(barType);
CharSequence barJavaCode = this.generator.generateType(barType, generatorConfig);
barJavaCode = this.postProcessor.postProcess(null, barJavaCode);
CharSequence bazJavaCode = this.generator.generateType(bazType, generatorConfig);
bazJavaCode = this.postProcessor.postProcess(null, bazJavaCode);
XtendCompilerTest.assertEquals(expectedBarClass.toString(), barJavaCode.toString());
XtendCompilerTest.assertEquals(expectedBazClass.toString(), bazJavaCode.toString());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations