Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Make anonymous annotation behave as named ones 6763 #7459

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -8146,14 +8146,15 @@ private void putAnnotation(
annotationSet.put(annotationClass, list.append(annotation));
}


public void transformAnonymousAnnotation(Tree.AnonymousAnnotation annotation, Map<Class, ListBuffer<JCAnnotation>> annos) {
Type docType = ((TypeDeclaration)typeFact().getLanguageModuleDeclaration("DocAnnotation")).getType();
JCAnnotation docAnnotation = at(annotation).Annotation(
makeJavaType(docType, JT_ANNOTATION),
List.<JCExpression>of(make().Assign(naming.makeUnquotedIdent("description"),
transform(annotation.getStringLiteral()))));
putAnnotation(annos, docAnnotation, (Class)docType.getDeclaration());
HasErrorException firstExpressionErrorAndMarkBrokenness = errors().getFirstExpressionErrorAndMarkBrokenness(annotation);
if (firstExpressionErrorAndMarkBrokenness == null) {
Type docType = ((TypeDeclaration) typeFact().getLanguageModuleDeclaration("DocAnnotation")).getType();
JCAnnotation docAnnotation = at(annotation).Annotation(makeJavaType(docType, JT_ANNOTATION),
List.<JCExpression>of(make().Assign(naming.makeUnquotedIdent("description"),
transform(annotation.getStringLiteral()))));
putAnnotation(annos, docAnnotation, (Class) docType.getDeclaration());
}
}

public JCExpression makeMetaLiteralStringLiteralForAnnotation(Tree.MetaLiteral literal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.ceylon.compiler.typechecker.tree.Node;
import org.eclipse.ceylon.compiler.typechecker.tree.Tree;
import org.eclipse.ceylon.compiler.typechecker.tree.Visitor;
import org.eclipse.ceylon.compiler.typechecker.tree.Tree.AnonymousAnnotation;
import org.eclipse.ceylon.model.loader.model.LazyClass;
import org.eclipse.ceylon.model.loader.model.LazyInterface;
import org.eclipse.ceylon.model.typechecker.model.Class;
Expand Down Expand Up @@ -109,7 +110,6 @@ public final void visitAny(Node that) {
*/
private void planAccordingToErrors(Node that) {
List<Message> errors = that.getErrors();

for(Message message : errors){
if(isError(that, message)) {
TransformationPlan plan;
Expand Down Expand Up @@ -167,6 +167,11 @@ private boolean isError(Node that, Message message) {
}
}

@Override
public void visit(AnonymousAnnotation that) {
// don't go there
}

@Override
public void visit(Tree.Annotation that) {
// don't go there
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public TransformationPlan hasDeclarationError(Tree.Declaration node) {
return declarationVisitor.getRecoveryPlan(node);
}

public HasErrorException getFirstExpressionErrorAndMarkBrokenness(Tree.AnonymousAnnotation node) {
return annotateBrokenness(expressionVisitor.getFirstErrorMessage(node));
}

/**
* Visit the given tree of expressions returning the first error found,
* or null if the tree is free of errors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.Collections;
import java.util.TreeSet;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;

import org.eclipse.ceylon.compiler.java.launcher.Main.ExitState;
import org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel;
import org.eclipse.ceylon.compiler.java.test.CompilerError;
import org.eclipse.ceylon.compiler.java.test.CompilerError.Classification;
import org.eclipse.ceylon.compiler.java.test.CompilerTests;
import org.eclipse.ceylon.compiler.java.test.ErrorCollector;
import org.eclipse.ceylon.javax.tools.Diagnostic.Kind;
Expand Down Expand Up @@ -441,4 +443,13 @@ public void testBug6982() throws Throwable {
public void testBug6997() throws Throwable {
compareWithJavaSource("bug69xx/Bug6997");
}
@Test
public void testBug6763() {
assertErrors("bug67xx/Bug6763", Collections.emptyList(), null,
new CompilerError(
Kind.ERROR,"Bug6763",1,
"illegal escape sequence: '\\i' is not a recognized escape sequence",
Classification.FRONTEND)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"\i"
class C() {}
C f(C c) => c;