List of usage examples for org.eclipse.jdt.core.dom SimpleName getFullyQualifiedName
public final String getFullyQualifiedName()
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(SimpleName node) { boa.types.Ast.Expression.Builder b = boa.types.Ast.Expression.newBuilder(); // b.setPosition(pos.build()); b.setKind(boa.types.Ast.Expression.ExpressionKind.VARACCESS); b.setVariable(node.getFullyQualifiedName()); expressions.push(b.build());//from w w w. ja v a 2s . co m return false; }
From source file:ca.mcgill.cs.swevo.ppa.inference.FieldInferenceStrategy.java
License:Open Source License
public void makeSafeSecondary(ASTNode node, TypeFact typeFact) { SimpleName sName = (SimpleName) node; PPATypeRegistry typeRegistry = ppaEngine.getRegistry(); PPADefaultBindingResolver resolver = getResolver(sName); ASTNode newContainerNode = PPAASTUtil.getFieldContainer(node, true, false); ITypeBinding newContainer = PPABindingsUtil.getTypeBinding(newContainerNode); if (newContainer == null) { return;/*from w ww.j a v a 2 s. c om*/ } IVariableBinding varBinding = (IVariableBinding) sName.resolveBinding(); IVariableBinding newFieldBinding = null; if (PPABindingsUtil.isMissingType(newContainer)) { newFieldBinding = typeRegistry.getFieldBinding(varBinding.getName(), newContainer, varBinding.getType(), resolver); } else { // Maybe we can find the field declaration newFieldBinding = PPABindingsUtil.findFieldHierarchy(newContainer, sName.getFullyQualifiedName()); if (newFieldBinding == null) { // We did not find the field in the container, try to find a suitable container (missing type) ITypeBinding tempContainer = PPABindingsUtil.getFirstMissingSuperType(newContainer); if (tempContainer != null) { newContainer = tempContainer; newFieldBinding = typeRegistry.getFieldBinding(varBinding.getName(), newContainer, varBinding.getType(), resolver); } else { newFieldBinding = typeRegistry.getFieldBinding(varBinding.getName(), newContainer, varBinding.getType(), resolver); } } else { // In case we found the field in a super type of the container. newContainer = newFieldBinding.getDeclaringClass(); } } // Check field type ITypeBinding newFieldType = newFieldBinding.getType(); ITypeBinding oldFieldType = varBinding.getType(); if (!newFieldType.isEqualTo(oldFieldType)) { if (PPABindingsUtil.isSafer(newFieldType, oldFieldType)) { resolver.fixFieldBinding(sName, newFieldBinding); TypeFact tFact = new TypeFact(indexer.getMainIndex(sName), oldFieldType, TypeFact.UNKNOWN, newFieldType, TypeFact.EQUALS, TypeFact.FIELD_STRATEGY); ppaEngine.reportTypeFact(tFact); } else if (!PPABindingsUtil.isMissingType(newContainer)) { resolver.fixFieldBinding(sName, newFieldBinding); // This is the case where we found the field declaration and the field is "less" safe than the previous type. // XXX The oldType = Unknown is to ensure that the new type will be pushed. TypeFact tFact = new TypeFact(indexer.getMainIndex(sName), typeRegistry.getUnknownBinding(resolver), TypeFact.UNKNOWN, newFieldType, TypeFact.EQUALS, TypeFact.FIELD_STRATEGY); ppaEngine.reportTypeFact(tFact); } else { // This is an odd case: we found a ppa generated field, but the type we got before was safer. newFieldBinding = typeRegistry.getFieldBindingWithType(varBinding.getName(), newContainer, varBinding.getType(), resolver); resolver.fixFieldBinding(sName, newFieldBinding); } } else { resolver.fixFieldBinding(sName, newFieldBinding); } }
From source file:ca.mcgill.cs.swevo.ppa.PPAASTUtil.java
License:Open Source License
/** * <p>//from w w w . ja va 2 s . c o m * Returns the name + its qualifier if any. Does not return the suffix of * the FQN. * </p> * <ol> * <li>A : returns A</li> * <li>A.B : returns A</li> * <li>C.A : return C.A</li> * <li>C.A.B : returns C.A</li> * </ol> * * @param name * @return */ public static String getQualifierPlusName(SimpleName name) { String qualifierPlusName = name.getFullyQualifiedName(); ASTNode parent = name.getParent(); if (parent != null && parent instanceof QualifiedName) { QualifiedName qName = (QualifiedName) parent; if (qName.getName().equals(name)) { qualifierPlusName = qName.getFullyQualifiedName(); } } return qualifierPlusName; }
From source file:ch.uzh.ifi.seal.changedistiller.treedifferencing.Node.java
License:Apache License
/** * @param aNewName//from w ww .ja va2 s. c om * @param aOldName * @param aSrc */ public void setNewValue_localValDecl(SimpleName aNewName, SimpleName aOldName, String aSrc) { String oldName = aOldName.getFullyQualifiedName(); String newName = aNewName.getFullyQualifiedName(); int bgn14 = aOldName.getStartPosition(); int end14 = bgn14 + aOldName.getLength(); String value = getValue(); int bgn17 = getEntity().getStartPosition(); int end17 = getEntity().getEndPosition(); if (bgn17 < bgn14 && end14 < end17 && value.contains(oldName)) { String newSrcFirstPart = aSrc.substring(bgn17, bgn14); String newSrcLastPart = aSrc.substring(end14, end17 + 1); String newValue = newSrcFirstPart + newName + newSrcLastPart; mNewValue = newValue; } }
From source file:ch.uzh.ifi.seal.changedistiller.treedifferencing.Node.java
License:Apache License
/** * Sets the new value.//from w ww . jav a 2 s. c om * * @param aNewName * the a new name * @param aOldName * the a old name * @param aSrc * the a src */ @SuppressWarnings("unused") public void setNewValue(SimpleName aNewName, SimpleName aOldName, String aSrc) { String oldName = aOldName.getFullyQualifiedName(); String newName = aNewName.getFullyQualifiedName(); int bgn14 = aOldName.getStartPosition(); int end14 = bgn14 + aOldName.getLength(); String value = getValue(); int bgn17 = getEntity().getStartPosition(); int end17 = getEntity().getEndPosition(); // if (bgn17 <= bgn14 && end14 <= end17 && oldName.equals(value)) { // System.out.print(""); // } if (bgn17 <= bgn14 && end14 <= end17) { String newSrcFirstPart = aSrc.substring(bgn17, bgn14); String newSrcLastPart = aSrc.substring(end14, end17 + 1); String newValue = newSrcFirstPart + newName + newSrcLastPart; mNewValue = newValue; } }
From source file:ch.uzh.ifi.seal.changedistiller.treedifferencing.Node.java
License:Apache License
/** * @param aNewName//from w w w . ja v a2 s . c om * @param aOldName * @param aSrc */ @SuppressWarnings("unused") public void setNewValueForEachStmt(SimpleName aNewName, SimpleName aOldName, String aSrc) { String oldName = aOldName.getFullyQualifiedName(); String newName = aNewName.getFullyQualifiedName(); int bgn14 = aOldName.getStartPosition(); int end14 = bgn14 + aOldName.getLength(); String value = getValue(); int bgn17 = getEntity().getStartPosition(); int end17 = getEntity().getEndPosition(); int bgnPar17 = aSrc.indexOf("(", bgn17) + 1; int bgnBlock17 = aSrc.indexOf("{", bgn17); int endPar17 = aSrc.lastIndexOf(")", bgnBlock17); if (bgnPar17 <= bgn14 && end14 <= endPar17) { String forEachValue = aSrc.substring(bgnPar17, endPar17); String firstPart = aSrc.substring(bgnPar17, bgn14); String lastPart = aSrc.substring(end14, endPar17); String newValue = firstPart + newName + lastPart; mNewValue = newValue; } }
From source file:ch.uzh.ifi.seal.changedistiller.treedifferencing.Node.java
License:Apache License
/** * @param aNewName/*w w w .j av a 2 s .c o m*/ * @param aOldName * @param aSrc */ @SuppressWarnings("unused") public void setNewValueForStmt(SimpleName aNewName, SimpleName aOldName, String aSrc) { String oldName = aOldName.getFullyQualifiedName(); String newName = aNewName.getFullyQualifiedName(); int bgn14 = aOldName.getStartPosition(); int end14 = bgn14 + aOldName.getLength(); String value = getValue(); int bgn17 = getEntity().getStartPosition(); int end17 = getEntity().getEndPosition(); int bgnPar17 = aSrc.indexOf("(", bgn17) + 1; int bgnBlock17 = aSrc.indexOf("{", bgn17); int endPar17 = aSrc.lastIndexOf(")", bgnBlock17); int bgnSemicolon17 = aSrc.indexOf(";", bgnPar17) + 1; int endSemicolon17 = aSrc.lastIndexOf(";", endPar17); if (bgnSemicolon17 <= bgn14 && end14 <= endSemicolon17) { String forConditon = aSrc.substring(bgnSemicolon17, endSemicolon17); String firstPart = aSrc.substring(bgnSemicolon17, bgn14); String lastPart = aSrc.substring(end14, endSemicolon17); String newValue = "(" + firstPart + newName + lastPart + ")"; String newValueNoSpace = newValue.replaceAll("\\s", ""); mNewValue = newValueNoSpace; } }
From source file:ch.uzh.ifi.seal.changedistiller.treedifferencing.Node.java
License:Apache License
/** * @param aNewName//from ww w .j a va2s . com * @param aOldName * @param aSrc */ @SuppressWarnings("unused") public void setNewValueIfStmt(SimpleName aNewName, SimpleName aOldName, String aSrc) { String oldName = aOldName.getFullyQualifiedName(); String newName = aNewName.getFullyQualifiedName(); int bgn14 = aOldName.getStartPosition(); int end14 = bgn14 + aOldName.getLength(); String value = getValue(); int bgn17 = getEntity().getStartPosition(); int end17 = getEntity().getEndPosition(); int bgnPar17 = aSrc.indexOf("(", bgn17) + 1; int bgnBlock17 = aSrc.indexOf("{", bgn17); int endPar17 = aSrc.lastIndexOf(")", bgnBlock17); if (bgnPar17 <= bgn14 && end14 <= endPar17) { String ifValue = aSrc.substring(bgnPar17, endPar17); String firstPart = aSrc.substring(bgnPar17, bgn14); String lastPart = aSrc.substring(end14, endPar17); String newValue = firstPart + newName + lastPart; mNewValue = newValue; // ///////////////////////////////////////////////// Enumeration<?> e = preorderEnumeration(); while (e.hasMoreElements()) { Node iNode = (Node) e.nextElement(); if (iNode.isThenStmt() || iNode.isElseStmt()) { if (iNode.getValue().equals(this.mValue)) { iNode.setNewValue(this.mNewValue); } } } } }
From source file:changetypes.ASTVisitorAtomicChange.java
License:Open Source License
public boolean visit(SimpleName node) { if ((this.mtbStack.isEmpty()) && (!this.itbStack.isEmpty())) { return false; }/* w w w. j a va 2 s. c o m*/ if (!this.mtbStack.isEmpty()) { if (node.getIdentifier().equals("length")) { return false; } try { return visitName(node.resolveBinding(), (IMethodBinding) this.mtbStack.peek()); } catch (Exception localException) { System.err .println("Cannot resolve simple name \"" + node.getFullyQualifiedName().toString() + "\""); return false; } } return false; }
From source file:com.facebook.nuclide.shim.EclipseJavaElementShim.java
License:Open Source License
@Override public ISourceRange getNameRange() throws JavaModelException { if (_sourceRange != null) { return _sourceRange; }/* w w w . j a v a2 s . c o m*/ // We need to determine the location in the source at which this type // is declared. Compute an AST from the source file, and fine the declaring // node. ICompilationUnit unit = getCompilationUnit(); ASTParser parser = ASTParser.newParser(AST.JLS8); Map<String, String> options = JavaCore.getOptions(); JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options); parser.setCompilerOptions(options); try { parser.setSource(unit.getSource().toCharArray()); } catch (Exception ex) { return new SourceRange(0, 0); } final String targetName = fixTargetName(_refType.name()); CompilationUnit ast = (CompilationUnit) parser.createAST(null); ast.accept(new ASTVisitor(false) { public boolean visit(TypeDeclaration node) { SimpleName name = getNodeDeclName(node); if (name.getFullyQualifiedName().equals(targetName)) { _sourceRange = new SourceRange(name.getStartPosition(), name.getLength()); // No need to continue processing, we've found what we're looking for. return false; } return true; } }); if (_sourceRange != null) { return _sourceRange; } // Can't return null or the source generator will die. return new SourceRange(0, 1); }