本文整理汇总了Java中org.codehaus.groovy.ast.ASTNode.getLineNumber方法的典型用法代码示例。如果您正苦于以下问题:Java ASTNode.getLineNumber方法的具体用法?Java ASTNode.getLineNumber怎么用?Java ASTNode.getLineNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.ASTNode
的用法示例。
在下文中一共展示了ASTNode.getLineNumber方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onLineNumber
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
public void onLineNumber(ASTNode statement, String message) {
MethodVisitor mv = controller.getMethodVisitor();
if (statement==null) return;
int line = statement.getLineNumber();
this.currentASTNode = statement;
if (line < 0) return;
if (!ASM_DEBUG && line==controller.getLineNumber()) return;
controller.setLineNumber(line);
if (mv != null) {
Label l = new Label();
mv.visitLabel(l);
mv.visitLineNumber(line, l);
}
}
示例2: parse
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
static Options parse(MethodNode mn, ASTNode source, String[] options) throws IncorrectTypeHintException {
int pIndex = 0;
boolean generateIndex = false;
for (String option : options) {
String[] keyValue = option.split("=");
if (keyValue.length==2) {
String key = keyValue[0];
String value = keyValue[1];
if ("argNum".equals(key)) {
pIndex = Integer.parseInt(value);
} else if ("index".equals(key)) {
generateIndex = Boolean.valueOf(value);
} else {
throw new IncorrectTypeHintException(mn, "Unrecognized option: "+key, source.getLineNumber(), source.getColumnNumber());
}
} else {
throw new IncorrectTypeHintException(mn, "Incorrect option format. Should be argNum=<num> or index=<boolean> ", source.getLineNumber(), source.getColumnNumber());
}
}
return new Options(pIndex, generateIndex);
}
示例3: createLocation
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
@Override
protected Location createLocation(@NonNull Context context, @NonNull Object cookie) {
ASTNode node = (ASTNode) cookie;
Pair<Integer, Integer> offsets = getOffsets(node, context);
int fromLine = node.getLineNumber() - 1;
int fromColumn = node.getColumnNumber() - 1;
int toLine = node.getLastLineNumber() - 1;
int toColumn = node.getLastColumnNumber() - 1;
return Location.create(context.file,
new DefaultPosition(fromLine, fromColumn, offsets.getFirst()),
new DefaultPosition(toLine, toColumn, offsets.getSecond()));
}
示例4: addErrorMessage
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
private void addErrorMessage(GroovyRuntimeException exception) {
ASTNode astNode = exception.getNode();
ModuleNode module = exception.getModule();
if (module == null) {
module = findModule(astNode);
}
String moduleName = module == null ? "<no module>" : module.getDescription();
int lineNumber = astNode == null ? -1 : astNode.getLineNumber();
int columnNumber = astNode == null ? -1 : astNode.getColumnNumber();
collector.add(new CompilerMessage(GroovyCompilerMessageCategories.ERROR, getExceptionMessage(exception), moduleName, lineNumber, columnNumber));
}
示例5: addError
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
@Override
public void addError(final String msg, final ASTNode expr) {
Long err = ((long) expr.getLineNumber()) << 16 + expr.getColumnNumber();
if ((DEBUG_GENERATED_CODE && expr.getLineNumber()<0) || !typeCheckingContext.reportedErrors.contains(err)) {
typeCheckingContext.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException(msg + '\n', expr.getLineNumber(), expr.getColumnNumber(), expr.getLastLineNumber(), expr.getLastColumnNumber()),
typeCheckingContext.source)
);
typeCheckingContext.reportedErrors.add(err);
}
}
示例6: addStaticTypeError
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
protected void addStaticTypeError(final String msg, final ASTNode expr) {
if (expr.getColumnNumber() > 0 && expr.getLineNumber() > 0) {
addError(StaticTypesTransformation.STATIC_ERROR_PREFIX + msg, expr);
} else {
if (DEBUG_GENERATED_CODE) {
addError(StaticTypesTransformation.STATIC_ERROR_PREFIX + "Error in generated code ["+expr.getText()+"] - "+ msg, expr);
}
// ignore errors which are related to unknown source locations
// because they are likely related to generated code
}
}
示例7: convertASTToSource
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
/**
* Converts an expression into the String source. Only some specific expressions like closure expression
* support this.
*
* @param readerSource a source
* @param expression an expression. Can't be null
* @return the source the closure was created from
* @throws java.lang.IllegalArgumentException when expression is null
* @throws java.lang.Exception when closure can't be read from source
*/
public static String convertASTToSource(ReaderSource readerSource, ASTNode expression) throws Exception {
if (expression == null) throw new IllegalArgumentException("Null: expression");
StringBuilder result = new StringBuilder();
for (int x = expression.getLineNumber(); x <= expression.getLastLineNumber(); x++) {
String line = readerSource.getLine(x, null);
if (line == null) {
throw new Exception(
"Error calculating source code for expression. Trying to read line " + x + " from " + readerSource.getClass()
);
}
if (x == expression.getLastLineNumber()) {
line = line.substring(0, expression.getLastColumnNumber() - 1);
}
if (x == expression.getLineNumber()) {
line = line.substring(expression.getColumnNumber() - 1);
}
//restoring line breaks is important b/c of lack of semicolons
result.append(line).append('\n');
}
String source = result.toString().trim();
return source;
}
示例8: hasPlausibleSourcePosition
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
private static boolean hasPlausibleSourcePosition(ASTNode node) {
return node.getLineNumber() > 0
&& node.getColumnNumber() > 0
&& node.getLastLineNumber() >= node.getLineNumber()
&& node.getLastColumnNumber() >
(node.getLineNumber() == node.getLastLineNumber() ? node.getColumnNumber() : 0);
}
示例9: createLocation
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
private Location createLocation(@NonNull Context context, @NonNull Object cookie) {
ASTNode node = (ASTNode) cookie;
Pair<Integer, Integer> offsets = getOffsets(node, context);
int fromLine = node.getLineNumber() - 1;
int fromColumn = node.getColumnNumber() - 1;
int toLine = node.getLastLineNumber() - 1;
int toColumn = node.getLastColumnNumber() - 1;
return Location.create(context.file,
new DefaultPosition(fromLine, fromColumn, offsets.getFirst()),
new DefaultPosition(toLine, toColumn, offsets.getSecond()));
}
示例10: createSyntaxErrorMessage
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
private Message createSyntaxErrorMessage(String message, ASTNode node) {
return new SyntaxErrorMessage(
new SyntaxException(message, node.getLineNumber(), node.getColumnNumber(),
node.getLastLineNumber(), node.getLastColumnNumber()),
getSourceUnit());
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:7,代码来源:DependencyManagementBomTransformation.java
示例11: throwParserException
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
public void throwParserException() throws SyntaxException {
final ASTNode node = getNode();
throw new SyntaxException(getMessage(), node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber());
}
示例12: SyntaxException
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
public SyntaxException(String message, ASTNode node) {
this(message, node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber());
}
示例13: checkNoStaticMethodWithSameSignatureAsNonStatic
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
private void checkNoStaticMethodWithSameSignatureAsNonStatic(final ClassNode node) {
ClassNode parent = node.getSuperClass();
Map<String, MethodNode> result;
// start with methods from the parent if any
if (parent != null) {
result = parent.getDeclaredMethodsMap();
} else {
result = new HashMap<String, MethodNode>();
}
// add in unimplemented abstract methods from the interfaces
ClassNodeUtils.addDeclaredMethodsFromInterfaces(node, result);
for (MethodNode methodNode : node.getMethods()) {
MethodNode mn = result.get(methodNode.getTypeDescriptor());
if (mn != null && (mn.isStatic() ^ methodNode.isStatic()) && !methodNode.isStaticConstructor()) {
if (!mn.isAbstract()) continue;
ClassNode declaringClass = mn.getDeclaringClass();
ClassNode cn = declaringClass.getOuterClass();
if (cn == null && declaringClass.isResolved()) {
// in case of a precompiled class, the outerclass is unknown
Class typeClass = declaringClass.getTypeClass();
typeClass = typeClass.getEnclosingClass();
if (typeClass != null) {
cn = ClassHelper.make(typeClass);
}
}
if (cn == null || !Traits.isTrait(cn)) {
ASTNode errorNode = methodNode;
String name = mn.getName();
if (errorNode.getLineNumber() == -1) {
// try to get a better error message location based on the property
for (PropertyNode propertyNode : node.getProperties()) {
if (name.startsWith("set") || name.startsWith("get") || name.startsWith("is")) {
String propName = Verifier.capitalize(propertyNode.getField().getName());
String shortName = name.substring(name.startsWith("is") ? 2 : 3);
if (propName.equals(shortName)) {
errorNode = propertyNode;
break;
}
}
}
}
addError("The " + getDescription(methodNode) + " is already defined in " + getDescription(node) +
". You cannot have both a static and an instance method with the same signature", errorNode);
}
}
result.put(methodNode.getTypeDescriptor(), methodNode);
}
}