org.eclipse.jdt.core.dom.CompilationUnit.getColumnNumber()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(125)

本文整理了Java中org.eclipse.jdt.core.dom.CompilationUnit.getColumnNumber()方法的一些代码示例,展示了CompilationUnit.getColumnNumber()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CompilationUnit.getColumnNumber()方法的具体详情如下:
包路径:org.eclipse.jdt.core.dom.CompilationUnit
类名称:CompilationUnit
方法名:getColumnNumber

CompilationUnit.getColumnNumber介绍

[英]Returns the column number corresponding to the given source character position in the original source string. Column number are zero-based. Return -1 if it is beyond the valid range or -2 if the column number information is unknown.
[中]

代码示例

代码示例来源:origin: forge/roaster

@Override
  public int getColumnNumber()
  {
   return cu.getColumnNumber(getStartPosition());
  }
}

代码示例来源:origin: forge/roaster

@Override
  public int getColumnNumber()
  {
   return cu.getColumnNumber(getStartPosition());
  }
}

代码示例来源:origin: tsantalis/RefactoringMiner

public VariableScope(CompilationUnit cu, String filePath, int startOffset, int endOffset) {
  //ASTNode parent = node.getParent();
  this.filePath = filePath;
  this.startOffset = startOffset;
  this.endOffset = endOffset;
  //this.startOffset = node.getStartPosition();
  //this.endOffset = parent.getStartPosition() + parent.getLength();
  
  //lines are 1-based
  this.startLine = cu.getLineNumber(startOffset);
  this.endLine = cu.getLineNumber(endOffset);
  //columns are 0-based
  this.startColumn = cu.getColumnNumber(startOffset);
  //convert to 1-based
  if(this.startColumn > 0) {
    this.startColumn += 1;
  }
  this.endColumn = cu.getColumnNumber(endOffset);
  //convert to 1-based
  if(this.endColumn > 0) {
    this.endColumn += 1;
  }
}

代码示例来源:origin: tsantalis/RefactoringMiner

public LocationInfo(CompilationUnit cu, String filePath, ASTNode node) {
  this.filePath = filePath;
  this.startOffset = node.getStartPosition();
  this.length = node.getLength();
  this.endOffset = startOffset + length;
  
  //lines are 1-based
  this.startLine = cu.getLineNumber(startOffset);
  this.endLine = cu.getLineNumber(endOffset);
  //columns are 0-based
  this.startColumn = cu.getColumnNumber(startOffset);
  //convert to 1-based
  if(this.startColumn > 0) {
    this.startColumn += 1;
  }
  this.endColumn = cu.getColumnNumber(endOffset);
  //convert to 1-based
  if(this.endColumn > 0) {
    this.endColumn += 1;
  }
}

代码示例来源:origin: forge/roaster

@Override
public int getColumn()
{
 int position = problem.getSourceStart();
 if (position >= 0 && parent != null && (parent.getInternal() instanceof CompilationUnit))
 {
   return ((CompilationUnit) parent.getInternal()).getColumnNumber(position);
 }
 return -1;
}

代码示例来源:origin: JnRouvignac/AutoRefactor

@Override
  public String toString() {
    final CompilationUnit astRoot = sourceCode.astRoot;
    return "[(" + astRoot.getLineNumber(getStartPosition()) + ","
        + astRoot.getColumnNumber(getStartPosition()) + ")"
        + " => (" + astRoot.getLineNumber(getEndPosition())
        + "," + astRoot.getColumnNumber(getEndPosition()) + ")]";
  }
}

代码示例来源:origin: stackoverflow.com

final ASTParser p = ASTParser.newParser(AST.JLS3);
p.setSource(source);
final CompilationUnit root = (CompilationUnit) p.createAST(null);
// stuff happens
final ASTNode node = //get a node

final int line = root.getLineNumber(node.getStartPosition());
final int column = root.getColumnNumber(node.getStartPosition());
System.out.println("Node started at (" + line + ", " + column + ")";

代码示例来源:origin: org.jboss.windup.rules.apps/rules-java

private void processType(Type type, TypeReferenceLocation referenceLocation)
{
  if (type == null)
    return;
  String sourceString = type.toString();
  sourceString = resolveClassname(sourceString);
  if (TypeInterestFactory.matchesAny(sourceString, referenceLocation))
  {
    int lineNumber = cu.getLineNumber(type.getStartPosition());
    int columnNumber = cu.getColumnNumber(type.getStartPosition());
    int length = type.getLength();
    JavaTypeReferenceModel typeRef = typeRefService.createTypeReference(fileModel, referenceLocation,
          lineNumber, columnNumber, length, sourceString);
    LOG.finer("Prefix: " + referenceLocation);
    if (type instanceof SimpleType)
    {
      SimpleType sType = (SimpleType) type;
      LOG.finer("The type name is: " + sType.getName().getFullyQualifiedName() + " and " + sourceString);
    }
    LOG.finer("Candidate: " + typeRef);
  }
}

代码示例来源:origin: org.jboss.windup.rules.apps/rules-java

@Override
public boolean visit(MarkerAnnotation node)
{
  processName(node.getTypeName(), TypeReferenceLocation.ANNOTATION, cu.getLineNumber(node.getStartPosition()),
        cu.getColumnNumber(cu.getStartPosition()), cu.getLength());
  return super.visit(node);
}

代码示例来源:origin: org.jboss.windup.rules.apps/rules-java

@Override
public boolean visit(SingleMemberAnnotation node)
{
  processName(node.getTypeName(), TypeReferenceLocation.ANNOTATION, cu.getLineNumber(node.getStartPosition()),
        cu.getColumnNumber(node.getStartPosition()), node.getLength());
  return super.visit(node);
}

代码示例来源:origin: org.jboss.windup.rules.apps/rules-java

@Override
public boolean visit(NormalAnnotation node)
{
  JavaTypeReferenceModel typeRef = processName(node.getTypeName(), TypeReferenceLocation.ANNOTATION, cu.getLineNumber(node.getStartPosition()),
        cu.getColumnNumber(node.getStartPosition()), node.getLength());
  if (typeRef != null)
    addAnnotationValues((JavaAnnotationTypeReferenceModel) typeRef, node);
  return super.visit(node);
}

代码示例来源:origin: windup/windup

/**
 * Declaration of the variable within a block
 */
@Override
public boolean visit(VariableDeclarationStatement node)
{
  for (int i = 0; i < node.fragments().size(); ++i)
  {
    String nodeType = node.getType().toString();
    VariableDeclarationFragment frag = (VariableDeclarationFragment) node.fragments().get(i);
    state.getNames().add(frag.getName().getIdentifier());
    state.getNameInstance().put(frag.getName().toString(), nodeType.toString());
  }
  processType(node.getType(), TypeReferenceLocation.VARIABLE_DECLARATION,
        compilationUnit.getLineNumber(node.getStartPosition()),
        compilationUnit.getColumnNumber(node.getStartPosition()), node.getLength(), node.toString());
  return super.visit(node);
}

代码示例来源:origin: windup/windup

@Override
public boolean visit(InstanceofExpression node)
{
  Type type = node.getRightOperand();
  processType(type, TypeReferenceLocation.INSTANCE_OF, compilationUnit.getLineNumber(node.getStartPosition()),
        compilationUnit.getColumnNumber(type.getStartPosition()), type.getLength(), node.toString());
  return super.visit(node);
}

代码示例来源:origin: JnRouvignac/AutoRefactor

/**
 * Returns a string suitable for identifying a location in the source.
 *
 * @param node the node from which to retrieve the source location
 * @return a string suitable for identifying a location in the source
 */
public static String getSourceLocation(ASTNode node) {
  final ASTNode root = node != null ? node.getRoot() : null;
  if (root instanceof CompilationUnit) {
    final CompilationUnit cu = (CompilationUnit) root;
    final int position = node.getStartPosition();
    final int line = cu.getLineNumber(position);
    final int column = cu.getColumnNumber(position) + 1;
    if (cu.getTypeRoot() != null) {
      return cu.getTypeRoot().getElementName() + ":" + line + ":" + column;
    }
    // it was not created from a file
    return line + ":" + column;
  }
  return "";
}

代码示例来源:origin: usethesource/rascal

protected ISourceLocation getSourceLocation(ASTNode node) {
  try {
    int nodeLength = compilUnit.getExtendedLength(node);
    
    if (nodeLength > 0) {
      int start = compilUnit.getExtendedStartPosition(node);
      int end = start + nodeLength -1;
      
      if (end < start && ((node.getFlags() & 9) > 0)) {
        insert(messages, values.constructor(DATATYPE_RASCAL_MESSAGE_ERROR_NODE_TYPE,
            values.string("Recovered/Malformed node, guessing the length"),
            values.sourceLocation(loc, 0, 0)));
        nodeLength = node.toString().length();
        end = start + nodeLength - 1;
      }
  
      return values.sourceLocation(loc, 
           start, nodeLength, 
           compilUnit.getLineNumber(start), compilUnit.getLineNumber(end), 
           // TODO: only adding 1 at the end seems to work, need to test.
           compilUnit.getColumnNumber(start), compilUnit.getColumnNumber(end)+1);
    }
  } catch (IllegalArgumentException e) {
    insert(messages, values.constructor(DATATYPE_RASCAL_MESSAGE_ERROR_NODE_TYPE,
        values.string("Most probably missing dependency"),
        values.sourceLocation(loc, 0, 0)));
  }
  return values.sourceLocation(loc, 0, 0, 0, 0, 0, 0);
}

代码示例来源:origin: windup/windup

public boolean visit(org.eclipse.jdt.core.dom.CatchClause node)
{
  Type catchType = node.getException().getType();
  processType(catchType, TypeReferenceLocation.CATCH_EXCEPTION_STATEMENT, compilationUnit.getLineNumber(node.getStartPosition()),
        compilationUnit.getColumnNumber(catchType.getStartPosition()), catchType.getLength(), node.toString());
  return super.visit(node);
}

代码示例来源:origin: org.jboss.windup.rules.apps/rules-java

@Override
public boolean visit(ImportDeclaration node)
{
  String name = node.getName().toString();
  if (node.isOnDemand())
  {
    wildcardImports.add(name);
    Iterable<JavaClassModel> classModels = javaClassService.findByJavaPackage(name);
    for (JavaClassModel classModel : classModels)
    {
      processImport(classModel.getQualifiedName(), cu.getLineNumber(node.getName().getStartPosition()),
            cu.getColumnNumber(node.getName().getStartPosition()), node.getName().getLength());
    }
  }
  else
  {
    String clzName = StringUtils.substringAfterLast(name, ".");
    classNameLookedUp.add(clzName);
    classNameToFQCN.put(clzName, name);
    processImport(node.getName().toString(), cu.getLineNumber(node.getName().getStartPosition()),
          cu.getColumnNumber(node.getName().getStartPosition()), node.getName().getLength());
  }
  return super.visit(node);
}

代码示例来源:origin: org.jboss.windup.rules.apps/rules-java

/***
 * Takes the MethodInvocation, and attempts to resolve the types of objects passed into the method invocation.
 */
public boolean visit(MethodInvocation node)
{
  if (!StringUtils.contains(node.toString(), "."))
  {
    // it must be a local method. ignore.
    return true;
  }
  String nodeName = StringUtils.removeStart(node.toString(), "this.");
  List<?> arguments = node.arguments();
  List<String> resolvedParams = methodParameterGuesser(arguments);
  String objRef = StringUtils.substringBefore(nodeName, "." + node.getName().toString());
  if (nameInstance.containsKey(objRef))
  {
    objRef = nameInstance.get(objRef);
  }
  objRef = resolveClassname(objRef);
  MethodType methodCall = new MethodType(objRef, node.getName().toString(), resolvedParams);
  processMethod(methodCall, cu.getLineNumber(node.getName().getStartPosition()),
        cu.getColumnNumber(node.getName().getStartPosition()), node.getName().getLength());
  return super.visit(node);
}

代码示例来源:origin: windup/windup

public boolean visit(org.eclipse.jdt.core.dom.ThrowStatement node)
{
  if (node.getExpression() instanceof ClassInstanceCreation)
  {
    ClassInstanceCreation cic = (ClassInstanceCreation) node.getExpression();
    Type type = cic.getType();
    processType(type, TypeReferenceLocation.THROW_STATEMENT, compilationUnit.getLineNumber(node.getStartPosition()),
          compilationUnit.getColumnNumber(cic.getStartPosition()), cic.getLength(), node.toString());
  }
  return super.visit(node);
}

代码示例来源:origin: org.jboss.windup.rules.apps/rules-java

@Override
public boolean visit(ClassInstanceCreation node)
{
  String nodeType = node.getType().toString();
  nodeType = resolveClassname(nodeType);
  List<String> resolvedParams = this.methodParameterGuesser(node.arguments());
  ConstructorType resolvedConstructor = new ConstructorType(nodeType, resolvedParams);
  processConstructor(resolvedConstructor, cu.getLineNumber(node.getType().getStartPosition()),
        cu.getColumnNumber(node.getType().getStartPosition()), node.getType().getLength());
  return super.visit(node);
}

相关文章

微信公众号

最新文章

更多