List of usage examples for org.eclipse.jdt.core.compiler ITerminalSymbols TokenNamepublic
int TokenNamepublic
To view the source code for org.eclipse.jdt.core.compiler ITerminalSymbols TokenNamepublic.
Click Source Link
From source file:com.google.googlejavaformat.java.ModifierOrderer.java
License:Apache License
/** * Returns the {@link javax.lang.model.element.Modifier} for the given token id, or {@code null}. *//* w w w . ja va2 s . com*/ static Modifier getModifier(int tokenId) { switch (tokenId) { case ITerminalSymbols.TokenNamepublic: return Modifier.PUBLIC; case ITerminalSymbols.TokenNameprotected: return Modifier.PROTECTED; case ITerminalSymbols.TokenNameprivate: return Modifier.PRIVATE; case ITerminalSymbols.TokenNameabstract: return Modifier.ABSTRACT; case ITerminalSymbols.TokenNamestatic: return Modifier.STATIC; case ITerminalSymbols.TokenNamedefault: return Modifier.DEFAULT; case ITerminalSymbols.TokenNamefinal: return Modifier.FINAL; case ITerminalSymbols.TokenNametransient: return Modifier.TRANSIENT; case ITerminalSymbols.TokenNamevolatile: return Modifier.VOLATILE; case ITerminalSymbols.TokenNamesynchronized: return Modifier.SYNCHRONIZED; case ITerminalSymbols.TokenNamenative: return Modifier.NATIVE; case ITerminalSymbols.TokenNamestrictfp: return Modifier.STRICTFP; default: return null; } }
From source file:org.eclipse.reddeer.eclipse.ui.wizards.NewRedDeerTestWizardPageOne.java
License:Open Source License
private void addAnnotation(IType type) throws JavaModelException { ISourceRange range = type.getSourceRange(); IBuffer buf = type.getCompilationUnit().getBuffer(); char[] source = buf.getCharacters(); IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_8); scanner.setSource(source);//from w w w.j a va2 s . co m int offset = range.getOffset(); try { int token = scanner.getNextToken(); while (token != ITerminalSymbols.TokenNameEOF) { if (token == ITerminalSymbols.TokenNamepublic) { offset = scanner.getCurrentTokenStartPosition(); break; } token = scanner.getNextToken(); } } catch (InvalidInputException e) { Activator.log(e); } StringBuffer sb = new StringBuffer(); sb.append("@RunWith(RedDeerSuite.class)").append(getPackageFragment().findRecommendedLineSeparator()); buf.replace(offset, 0, sb.toString()); }
From source file:org.j2eespider.util.AnnotationUtil.java
License:Open Source License
/** * Replace annotations in method./*w w w. j av a 2s . c o m*/ */ public static void replaceAnnotationsInMethod(IMethod imethod, List<ValidatorType> annotations, String textNewAnnotations) { try { //monta o scanner do metodo IBuffer methodBuffer = imethod.getOpenable().getBuffer(); ISourceRange sourceRange = imethod.getSourceRange(); ISourceRange javadocRange = null;//imethod.getJavadocRange(); ISourceRange nameRange = imethod.getNameRange(); IScanner scanner = null; // delay initialization if (sourceRange != null && nameRange != null) { if (scanner == null) { scanner = ToolFactory.createScanner(false, false, true, false); scanner.setSource(methodBuffer.getCharacters()); } scanner.resetTo(sourceRange.getOffset(), nameRange.getOffset()); } //apaga todas as annotations que esto em annotationsType e adiciona textNewAnnotations StringBuffer sourceMethod = new StringBuffer(); int tok = scanner.getNextToken(); while (tok != ITerminalSymbols.TokenNameprivate && tok != ITerminalSymbols.TokenNameprotected && tok != ITerminalSymbols.TokenNamepublic) { //loop nas annotations if (tok == ITerminalSymbols.TokenNameAT) { //encontrou o inicio de uma annotation StringBuffer thisAnnotation = new StringBuffer("@"); tok = scanner.getNextToken(); //trabalha todo o contedo da annotation while (tok != ITerminalSymbols.TokenNameAT && tok != ITerminalSymbols.TokenNameprivate && tok != ITerminalSymbols.TokenNameprotected && tok != ITerminalSymbols.TokenNamepublic) { //pega todo o conteudo desta annotation thisAnnotation.append(scanner.getCurrentTokenSource()); //pega o nome dessa annotation tok = scanner.getNextToken(); } //verifica se para apagar essa annotation (s joga no novo sourceMethod se ela no tiver na lista que para apagar) if (!ValidatorUtil.containsValidator(annotations, thisAnnotation.toString())) { sourceMethod.append(thisAnnotation); } } } //grava o resto do metodo int posStartMethod = scanner.getCurrentTokenStartPosition(); int lengthRemoved = posStartMethod - sourceRange.getOffset(); //conta quantos caracteres foram removidos desse metodo (as annotations) String codeRemain = String.valueOf(scanner.getSource()).substring(posStartMethod, posStartMethod + sourceRange.getLength() - lengthRemoved); if (!sourceMethod.toString().equals("") && sourceMethod.toString().lastIndexOf("\n") != sourceMethod.toString().length() - 1) { //se j tem alguma annotation, ve se precisa de quebra de linha sourceMethod.append("\n\t"); } sourceMethod.append(textNewAnnotations); //adiciona as novas annotations antes do resto do mtodo sourceMethod.append(codeRemain); if (javadocRange != null) { //se tiver javadoc, no altera ele... methodBuffer.replace(sourceRange.getOffset() + javadocRange.getLength(), sourceRange.getLength() - javadocRange.getLength(), "\t" + sourceMethod.toString()); //altera o cdigo do mtodo } else { methodBuffer.replace(sourceRange.getOffset(), sourceRange.getLength(), sourceMethod.toString()); //altera o cdigo do mtodo } imethod.getOpenable().save(null, true); } catch (JavaModelException e) { } catch (InvalidInputException e) { } }
From source file:org.jboss.reddeer.eclipse.ui.wizards.NewRedDeerTestWizardPageOne.java
License:Open Source License
private void addAnnotation(IType type) throws JavaModelException { ISourceRange range = type.getSourceRange(); IBuffer buf = type.getCompilationUnit().getBuffer(); char[] source = buf.getCharacters(); IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_5); scanner.setSource(source);/*from ww w. j a v a2 s. co m*/ int offset = range.getOffset(); try { int token = scanner.getNextToken(); while (token != ITerminalSymbols.TokenNameEOF) { if (token == ITerminalSymbols.TokenNamepublic) { offset = scanner.getCurrentTokenStartPosition(); break; } token = scanner.getNextToken(); } } catch (InvalidInputException e) { Activator.log(e); } StringBuffer sb = new StringBuffer(); sb.append("@RunWith(RedDeerSuite.class)").append(getPackageFragment().findRecommendedLineSeparator()); buf.replace(offset, 0, sb.toString()); }
From source file:org.jboss.tools.arquillian.ui.internal.wizards.NewArquillianJUnitTestCasePageOne.java
License:Open Source License
@Override protected void createTypeMembers(IType type, ImportsManager imports, IProgressMonitor monitor) throws CoreException { if (fMethodStubsButtons.isSelected(IDX_DEPLOYMENT)) { String delimiter = getLineDelimiter(); NewArquillianJUnitTestCaseDeploymentPage deploymentPage = (NewArquillianJUnitTestCaseDeploymentPage) getWizard() .getPage(/*from w w w. j a va 2s . c o m*/ NewArquillianJUnitTestCaseDeploymentPage.ORG_JBOSS_TOOLS_ARQUILLIAN_UI_DEPLOYMENT_PAGE); ArquillianUIUtil.createDeploymentMethod(null, type, imports, isAddComments(), delimiter, deploymentPage, null, false); } if (fMethodStubsButtons.isSelected(IDX_SETUP_CLASS)) { createSetUpClass(type, imports); } if (fMethodStubsButtons.isSelected(IDX_TEARDOWN_CLASS)) { createTearDownClass(type, imports); } if (fMethodStubsButtons.isSelected(IDX_SETUP)) { createSetUp(type, imports); } if (fMethodStubsButtons.isSelected(IDX_TEARDOWN)) { createTearDown(type, imports); } createTestMethodStubs(type, imports); imports.addStaticImport("org.junit.Assert", "*", false); //$NON-NLS-1$ //$NON-NLS-2$ imports.addImport(ORG_JUNIT_RUNNER_RUNWITH); imports.addImport("org.jboss.arquillian.junit.Arquillian"); ISourceRange range = type.getSourceRange(); IBuffer buf = type.getCompilationUnit().getBuffer(); char[] source = buf.getCharacters(); IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_5); scanner.setSource(source); int offset = range.getOffset(); try { int token = scanner.getNextToken(); while (token != ITerminalSymbols.TokenNameEOF) { if (token == ITerminalSymbols.TokenNamepublic) { offset = scanner.getCurrentTokenStartPosition(); break; } token = scanner.getNextToken(); } } catch (InvalidInputException e) { ArquillianUIActivator.log(e); } StringBuffer sb = new StringBuffer(); sb.append("@RunWith(Arquillian.class)").append(getPackageFragment().findRecommendedLineSeparator()); buf.replace(offset, 0, sb.toString()); }