List of usage examples for org.eclipse.jdt.core.compiler ITerminalSymbols TokenNameprotected
int TokenNameprotected
To view the source code for org.eclipse.jdt.core.compiler ITerminalSymbols TokenNameprotected.
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 . j ava 2 s . c om*/ 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.j2eespider.util.AnnotationUtil.java
License:Open Source License
/** * Replace annotations in method./*from w w w . j ava2s . c om*/ */ 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) { } }