Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some Xbase cleanup #2888

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ class JvmModelGenerator implements IGenerator {
generateDocumentation(adapter.documentation, emptyList, appendable, config)
}
}
}
}

def addJavaDocImports(EObject it, ITreeAppendable appendable,List<INode> documentationNodes) {
for(node : documentationNodes){
Expand Down Expand Up @@ -839,12 +839,7 @@ class JvmModelGenerator implements IGenerator {
}

def getImportManager(ITreeAppendable appendable) {
val stateField = appendable.getClass.getDeclaredField("state")
stateField.setAccessible(true)
val stateValue = stateField.get(appendable)
val importManagerField = stateValue.getClass.getDeclaredField("importManager")
importManagerField.setAccessible(true)
importManagerField.get(stateValue) as ImportManager
(appendable as TreeAppendable).getImportManager()
}

def protected generateDocumentation(String text, List<INode> documentationNodes, ITreeAppendable appendable, GeneratorConfig config) {
Expand Down Expand Up @@ -886,7 +881,7 @@ class JvmModelGenerator implements IGenerator {
toJava(appendable, config)
])
}

def void toJava(JvmAnnotationValue it, ITreeAppendable appendable, GeneratorConfig config) {
if (operation !== null) {
if (operation.simpleName === null) {
Expand All @@ -899,11 +894,11 @@ class JvmModelGenerator implements IGenerator {
}
toJavaLiteral(appendable, config)
}

def dispatch void toJavaLiteral(JvmAnnotationAnnotationValue value, ITreeAppendable appendable, GeneratorConfig config) {
appendable.forEachWithShortcut(value.values, [generateAnnotation(appendable, config)])
}

def dispatch void toJavaLiteral(JvmShortAnnotationValue it, ITreeAppendable appendable, GeneratorConfig config) {
appendable.forEachWithShortcut(values, [appendable.append(toString)])
}
Expand Down Expand Up @@ -955,26 +950,26 @@ class JvmModelGenerator implements IGenerator {
appendable.append('"' + doConvertToJavaString(toString) + '"')
])
}

def dispatch void toJavaLiteral(JvmTypeAnnotationValue it, ITreeAppendable appendable, GeneratorConfig config) {
appendable.forEachWithShortcut(values, [
appendable.append(type).append(".class")
])
}
}

def dispatch void toJavaLiteral(JvmEnumAnnotationValue it, ITreeAppendable appendable, GeneratorConfig config) {
appendable.forEachWithShortcut(values, [
appendable.append(declaringType)
appendable.append(".")
appendable.append(simpleName.makeJavaIdentifier)
])
}
}

def dispatch void toJavaLiteral(JvmBooleanAnnotationValue it, ITreeAppendable appendable, GeneratorConfig config) {
appendable.forEachWithShortcut(values, [
appendable.append(toString)
])
}
}

def dispatch void toJavaLiteral(JvmCustomAnnotationValue it, ITreeAppendable appendable, GeneratorConfig config) {
if(values.isEmpty)
Expand All @@ -984,7 +979,7 @@ class JvmModelGenerator implements IGenerator {
compiler.toJavaExpression(it, appendable)
])
}

def TreeAppendable createAppendable(EObject context, ImportManager importManager, GeneratorConfig config) {
val cachingConverter = new ITraceURIConverter() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@

import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.inject.Inject;

Expand Down Expand Up @@ -1132,14 +1131,9 @@ protected void constructorCallToJavaExpression(final XConstructorCall expr, ITre
}

protected void appendConstructedTypeName(XConstructorCall constructorCall, ITreeAppendable typeAppendable) {
JvmDeclaredType type = constructorCall.getConstructor().getDeclaringType();
if (type instanceof JvmGenericType && ((JvmGenericType) type).isAnonymous()) {
typeAppendable.append(Iterables.getLast(type.getSuperTypes()).getType());
} else {
IResolvedTypes resolvedTypes = batchTypeResolver.resolveTypes(constructorCall);
LightweightTypeReference actualType = resolvedTypes.getActualType(constructorCall).getRawTypeReference();
typeAppendable.append(actualType);
}
IResolvedTypes resolvedTypes = batchTypeResolver.resolveTypes(constructorCall);
LightweightTypeReference actualType = resolvedTypes.getActualType(constructorCall).getRawTypeReference();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use getNamedType to obtain the correct type if it’s an anonymous class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@szarnekow This is done by org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReferenceSerializer.doVisitParameterizedTypeReference(ParameterizedTypeReference)

	@Override
	protected void doVisitParameterizedTypeReference(ParameterizedTypeReference reference) {
		if (reference.isAnonymous()) {
			reference.getNamedType().accept(this);
		} else {
			appender.append(reference.getType());
			if (!reference.getTypeArguments().isEmpty()) {
				appender.append("<");
				appendCommaSeparated(reference.getTypeArguments());
				appender.append(">");
			}
		}
	}

But I've just noted Xtend compilation tests fail: also the org.eclipse.xtext.xbase.compiler.XbaseCompiler.constructorCallToJavaExpression(XConstructorCall, ITreeAppendable) needs adjusting/simplification or it generates type arguments twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@szarnekow the new commit fdad984 updates/simplified org.eclipse.xtext.xbase.compiler.XbaseCompiler.constructorCallToJavaExpression(XConstructorCall, ITreeAppendable) accordingly (at least locally Xtend tests are now green)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@szarnekow it can be simplified even further 28a2e11

last message for this year: Happy new year :)

typeAppendable.append(actualType);
}

/* @Nullable */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,10 @@ public SharedAppendableState getState() {
return state;
}

ImportManager getImportManager() {
/**
* @since 2.34
*/
public ImportManager getImportManager() {
return state.getImportManager();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.inject.Inject;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -1226,21 +1225,7 @@ public void addJavaDocImports(final EObject it, final ITreeAppendable appendable
}

public ImportManager getImportManager(final ITreeAppendable appendable) {
try {
ImportManager _xblockexpression = null;
{
final Field stateField = appendable.getClass().getDeclaredField("state");
stateField.setAccessible(true);
final Object stateValue = stateField.get(appendable);
final Field importManagerField = stateValue.getClass().getDeclaredField("importManager");
importManagerField.setAccessible(true);
Object _get = importManagerField.get(stateValue);
_xblockexpression = ((ImportManager) _get);
}
return _xblockexpression;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
return ((TreeAppendable) appendable).getImportManager();
}

protected ITreeAppendable generateDocumentation(final String text, final List<INode> documentationNodes, final ITreeAppendable appendable, final GeneratorConfig config) {
Expand Down
Loading