本文整理了Java中org.codehaus.groovy.ast.AnnotationNode.getLastLineNumber()
方法的一些代码示例,展示了AnnotationNode.getLastLineNumber()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AnnotationNode.getLastLineNumber()
方法的具体详情如下:
包路径:org.codehaus.groovy.ast.AnnotationNode
类名称:AnnotationNode
方法名:getLastLineNumber
暂无
代码示例来源:origin: org.codehaus.groovy/groovy
/**
* Handles the bulk of the processing, mostly delegating to other methods.
*
* @param nodes the AST nodes
* @param source the source unit for the nodes
*/
public void visit(ASTNode[] nodes, SourceUnit source) {
if (!(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
throw new RuntimeException("Internal error: wrong types: $node.class / $parent.class");
}
AnnotationNode node = (AnnotationNode) nodes[0];
if (nodes[1] instanceof ClassNode) {
addListenerToClass(source, (ClassNode) nodes[1]);
} else {
if ((((FieldNode)nodes[1]).getModifiers() & Opcodes.ACC_FINAL) != 0) {
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@groovy.beans.Vetoable cannot annotate a final property.",
node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
source));
}
addListenerToProperty(source, node, (AnnotatedNode) nodes[1]);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
private static ClassNode getTargetClass(SourceUnit source, AnnotationNode annotation) {
Expression value = annotation.getMember("value");
if (!(value instanceof ClassExpression)) {
//noinspection ThrowableInstanceNeverThrown
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@groovy.lang.Category must define 'value' which is the class to apply this category to",
annotation.getLineNumber(), annotation.getColumnNumber(), annotation.getLastLineNumber(), annotation.getLastColumnNumber()),
source));
return null;
} else {
ClassExpression ce = (ClassExpression) value;
return ce.getType();
}
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
private void addListenerToProperty(SourceUnit source, AnnotationNode node, ClassNode declaringClass, FieldNode field) {
String fieldName = field.getName();
for (PropertyNode propertyNode : declaringClass.getProperties()) {
if (propertyNode.getName().equals(fieldName)) {
if (field.isStatic()) {
//noinspection ThrowableInstanceNeverThrown
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@groovy.beans.Bindable cannot annotate a static property.",
node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
source));
} else {
if (needsPropertyChangeSupport(declaringClass, source)) {
addPropertyChangeSupport(declaringClass);
}
createListenerSetter(declaringClass, propertyNode);
}
return;
}
}
//noinspection ThrowableInstanceNeverThrown
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@groovy.beans.Bindable must be on a property, not a field. Try removing the private, protected, or public modifier.",
node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
source));
}
代码示例来源:origin: org.codehaus.groovy/groovy
private void addListenerToProperty(SourceUnit source, AnnotationNode node, AnnotatedNode parent) {
ClassNode declaringClass = parent.getDeclaringClass();
FieldNode field = ((FieldNode) parent);
String fieldName = field.getName();
for (PropertyNode propertyNode : declaringClass.getProperties()) {
boolean bindable = BindableASTTransformation.hasBindableAnnotation(parent)
|| BindableASTTransformation.hasBindableAnnotation(parent.getDeclaringClass());
if (propertyNode.getName().equals(fieldName)) {
if (field.isStatic()) {
//noinspection ThrowableInstanceNeverThrown
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@groovy.beans.Vetoable cannot annotate a static property.",
node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
source));
} else {
createListenerSetter(source, bindable, declaringClass, propertyNode);
}
return;
}
}
//noinspection ThrowableInstanceNeverThrown
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@groovy.beans.Vetoable must be on a property, not a field. Try removing the private, protected, or public modifier.",
node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
source));
}
代码示例来源:origin: org.codehaus.groovy/groovy
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@groovy.beans.Bindable cannot annotate a final property.",
node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
source));
代码示例来源:origin: org.codenarc/CodeNarc
/**
* gets the first non annotation line number of a node, taking into account annotations.
*/
public static int findFirstNonAnnotationLine(ASTNode node, SourceCode sourceCode) {
if (node instanceof AnnotatedNode && !((AnnotatedNode) node).getAnnotations().isEmpty()) {
// HACK: Groovy line numbers are broken when annotations have a parameter :(
// so we must look at the lineNumber, not the lastLineNumber
AnnotationNode lastAnnotation = null;
for (AnnotationNode annotation : ((AnnotatedNode) node).getAnnotations()) {
if (lastAnnotation == null) lastAnnotation = annotation;
else if (lastAnnotation.getLineNumber() < annotation.getLineNumber()) lastAnnotation = annotation;
}
String rawLine = getRawLine(sourceCode, lastAnnotation.getLastLineNumber()-1);
if(rawLine == null) {
return node.getLineNumber();
}
// is the annotation the last thing on the line?
if (rawLine.length() > lastAnnotation.getLastColumnNumber()) {
// no it is not
return lastAnnotation.getLastLineNumber();
}
// yes it is the last thing, return the next thing
return lastAnnotation.getLastLineNumber() + 1;
}
return node.getLineNumber();
}
代码示例来源:origin: org.codehaus.griffon/griffon-groovy-compile
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@griffon.transform.Observable cannot annotate a final property.",
node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
source));
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-editor
private void addAnnotationOccurrences(AnnotationNode annotation, ClassNode findingNode) {
ClassNode classNode = annotation.getClassNode();
classNode.setLineNumber(annotation.getLineNumber());
classNode.setColumnNumber(annotation.getColumnNumber());
classNode.setLastLineNumber(annotation.getLastLineNumber());
classNode.setLastColumnNumber(annotation.getLastColumnNumber());
addOccurrences(classNode, findingNode);
}
代码示例来源:origin: org.codehaus.griffon/griffon-groovy-compile
/**
* Handles the bulk of the processing, mostly delegating to other methods.
*
* @param nodes the ast nodes
* @param source the source unit for the nodes
*/
public void visit(ASTNode[] nodes, SourceUnit source) {
if (!(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
throw new RuntimeException("Internal error: wrong types: $node.class / $parent.class");
}
AnnotationNode node = (AnnotationNode) nodes[0];
if (nodes[1] instanceof ClassNode) {
addVetoableIfNeeded(source, (ClassNode) nodes[1]);
} else {
if ((((FieldNode) nodes[1]).getModifiers() & Modifier.FINAL) != 0) {
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@griffon.transform.Vetoable cannot annotate a final property.",
node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
source));
}
addVetoableIfNeeded(source, node, (AnnotatedNode) nodes[1]);
}
}
代码示例来源:origin: org.codehaus.griffon/griffon-groovy-compile
public static void addObservableIfNeeded(SourceUnit source, AnnotationNode annotationNode, ClassNode classNode, FieldNode field) {
String fieldName = field.getName();
for (PropertyNode propertyNode : classNode.getProperties()) {
if (propertyNode.getName().equals(fieldName)) {
if (field.isStatic()) {
//noinspection ThrowableInstanceNeverThrown
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@griffon.transform.Observable cannot annotate a static property.",
annotationNode.getLineNumber(), annotationNode.getColumnNumber(), annotationNode.getLastLineNumber(), annotationNode.getLastColumnNumber()),
source));
} else {
if (needsObservableSupport(classNode, source)) {
LOG.debug("Injecting {} into {}", OBSERVABLE_TYPE, classNode.getName());
apply(classNode);
}
createListenerSetter(classNode, propertyNode);
}
return;
}
}
//noinspection ThrowableInstanceNeverThrown
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@griffon.transform.Observable must be on a property, not a field. Try removing the private, protected, or public modifier.",
annotationNode.getLineNumber(), annotationNode.getColumnNumber(), annotationNode.getLastLineNumber(), annotationNode.getLastColumnNumber()),
source));
}
代码示例来源:origin: org.codehaus.griffon/griffon-groovy-compile
private void addVetoableIfNeeded(SourceUnit source, AnnotationNode node, AnnotatedNode parent) {
ClassNode declaringClass = parent.getDeclaringClass();
FieldNode field = ((FieldNode) parent);
String fieldName = field.getName();
for (PropertyNode propertyNode : declaringClass.getProperties()) {
boolean bindable = hasObservableAnnotation(parent)
|| hasObservableAnnotation(parent.getDeclaringClass());
if (propertyNode.getName().equals(fieldName)) {
if (field.isStatic()) {
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@griffon.transform.Vetoable cannot annotate a static property.",
node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
source));
} else {
createListenerSetter(source, bindable, declaringClass, propertyNode);
}
return;
}
}
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@griffon.transform.Vetoable must be on a property, not a field. Try removing the private, protected, or public modifier.",
node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
source));
}
内容来源于网络,如有侵权,请联系作者删除!