List of usage examples for org.eclipse.jdt.core.dom QualifiedName setSourceRange
public final void setSourceRange(int startPosition, int length)
From source file:com.windowtester.eclipse.ui.convert.WTConvertAPIContext.java
License:Open Source License
/** * Construct a new simple or qualified name * //from w w w . j a v a 2 s . c o m * @param text the simple or qualified name as text (not <code>null</code>, not empty) * @param startPosition the starting position relative to the new AST nodes being * created. For example, when instantiating a new name node to replace an * existing name node, pass zero. When instantiation a new name node to be * used as part of a new import declaration, pass the offset of the name * node within the new import declaration. * @return a new name (not <code>null</code>) */ public Name newName(String text, final int startPosition) { Name newName = compUnit.getAST().newName(text); newName.accept(new ASTVisitor() { int index = startPosition; public boolean visit(QualifiedName node) { node.setSourceRange(startPosition, node.toString().length()); return true; } public boolean visit(SimpleName node) { int length = node.getIdentifier().length(); node.setSourceRange(index, length); index += length + 1; return true; } }); return newName; }
From source file:lombok.eclipse.agent.PatchValEclipse.java
License:Open Source License
public static MarkerAnnotation createValAnnotation(AST ast, Annotation original, int start, int end) { MarkerAnnotation out = null;/*ww w . ja v a2s.c om*/ try { out = Reflection.markerAnnotationConstructor.newInstance(ast); } catch (InstantiationException e) { throw Lombok.sneakyThrow(e); } catch (IllegalAccessException e) { throw Lombok.sneakyThrow(e); } catch (InvocationTargetException e) { throw Lombok.sneakyThrow(e); } if (out != null) { SimpleName valName = ast.newSimpleName("val"); valName.setSourceRange(start, end - start + 1); if (original.type instanceof SingleTypeReference) { out.setTypeName(valName); setIndex(valName, 1); } else { SimpleName lombokName = ast.newSimpleName("lombok"); lombokName.setSourceRange(start, end - start + 1); setIndex(lombokName, 1); setIndex(valName, 2); QualifiedName fullName = ast.newQualifiedName(lombokName, valName); setIndex(fullName, 1); fullName.setSourceRange(start, end - start + 1); out.setTypeName(fullName); } out.setSourceRange(start, end - start + 1); } return out; }
From source file:org.eclipse.jdt.core.dom.ASTConverter.java
License:Open Source License
protected QualifiedName setQualifiedNameNameAndSourceRanges(char[][] typeName, long[] positions, org.eclipse.jdt.internal.compiler.ast.ASTNode node) { int length = typeName.length; final SimpleName firstToken = new SimpleName(this.ast); firstToken.internalSetIdentifier(new String(typeName[0])); firstToken.index = 1;//from w w w. j a v a2s . co m int start0 = (int) (positions[0] >>> 32); int start = start0; int end = (int) (positions[0] & 0xFFFFFFFF); firstToken.setSourceRange(start, end - start + 1); final SimpleName secondToken = new SimpleName(this.ast); secondToken.internalSetIdentifier(new String(typeName[1])); secondToken.index = 2; start = (int) (positions[1] >>> 32); end = (int) (positions[1] & 0xFFFFFFFF); secondToken.setSourceRange(start, end - start + 1); QualifiedName qualifiedName = new QualifiedName(this.ast); qualifiedName.setQualifier(firstToken); qualifiedName.setName(secondToken); if (this.resolveBindings) { recordNodes(qualifiedName, node); recordPendingNameScopeResolution(qualifiedName); recordNodes(firstToken, node); recordNodes(secondToken, node); recordPendingNameScopeResolution(firstToken); recordPendingNameScopeResolution(secondToken); } qualifiedName.index = 2; qualifiedName.setSourceRange(start0, end - start0 + 1); SimpleName newPart = null; for (int i = 2; i < length; i++) { newPart = new SimpleName(this.ast); newPart.internalSetIdentifier(new String(typeName[i])); newPart.index = i + 1; start = (int) (positions[i] >>> 32); end = (int) (positions[i] & 0xFFFFFFFF); newPart.setSourceRange(start, end - start + 1); QualifiedName qualifiedName2 = new QualifiedName(this.ast); qualifiedName2.setQualifier(qualifiedName); qualifiedName2.setName(newPart); qualifiedName = qualifiedName2; qualifiedName.index = newPart.index; qualifiedName.setSourceRange(start0, end - start0 + 1); if (this.resolveBindings) { recordNodes(qualifiedName, node); recordNodes(newPart, node); recordPendingNameScopeResolution(qualifiedName); recordPendingNameScopeResolution(newPart); } } QualifiedName name = qualifiedName; if (this.resolveBindings) { recordNodes(name, node); recordPendingNameScopeResolution(name); } return name; }
From source file:org.eclipse.jdt.core.dom.ASTConverter.java
License:Open Source License
protected QualifiedName setQualifiedNameNameAndSourceRanges(char[][] typeName, long[] positions, int endingIndex, org.eclipse.jdt.internal.compiler.ast.ASTNode node) { int length = endingIndex + 1; final SimpleName firstToken = new SimpleName(this.ast); firstToken.internalSetIdentifier(new String(typeName[0])); firstToken.index = 1;//from w w w . jav a 2 s . co m int start0 = (int) (positions[0] >>> 32); int start = start0; int end = (int) positions[0]; firstToken.setSourceRange(start, end - start + 1); final SimpleName secondToken = new SimpleName(this.ast); secondToken.internalSetIdentifier(new String(typeName[1])); secondToken.index = 2; start = (int) (positions[1] >>> 32); end = (int) positions[1]; secondToken.setSourceRange(start, end - start + 1); QualifiedName qualifiedName = new QualifiedName(this.ast); qualifiedName.setQualifier(firstToken); qualifiedName.setName(secondToken); if (this.resolveBindings) { recordNodes(qualifiedName, node); recordPendingNameScopeResolution(qualifiedName); recordNodes(firstToken, node); recordNodes(secondToken, node); recordPendingNameScopeResolution(firstToken); recordPendingNameScopeResolution(secondToken); } qualifiedName.index = 2; qualifiedName.setSourceRange(start0, end - start0 + 1); SimpleName newPart = null; for (int i = 2; i < length; i++) { newPart = new SimpleName(this.ast); newPart.internalSetIdentifier(new String(typeName[i])); newPart.index = i + 1; start = (int) (positions[i] >>> 32); end = (int) positions[i]; newPart.setSourceRange(start, end - start + 1); QualifiedName qualifiedName2 = new QualifiedName(this.ast); qualifiedName2.setQualifier(qualifiedName); qualifiedName2.setName(newPart); qualifiedName = qualifiedName2; qualifiedName.index = newPart.index; qualifiedName.setSourceRange(start0, end - start0 + 1); if (this.resolveBindings) { recordNodes(qualifiedName, node); recordNodes(newPart, node); recordPendingNameScopeResolution(qualifiedName); recordPendingNameScopeResolution(newPart); } } if (newPart == null && this.resolveBindings) { recordNodes(qualifiedName, node); recordPendingNameScopeResolution(qualifiedName); } return qualifiedName; }