List of usage examples for org.eclipse.jdt.core.dom AST newAST
public static AST newAST(Map<String, String> options)
"org.eclipse.jdt.core.compiler.source"
indicates the api level and source compatibility mode (as per JavaCore
) - defaults to 1.3 "1.3"
means the source code is as per JDK 1.3 and api level #JLS3 ."1.4", "1.5", "1.6", "1.7" "1.8"
implies the respective source JDK levels 1.4, 1.5, 1.6, 1.7 and api level #JLS4 ."1.8"
implies the respective source JDK level 1.8 and api level #JLS8 ."9", "10", "11", "12" and "13"
implies the respective JDK levels 9, 10, 11, 12 and 13 and api levels #JLS9 , #JLS10 , #JLS11 , #JLS12 and #JLS13 ."org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures"
- indicates whether the preview is enabled or disabled legal values are "enabled"
and "disabled"
implying preview enabled and disabled respectively. From source file:astview.Binding.java
License:Open Source License
public static String getEscapedStringLiteral(String stringValue) { StringLiteral stringLiteral = AST.newAST(8).newStringLiteral(); stringLiteral.setLiteralValue(stringValue); return stringLiteral.getEscapedValue(); }
From source file:astview.Binding.java
License:Open Source License
public static String getEscapedCharLiteral(char charValue) { CharacterLiteral charLiteral = AST.newAST(8).newCharacterLiteral(); charLiteral.setCharValue(charValue); return charLiteral.getEscapedValue(); }
From source file:br.com.objectos.way.core.code.jdt.ASTFake.java
License:Apache License
public static TypeDeclaration newTypeDeclaration() { AST ast = AST.newAST(AST.JLS8); return ast.newTypeDeclaration(); }
From source file:br.com.objectos.way.core.code.jdt.ASTTest.java
License:Apache License
@SuppressWarnings("unchecked") public void stackoverflow_answer() { AST ast = AST.newAST(AST.JLS8); CompilationUnit cu = ast.newCompilationUnit(); PackageDeclaration p1 = ast.newPackageDeclaration(); p1.setName(ast.newSimpleName("foo")); cu.setPackage(p1);//w w w .j a va 2s .c o m ImportDeclaration id = ast.newImportDeclaration(); id.setName(ast.newName(new String[] { "java", "util", "Set" })); cu.imports().add(id); TypeDeclaration td = ast.newTypeDeclaration(); td.setName(ast.newSimpleName("Foo")); TypeParameter tp = ast.newTypeParameter(); tp.setName(ast.newSimpleName("X")); td.typeParameters().add(tp); cu.types().add(td); MethodDeclaration md = ast.newMethodDeclaration(); md.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD)); md.setName(ast.newSimpleName("bar")); SingleVariableDeclaration var = ast.newSingleVariableDeclaration(); var.setType(ast.newSimpleType(ast.newSimpleName("String"))); var.setName(ast.newSimpleName("a")); md.parameters().add(var); td.bodyDeclarations().add(md); Block block = ast.newBlock(); md.setBody(block); MethodInvocation mi = ast.newMethodInvocation(); mi.setName(ast.newSimpleName("x")); ExpressionStatement e = ast.newExpressionStatement(mi); block.statements().add(e); System.out.println(cu); }
From source file:br.com.objectos.way.core.code.jdt.CompilationUnitWriter.java
License:Apache License
public static CompilationUnitWriter atPackageOf(TypeInfo typeInfo) { AST ast = AST.newAST(AST.JLS8); CompilationUnit compilationUnit = ast.newCompilationUnit(); PackageInfo packageInfo = typeInfo.writePackage(compilationUnit); return new CompilationUnitWriter(compilationUnit, packageInfo); }
From source file:cideplus.ui.astview.Binding.java
License:Open Source License
public static String getEscapedStringLiteral(String stringValue) { StringLiteral stringLiteral = AST.newAST(AST.JLS3).newStringLiteral(); stringLiteral.setLiteralValue(stringValue); return stringLiteral.getEscapedValue(); }
From source file:cideplus.ui.astview.Binding.java
License:Open Source License
public static String getEscapedCharLiteral(char charValue) { CharacterLiteral charLiteral = AST.newAST(AST.JLS3).newCharacterLiteral(); charLiteral.setCharValue(charValue); return charLiteral.getEscapedValue(); }
From source file:com.android.ide.eclipse.adt.internal.actions.RenamePackageAction.java
License:Open Source License
private void promptNewName(final IProject project) { ManifestData manifestData = AndroidManifestHelper.parseForData(project); if (manifestData == null) { return;/*from ww w . j a v a 2 s.c om*/ } final String old_package_name_string = manifestData.getPackage(); final AST ast_validator = AST.newAST(AST.JLS3); mOldPackageName = ast_validator.newName(old_package_name_string); IInputValidator validator = new IInputValidator() { public String isValid(String newText) { try { ast_validator.newName(newText); } catch (IllegalArgumentException e) { return "Illegal package name."; } if (newText.equals(old_package_name_string)) return "No change."; else return null; } }; InputDialog dialog = new InputDialog(AdtPlugin.getDisplay().getActiveShell(), "Rename Application Package", "Enter new package name:", old_package_name_string, validator); if (dialog.open() == Window.OK) { mNewPackageName = ast_validator.newName(dialog.getValue()); initiateAndroidPackageRefactoring(project); } }
From source file:com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoringTest.java
License:Open Source License
protected void renamePackage(@NonNull IProject project, @NonNull String newName, @NonNull String expected) throws Exception { ManifestInfo info = ManifestInfo.get(project); String currentPackage = info.getPackage(); assertNotNull(currentPackage);// w ww . ja va 2s .co m final AST astValidator = AST.newAST(AST.JLS3); Name oldPackageName = astValidator.newName(currentPackage); Name newPackageName = astValidator.newName(newName); ApplicationPackageNameRefactoring refactoring = new ApplicationPackageNameRefactoring(project, oldPackageName, newPackageName); checkRefactoring(refactoring, expected); }
From source file:com.android.ide.eclipse.adt.internal.refactorings.renamepackage.RenamePackageAction.java
License:Open Source License
private void promptNewName(final IProject project) { ManifestData manifestData = AndroidManifestHelper.parseForData(project); if (manifestData == null) { return;/*from w w w. j a v a 2s.co m*/ } final String oldPackageNameString = manifestData.getPackage(); final AST astValidator = AST.newAST(AST.JLS3); Name oldPackageName = astValidator.newName(oldPackageNameString); IInputValidator validator = new IInputValidator() { @Override public String isValid(String newText) { try { astValidator.newName(newText); } catch (IllegalArgumentException e) { return "Illegal package name."; } if (newText.equals(oldPackageNameString)) return "No change."; else return null; } }; InputDialog dialog = new InputDialog(AdtPlugin.getShell(), "Rename Application Package", "Enter new package name:", oldPackageNameString, validator); if (dialog.open() == Window.OK) { Name newPackageName = astValidator.newName(dialog.getValue()); initiateAndroidPackageRefactoring(project, oldPackageName, newPackageName); } }