/** Creates a new instance of Refactor */ public ElementsRenamer(WorkingCopy workingCopy, HashMap<? extends ElementHandle, String> handleAndNames) { this.workingCopy = workingCopy; make = workingCopy.getTreeMaker(); for(ElementHandle elemHandle : handleAndNames.keySet()){ Element elem = elemHandle.resolve(workingCopy); elementAndNames.put(elem, handleAndNames.get(elemHandle)); } }
private VariableElement getField(CompilationInfo cinfo, String name) { TypeElement typeElement = typeElementHandle.resolve(cinfo); for(VariableElement var : ElementFilter.fieldsIn(typeElement.getEnclosedElements())) { if(var.getSimpleName().toString().equals(name)) { return var; } } return null; }
/** Creates a new instance of Refactor */ public ElementsUsageFinder(CompilationInfo cinfo, HashMap<? extends ElementHandle, String> handleAndNames) { this.cinfo = cinfo; for (ElementHandle elemHandle : handleAndNames.keySet()) { Element elem = elemHandle.resolve(cinfo); elementAndNames.put(elem, handleAndNames.get(elemHandle)); } //To take care of VB expressions, Ex:- getValue(#{SessionBean1.personRowSet}) //renamePropertyBindingExpression(wc, name, newName); vbExpression = "#{" + getShortName() + "." + name + "}"; }
private ExecutableElement getConstructor(CompilationInfo cinfo, Class[] params) { TypeElement typeElement = typeElementHandle.resolve(cinfo); for(ExecutableElement method : ElementFilter.constructorsIn(typeElement.getEnclosedElements())) { if((params == null || matchTypes(cinfo, method.getParameters(), params))) { return method; } } return null; }
public Object run(CompilationInfo cinfo) { TypeElement typeElement = typeElementHandle.resolve(cinfo); TypeMirror superType = cinfo.getElements().getTypeElement(typeName).asType(); if(superType.getKind() == TypeKind.DECLARED && cinfo.getTypes().isSubtype(typeElement.asType(), superType)) { return Boolean.TRUE; } return Boolean.FALSE; } }, fObj);
boolean isAssignable( TypeElement element , CompilationController controller ){ TypeElement typeElement = getElementHandle().resolve(controller); if ( typeElement ==null ){ return false; } return controller.getTypes().isAssignable( typeElement.asType(), element.asType()); }
boolean isAssignableFrom( TypeElement element , CompilationController controller) { TypeElement typeElement = getElementHandle().resolve(controller); if ( typeElement ==null ){ return true; } return controller.getTypes().isAssignable( element.asType(), typeElement.asType()); }
public void requireCdiEnabled( Element element , WebBeansModel model){ ElementHandle<Element> handle = ElementHandle.create(element); Element resolved = handle.resolve( getInfo() ); if ( resolved == null ){ return; } requireCdiEnabled( resolved ); }
public void run( CompilationController compilationController) throws Exception { compilationController.toPhase(Phase.ELEMENTS_RESOLVED); Element element = myElementHandle.resolve(compilationController); setJavaDoc(ElementJavadoc.create(compilationController, element)); } }, true);
public Object run(WorkingCopy wc) { ExecutableElement execElement = methodElementHandle.resolve(wc); TypeElement typeElement = typeElementHandle.resolve(wc); ClassTree ctree = wc.getTrees().getTree(typeElement); ClassTree newctree = ctree; newctree = wc.getTreeMaker().removeClassMember(ctree, wc.getTrees().getTree(execElement)); wc.rewrite(ctree, newctree); return null; } }, fObj);
private void checkDecorators( TypeElement element, WebBeansModel model, Result result ) { Collection<TypeElement> decorators = model.getDecorators(element); if ( decorators!= null && decorators.size() >0 ){ EditorAnnotationsHelper helper = EditorAnnotationsHelper.getInstance(result); ElementHandle<TypeElement> handle = ElementHandle.create(element); if ( helper != null ){ helper.addDecoratedBean( result , handle.resolve( result.getInfo() )); } } }
public Object run(WorkingCopy wc) { ExecutableElement execElement = execElementHandle.resolve(wc); MethodTree oldTree = wc.getTrees().getTree(execElement); Tree newTree = wc.getTreeMaker().setLabel(oldTree, name); wc.rewrite(oldTree, newTree); return null; } }, javaClass.getFileObject());
public Object run(WorkingCopy wc) { ExecutableElement execElement = execElementHandle.resolve(wc); BlockTree block = wc.getTrees().getTree(execElement).getBody(); TreePath treePath = TreeUtils.getTreePath(wc, block); new Refactor.ReturnStatementLiteralRenamer(wc, oldStr, newStr).scan(treePath, null); return null; } }, javaClass.getFileObject());
@Override public void run(CompilationController controller) throws Exception { controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED); Element element = handles[0].resolve(controller); Trees trees = controller.getTrees(); Tree tree = trees.getTree(element); SourcePositions sourcePositions = trees.getSourcePositions(); offset[0] = (int) sourcePositions.getStartPosition(controller.getCompilationUnit(), tree); } }, true);
@Override public void run(CompilationController controller) throws Exception { controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED); Element element = handles[0].resolve(controller); Trees trees = controller.getTrees(); Tree tree = trees.getTree(element); SourcePositions sourcePositions = trees.getSourcePositions(); offset[0] = (int) sourcePositions.getStartPosition(controller.getCompilationUnit(), tree); } }, true);
public Object run(WorkingCopy wc) { TreeMaker make = wc.getTreeMaker(); ExecutableElement elem = execElementHandle.resolve(wc);//javaClass.getMethod(wc, "_init", new Class[]{}); MethodInvocationTree methInvkTree = TreeMakerUtils.createMethodInvocation(wc, methodName, pNames); if(noreturn) { addMethodInvocationStatement(wc, wc.getTrees().getTree(elem), methInvkTree); }else { addReturnStatement(wc, wc.getTrees().getTree(elem), methInvkTree); } return null; } }, javaClass.getFileObject());
void addCleanupStatements(WorkingCopy wc, List<Bean> beans) { ExecutableElement elem = execElementHandle.resolve(wc); BlockTree oldBlockTree = wc.getTrees().getTree(elem).getBody(); BlockTree newBlockTree = oldBlockTree; for (Bean bean : beans) { if (bean.getCleanupMethod() != null) { newBlockTree = addStatement(wc, newBlockTree, bean.getName(), bean.getCleanupMethod(), null); } } wc.rewrite(oldBlockTree, newBlockTree); }
void removeCleanupStatements(WorkingCopy wc, List<Bean> beans) { ExecutableElement elem = execElementHandle.resolve(wc); BlockTree oldBlockTree = wc.getTrees().getTree(elem).getBody(); BlockTree newBlockTree = oldBlockTree; for (Bean bean : beans) { if (bean.getCleanupMethod() != null) { newBlockTree = removeStatement(wc, newBlockTree, bean.getName(), bean.getCleanupMethod()); } } wc.rewrite(oldBlockTree, newBlockTree); }
private void addPropertySetStatements(WorkingCopy wc, Bean bean, List<Property> props) { ExecutableElement elem = execElementHandle.resolve(wc); BlockTree oldBlockTree = wc.getTrees().getTree(elem).getBody(); BlockTree newBlockTree = oldBlockTree; for (Property prop : props) { newBlockTree = addStatement(wc, newBlockTree, bean.getName(), prop.getWriteMethodName(), prop.getValueSource()); prop.setInserted(true); } wc.rewrite(oldBlockTree, newBlockTree); }
public Object run(WorkingCopy wc) { TreeMaker make = wc.getTreeMaker(); ExecutableElement execElement = execElementHandle.resolve(wc); MethodTree methodTree = wc.getTrees().getTree(execElement); MethodTree newMethodTree = wc.getTreeMaker().Method(methodTree.getModifiers(), methodTree.getName(), methodTree.getReturnType(), methodTree.getTypeParameters(), methodTree.getParameters(), methodTree.getThrows(), "{" + bodyText + "}", (ExpressionTree)methodTree.getDefaultValue()); wc.rewrite(methodTree, newMethodTree); return null; } }, javaClass.getFileObject());