List of usage examples for org.eclipse.jdt.core.dom QualifiedName setQualifier
public void setQualifier(Name qualifier)
From source file:de.ovgu.cide.export.physical.ahead.MethodObjectHelper.java
License:Open Source License
/** * replaces all implicit access to "this" with explicit access (i.e. writes * a this. before every method invocation or field access where possible) * //from www . jav a2s .co m * * @param targetMethod * @param colorManager */ public static void makeThisAccessExplicit(final MethodDeclaration targetMethod) { final AST ast = targetMethod.getAST(); final TypeDeclaration thisClass = RefactoringUtils.getContainingType(targetMethod); targetMethod.accept(new ASTVisitor() { @Override public boolean visit(MethodInvocation node) { if (node.getExpression() == null) node.setExpression(ast.newThisExpression()); return super.visit(node); } @Override public boolean visit(FieldAccess node) { if (node.getExpression() == null) node.setExpression(ast.newThisExpression()); return super.visit(node); } @Override public void endVisit(SimpleName node) { if (node.getLocationInParent() == FieldAccess.NAME_PROPERTY) return; if (node.getLocationInParent() == QualifiedName.NAME_PROPERTY) return; IBinding binding = ((Name) node).resolveBinding(); if (binding instanceof IVariableBinding) { IVariableBinding vBinding = (IVariableBinding) binding; if (vBinding.isField()) { ITypeBinding bc = vBinding.getDeclaringClass(); if (thisClass.resolveBinding() == bc) { /* * workaround if a field access is represented by a * qualified name (this qualified name must be first * replaced by a field access */ if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY) { QualifiedName parent = (QualifiedName) node.getParent(); parent.setQualifier(ast.newSimpleName("notUsed")); FieldAccess fieldAccess = ast.newFieldAccess(); RefactoringUtils.replaceASTNode(parent, fieldAccess); fieldAccess.setExpression(node); fieldAccess.setName(ast.newSimpleName(parent.getName().getIdentifier())); } FieldAccess fieldAccess = ast.newFieldAccess(); RefactoringUtils.replaceASTNode(node, fieldAccess); fieldAccess.setExpression(ast.newThisExpression()); fieldAccess.setName(node); } } } } }); }
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. jav a2 s . c o 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 ww. ja v a 2s.c o 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; }
From source file:ptolemy.backtrack.eclipse.ast.transform.PackageRule.java
License:Open Source License
/** Add a prefix to the AST name node, and return the new AST name node. * * @param name The AST node of the name. * @param prefix The prefix to be added to the beginning of the name (not * including "." between the prefix and the name). * @return The new AST name node.//from w ww.j a v a 2s .c o m */ private Name _addPrefix(Name name, String prefix) { AST ast = name.getAST(); Name newName = null; // Coverity scan suggests that name cannot be null. while (name instanceof QualifiedName && !(((QualifiedName) name).getQualifier() instanceof SimpleName)) { name = ((QualifiedName) name).getQualifier(); } int lastPosition = prefix.length() - 1; while (lastPosition >= 0) { int dotPosition = prefix.lastIndexOf('.', lastPosition); String part = (dotPosition == -1) ? prefix.substring(0, lastPosition + 1) : prefix.substring(dotPosition + 1, lastPosition + 1); lastPosition = dotPosition - 1; if (name == null) { name = ast.newSimpleName(part); newName = name; } else if (name instanceof SimpleName) { name = ast.newQualifiedName(ast.newSimpleName(part), ast.newSimpleName(((SimpleName) name).getIdentifier())); newName = name; } else { QualifiedName qualifiedName = (QualifiedName) name; SimpleName leftPart = (SimpleName) qualifiedName.getQualifier(); qualifiedName.setQualifier( ast.newQualifiedName(ast.newSimpleName(part), ast.newSimpleName(leftPart.getIdentifier()))); name = qualifiedName.getQualifier(); } } return newName; }
From source file:refactorer.Refactorer.java
License:Apache License
protected void processName(Name name) { switch (name.getNodeType()) { case ASTNode.SIMPLE_NAME: break;/* w ww .j a v a 2s. co m*/ case ASTNode.QUALIFIED_NAME: QualifiedName qualifiedName = (QualifiedName) name; ITypeBinding typeBinding = qualifiedName.getQualifier().resolveTypeBinding(); if (typeBinding != null) { AST ast = qualifiedName.getAST(); String typeName = typeBinding.getQualifiedName(); if ("javax.media.opengl.GL".equals(typeName)) { qualifiedName.setQualifier(ast.newSimpleName("GL2")); addImportIfRequired("javax.media.opengl.GL2"); String constantName = qualifiedName.getName().getFullyQualifiedName(); if (constantName.endsWith("_EXT") || constantName.endsWith("_ARB")) { //GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT no longer exists, replace with int literal if ("GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT".equals(constantName)) { if (name.getParent().getNodeType() == ASTNode.SWITCH_CASE) { SwitchCase switchCase = (SwitchCase) name.getParent(); switchCase.setExpression(ast.newNumberLiteral("0x8CD8")); } } else if (!"GL_TEXTURE_MAX_ANISOTROPY_EXT".equals(constantName) && !"GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT".equals(constantName) && !"GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_EXT".equals(constantName) && !"GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT".equals(constantName)) { qualifiedName.setName( ast.newSimpleName(constantName.substring(0, constantName.length() - 4))); } } } else if ("com.sun.opengl.util.BufferUtil".equals(typeName)) { qualifiedName.setQualifier(ast.newSimpleName("Buffers")); } } break; } }