本文整理汇总了Java中org.codehaus.groovy.control.SourceUnit.addError方法的典型用法代码示例。如果您正苦于以下问题:Java SourceUnit.addError方法的具体用法?Java SourceUnit.addError怎么用?Java SourceUnit.addError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.control.SourceUnit
的用法示例。
在下文中一共展示了SourceUnit.addError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMacroArguments
import org.codehaus.groovy.control.SourceUnit; //导入方法依赖的package包/类
protected static TupleExpression getMacroArguments(SourceUnit source, MethodCallExpression call) {
Expression macroCallArguments = call.getArguments();
if (macroCallArguments == null) {
source.addError(new SyntaxException("Call should have arguments" + '\n', call));
return null;
}
if (!(macroCallArguments instanceof TupleExpression)) {
source.addError(new SyntaxException("Call should have TupleExpression as arguments" + '\n', macroCallArguments));
return null;
}
TupleExpression tupleArguments = (TupleExpression) macroCallArguments;
if (tupleArguments.getExpressions() == null) {
source.addError(new SyntaxException("Call arguments should have expressions" + '\n', tupleArguments));
return null;
}
return tupleArguments;
}
示例2: getClosureArgument
import org.codehaus.groovy.control.SourceUnit; //导入方法依赖的package包/类
protected static ClosureExpression getClosureArgument(SourceUnit source, MethodCallExpression call) {
TupleExpression tupleArguments = getMacroArguments(source, call);
if (tupleArguments == null || tupleArguments.getExpressions().size() < 1) {
source.addError(new SyntaxException("Call arguments should have at least one argument" + '\n', tupleArguments));
return null;
}
Expression result = tupleArguments.getExpression(tupleArguments.getExpressions().size() - 1);
if (!(result instanceof ClosureExpression)) {
source.addError(new SyntaxException("Last call argument should be a closure" + '\n', result));
return null;
}
return (ClosureExpression) result;
}
示例3: resolveClassNode
import org.codehaus.groovy.control.SourceUnit; //导入方法依赖的package包/类
private static ClassNode resolveClassNode(final SourceUnit sourceUnit, final CompilationUnit compilationUnit, final MethodNode mn, final ASTNode usage, final ClassNode parsedNode) {
ClassNode dummyClass = new ClassNode("dummy",0, ClassHelper.OBJECT_TYPE);
dummyClass.setModule(new ModuleNode(sourceUnit));
dummyClass.setGenericsTypes(mn.getDeclaringClass().getGenericsTypes());
MethodNode dummyMN = new MethodNode(
"dummy",
0,
parsedNode,
Parameter.EMPTY_ARRAY,
ClassNode.EMPTY_ARRAY,
EmptyStatement.INSTANCE
);
dummyMN.setGenericsTypes(mn.getGenericsTypes());
dummyClass.addMethod(dummyMN);
ResolveVisitor visitor = new ResolveVisitor(compilationUnit) {
@Override
public void addError(final String msg, final ASTNode expr) {
sourceUnit.addError(new IncorrectTypeHintException(mn, msg, usage.getLineNumber(), usage.getColumnNumber()));
}
};
visitor.startResolving(dummyClass, sourceUnit);
return dummyMN.getReturnType();
}
示例4: checkTraitAllowed
import org.codehaus.groovy.control.SourceUnit; //导入方法依赖的package包/类
private static void checkTraitAllowed(final ClassNode bottomTrait, final SourceUnit unit) {
ClassNode superClass = bottomTrait.getSuperClass();
if (superClass==null || ClassHelper.OBJECT_TYPE.equals(superClass)) return;
if (!Traits.isTrait(superClass)) {
unit.addError(new SyntaxException("A trait can only inherit from another trait", superClass.getLineNumber(), superClass.getColumnNumber()));
}
}
示例5: visit
import org.codehaus.groovy.control.SourceUnit; //导入方法依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit source) {
AnnotationNode annotationInformation = (AnnotationNode) nodes[0];
Map<String,Expression> members = annotationInformation.getMembers();
Expression extensions = members.get("extensions");
AnnotatedNode node = (AnnotatedNode) nodes[1];
StaticTypeCheckingVisitor visitor = null;
if (node instanceof ClassNode) {
ClassNode classNode = (ClassNode) node;
visitor = newVisitor(source, classNode);
visitor.setCompilationUnit(compilationUnit);
addTypeCheckingExtensions(visitor, extensions);
visitor.initialize();
visitor.visitClass(classNode);
} else if (node instanceof MethodNode) {
MethodNode methodNode = (MethodNode) node;
visitor = newVisitor(source, methodNode.getDeclaringClass());
visitor.setCompilationUnit(compilationUnit);
addTypeCheckingExtensions(visitor, extensions);
visitor.setMethodsToBeVisited(Collections.singleton(methodNode));
visitor.initialize();
visitor.visitMethod(methodNode);
} else {
source.addError(new SyntaxException(STATIC_ERROR_PREFIX + "Unimplemented node type",
node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()));
}
if (visitor != null) {
visitor.performSecondPass();
}
}
示例6: getClosureSignatures
import org.codehaus.groovy.control.SourceUnit; //导入方法依赖的package包/类
public List<ClassNode[]> getClosureSignatures(final MethodNode node, final SourceUnit sourceUnit, final CompilationUnit compilationUnit, final String[] options, final ASTNode usage) {
Options opt;
try {
opt = Options.parse(node, usage, options);
} catch (IncorrectTypeHintException e) {
sourceUnit.addError(e);
return Collections.emptyList();
}
GenericsType[] genericsTypes = node.getParameters()[opt.parameterIndex].getOriginType().getGenericsTypes();
if (genericsTypes==null) {
// would happen if you have a raw Map type for example
genericsTypes = new GenericsType[] {
new GenericsType(ClassHelper.OBJECT_TYPE),
new GenericsType(ClassHelper.OBJECT_TYPE)
};
}
ClassNode[] firstSig;
ClassNode[] secondSig;
ClassNode mapEntry = MAPENTRY_TYPE.getPlainNodeReference();
mapEntry.setGenericsTypes(genericsTypes);
if (opt.generateIndex) {
firstSig = new ClassNode[] {genericsTypes[0].getType(), genericsTypes[1].getType(), ClassHelper.int_TYPE};
secondSig = new ClassNode[] {mapEntry, ClassHelper.int_TYPE};
} else {
firstSig = new ClassNode[] {genericsTypes[0].getType(), genericsTypes[1].getType()};
secondSig = new ClassNode[] {mapEntry};
}
return Arrays.asList(firstSig, secondSig);
}
示例7: visit
import org.codehaus.groovy.control.SourceUnit; //导入方法依赖的package包/类
@Override
public void visit(final ASTNode[] nodes, final SourceUnit source) {
AnnotationNode annotationInformation = (AnnotationNode) nodes[0];
AnnotatedNode node = (AnnotatedNode) nodes[1];
StaticTypeCheckingVisitor visitor = null;
Map<String,Expression> members = annotationInformation.getMembers();
Expression extensions = members.get("extensions");
if (node instanceof ClassNode) {
ClassNode classNode = (ClassNode) node;
visitor = newVisitor(source, classNode);
visitor.setCompilationUnit(compilationUnit);
addTypeCheckingExtensions(visitor, extensions);
classNode.putNodeMetaData(WriterControllerFactory.class, factory);
node.putNodeMetaData(STATIC_COMPILE_NODE, !visitor.isSkipMode(node));
visitor.initialize();
visitor.visitClass(classNode);
} else if (node instanceof MethodNode) {
MethodNode methodNode = (MethodNode) node;
ClassNode declaringClass = methodNode.getDeclaringClass();
visitor = newVisitor(source, declaringClass);
visitor.setCompilationUnit(compilationUnit);
addTypeCheckingExtensions(visitor, extensions);
methodNode.putNodeMetaData(STATIC_COMPILE_NODE, !visitor.isSkipMode(node));
if (declaringClass.getNodeMetaData(WriterControllerFactory.class) == null) {
declaringClass.putNodeMetaData(WriterControllerFactory.class, factory);
}
visitor.setMethodsToBeVisited(Collections.singleton(methodNode));
visitor.initialize();
visitor.visitMethod(methodNode);
} else {
source.addError(new SyntaxException(STATIC_ERROR_PREFIX + "Unimplemented node type",
node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()));
}
if (visitor != null) {
visitor.performSecondPass();
}
StaticCompilationTransformer transformer = new StaticCompilationTransformer(source, visitor);
if (node instanceof ClassNode) {
transformer.visitClass((ClassNode) node);
} else if (node instanceof MethodNode) {
transformer.visitMethod((MethodNode) node);
}
}