use of org.eclipse.jdt.core.dom.TypeDeclaration in project AutoRefactor by JnRouvignac.
the class AndroidViewHolderRefactoring method createViewHolderItemClass.
private TypeDeclaration createViewHolderItemClass(FindViewByIdVisitor findViewByIdVisitor, SimpleName typeName, TypeNameDecider typeNameDecider) {
final ASTBuilder b = this.ctx.getASTBuilder();
TypeDeclaration result = b.getAST().newTypeDeclaration();
modifiers(result).addAll(asList(b.private0(), b.static0()));
result.setName(typeName);
List<BodyDeclaration> viewItemsFieldDecls = bodyDeclarations(result);
for (FindViewByIdVisitor.FindViewByIdItem item : findViewByIdVisitor.items) {
viewItemsFieldDecls.add(item.toFieldDecl(b, typeNameDecider));
}
return result;
}
use of org.eclipse.jdt.core.dom.TypeDeclaration in project liferay-ide by liferay.
the class MigrateProjectHandler method _shouldSearch.
@SuppressWarnings("deprecation")
private boolean _shouldSearch(File file) {
String path = file.getAbsolutePath().replaceAll("\\\\", "/");
if (path.contains("WEB-INF/classes") || path.contains("WEB-INF/service") || ValidationUtil.isProjectTargetDirFile(file)) {
return false;
}
if (path.endsWith("java")) {
CompilationUnit ast = CUCache.getCU(file, FileUtil.readContents(file).toCharArray());
Name superClass = ((TypeDeclaration) ast.types().get(0)).getSuperclass();
if (superClass != null) {
return !_checkClassIgnore(ast, superClass.toString());
}
List<ASTNode> interfaces = ((TypeDeclaration) ast.types().get(0)).superInterfaces();
if (interfaces != null) {
for (ASTNode n : interfaces) {
String name = n.toString();
if (_checkClassIgnore(ast, name)) {
return false;
}
}
}
}
return true;
}
use of org.eclipse.jdt.core.dom.TypeDeclaration in project liferay-ide by liferay.
the class JavaFileJDT method findSuperClass.
@Override
public List<SearchResult> findSuperClass(String superClassName) {
List<SearchResult> searchResults = new ArrayList<>();
_ast.accept(new ASTVisitor() {
@Override
public boolean visit(TypeDeclaration node) {
ITypeBinding superClass = null;
if (node.resolveBinding() != null) {
superClass = node.resolveBinding().getSuperclass();
if (superClass != null) {
String searchContext = superClass.getName();
if (searchContext.equals(superClassName)) {
int startLine = _ast.getLineNumber(node.getName().getStartPosition());
int startOffset = node.getName().getStartPosition();
int endLine = _ast.getLineNumber(node.getName().getStartPosition() + node.getName().getLength());
int endOffset = node.getName().getStartPosition() + node.getName().getLength();
searchResults.add(createSearchResult(searchContext, startOffset, endOffset, startLine, endLine, true));
}
}
}
return true;
}
});
return searchResults;
}
use of org.eclipse.jdt.core.dom.TypeDeclaration in project eclipse.jdt.ls by eclipse.
the class QuickAssistProcessor method getUniqueMethodName.
private static String getUniqueMethodName(ASTNode astNode, String suggestedName) throws JavaModelException {
while (astNode != null && !(astNode instanceof TypeDeclaration)) {
astNode = astNode.getParent();
}
if (astNode instanceof TypeDeclaration) {
ITypeBinding typeBinding = ((TypeDeclaration) astNode).resolveBinding();
if (typeBinding == null) {
return suggestedName;
}
IType type = (IType) typeBinding.getJavaElement();
if (type == null) {
return suggestedName;
}
IMethod[] methods = type.getMethods();
int suggestedPostfix = 2;
String resultName = suggestedName;
while (suggestedPostfix < 1000) {
if (!hasMethod(methods, resultName)) {
return resultName;
}
resultName = suggestedName + suggestedPostfix++;
}
}
return suggestedName;
}
use of org.eclipse.jdt.core.dom.TypeDeclaration in project eclipse.jdt.ls by eclipse.
the class UnimplementedCodeFix method createCleanUp.
public static ICleanUpFix createCleanUp(CompilationUnit root, boolean addMissingMethod, boolean makeTypeAbstract, IProblemLocation[] problems) {
Assert.isLegal(!addMissingMethod || !makeTypeAbstract);
if (!addMissingMethod && !makeTypeAbstract) {
return null;
}
if (problems.length == 0) {
return null;
}
ArrayList<CompilationUnitRewriteOperation> operations = new ArrayList<>();
for (int i = 0; i < problems.length; i++) {
IProblemLocation problem = problems[i];
if (addMissingMethod) {
ASTNode typeNode = getSelectedTypeNode(root, problem);
if (typeNode != null && !isTypeBindingNull(typeNode)) {
operations.add(new AddUnimplementedMethodsOperation(typeNode));
}
} else {
ASTNode typeNode = getSelectedTypeNode(root, problem);
if (typeNode instanceof TypeDeclaration) {
operations.add(new MakeTypeAbstractOperation((TypeDeclaration) typeNode));
}
}
}
if (operations.size() == 0) {
return null;
}
String label;
if (addMissingMethod) {
label = CorrectionMessages.UnimplementedMethodsCorrectionProposal_description;
} else {
label = CorrectionMessages.UnimplementedCodeFix_MakeAbstractFix_label;
}
return new UnimplementedCodeFix(label, root, operations.toArray(new CompilationUnitRewriteOperation[operations.size()]));
}
Aggregations