List of usage examples for org.objectweb.asm Opcodes ACC_PROTECTED
int ACC_PROTECTED
To view the source code for org.objectweb.asm Opcodes ACC_PROTECTED.
Click Source Link
From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java
License:Apache License
protected void fieldDef(AST fieldDef) { List<AnnotationNode> annotations = new ArrayList<>(); AST node = fieldDef.getFirstChild(); int modifiers = 0; if (isType(MODIFIERS, node)) { modifiers = modifiers(node, annotations, modifiers); node = node.getNextSibling();/*from w w w .j av a 2 s . c o m*/ } if (classNode.isInterface()) { modifiers |= Opcodes.ACC_STATIC | Opcodes.ACC_FINAL; if ((modifiers & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED)) == 0) { modifiers |= Opcodes.ACC_PUBLIC; } } ClassNode type = null; if (isType(TYPE, node)) { type = makeTypeWithArguments(node); node = node.getNextSibling(); } String name = identifier(node); node = node.getNextSibling(); Expression initialValue = null; if (node != null) { assertNodeType(ASSIGN, node); initialValue = expression(node.getFirstChild()); } if (classNode.isInterface() && initialValue == null && type != null) { initialValue = getDefaultValueForPrimitive(type); } FieldNode fieldNode = new FieldNode(name, modifiers, type, classNode, initialValue); fieldNode.addAnnotations(annotations); configureAST(fieldNode, fieldDef); if (!hasVisibility(modifiers)) { // let's set the modifiers on the field int fieldModifiers = 0; int flags = Opcodes.ACC_STATIC | Opcodes.ACC_TRANSIENT | Opcodes.ACC_VOLATILE | Opcodes.ACC_FINAL; if (!hasVisibility(modifiers)) { modifiers |= Opcodes.ACC_PUBLIC; fieldModifiers |= Opcodes.ACC_PRIVATE; } // let's pass along any other modifiers we need fieldModifiers |= (modifiers & flags); fieldNode.setModifiers(fieldModifiers); fieldNode.setSynthetic(true); // in the case that there is already a field, we would // like to use that field, instead of the default field // for the property FieldNode storedNode = classNode.getDeclaredField(fieldNode.getName()); if (storedNode != null && !classNode.hasProperty(name)) { fieldNode = storedNode; // we remove it here, because addProperty will add it // again and we want to avoid it showing up multiple // times in the fields list. classNode.getFields().remove(storedNode); } PropertyNode propertyNode = new PropertyNode(fieldNode, modifiers, null, null); configureAST(propertyNode, fieldDef); classNode.addProperty(propertyNode); } else { fieldNode.setModifiers(modifiers); // if there is a property of that name, then a field of that // name already exists, which means this new field here should // be used instead of the field the property originally has. PropertyNode pn = classNode.getProperty(name); if (pn != null && pn.getField().isSynthetic()) { classNode.getFields().remove(pn.getField()); pn.setField(fieldNode); } classNode.addField(fieldNode); } }
From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java
License:Apache License
protected int modifiers(AST modifierNode, List<AnnotationNode> annotations, int defaultModifiers) { assertNodeType(MODIFIERS, modifierNode); boolean access = false; int answer = 0; for (AST node = modifierNode.getFirstChild(); node != null; node = node.getNextSibling()) { int type = node.getType(); switch (type) { case STATIC_IMPORT: // ignore break; // annotations case ANNOTATION: annotations.add(annotation(node)); break; // core access scope modifiers case LITERAL_private: answer = setModifierBit(node, answer, Opcodes.ACC_PRIVATE); access = setAccessTrue(node, access); break; case LITERAL_protected: answer = setModifierBit(node, answer, Opcodes.ACC_PROTECTED); access = setAccessTrue(node, access); break; case LITERAL_public: answer = setModifierBit(node, answer, Opcodes.ACC_PUBLIC); access = setAccessTrue(node, access); break; // other modifiers case ABSTRACT: answer = setModifierBit(node, answer, Opcodes.ACC_ABSTRACT); break; case FINAL: answer = setModifierBit(node, answer, Opcodes.ACC_FINAL); break; case LITERAL_native: answer = setModifierBit(node, answer, Opcodes.ACC_NATIVE); break; case LITERAL_static: answer = setModifierBit(node, answer, Opcodes.ACC_STATIC); break; case STRICTFP: answer = setModifierBit(node, answer, Opcodes.ACC_STRICT); break; case LITERAL_synchronized: answer = setModifierBit(node, answer, Opcodes.ACC_SYNCHRONIZED); break; case LITERAL_transient: answer = setModifierBit(node, answer, Opcodes.ACC_TRANSIENT); break; case LITERAL_volatile: answer = setModifierBit(node, answer, Opcodes.ACC_VOLATILE); break; default:/*from w w w .java 2 s . co m*/ unknownAST(node); } } if (!access) { answer |= defaultModifiers; // ACC_SYNTHETIC isn't used here, use it as a special flag if (defaultModifiers == Opcodes.ACC_PUBLIC) answer |= Opcodes.ACC_SYNTHETIC; } return answer; }
From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java
License:Apache License
/** * Returns true if the modifiers flags contain a visibility modifier *//*from w w w.j av a2 s . c o m*/ protected boolean hasVisibility(int modifiers) { return (modifiers & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC)) != 0; }
From source file:org.codehaus.groovy.eclipse.codeassist.creators.FieldProposalCreator.java
License:Apache License
/** * find the most accessible element// ww w . j a v a2 s . c o m */ private boolean leftIsMoreAccessible(FieldNode field, FieldNode existing) { int leftAcc; switch (field.getModifiers() & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED)) { case Opcodes.ACC_PUBLIC: leftAcc = 0; break; case Opcodes.ACC_PROTECTED: leftAcc = 1; break; case Opcodes.ACC_PRIVATE: leftAcc = 3; break; default: // package default leftAcc = 2; break; } int rightAcc; switch (existing.getModifiers() & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED)) { case Opcodes.ACC_PUBLIC: rightAcc = 0; break; case Opcodes.ACC_PROTECTED: rightAcc = 1; break; case Opcodes.ACC_PRIVATE: rightAcc = 3; break; default: // package default rightAcc = 2; break; } return leftAcc < rightAcc; }
From source file:org.codehaus.groovy.eclipse.codeassist.proposals.AbstractGroovyProposal.java
License:Apache License
/** * Use {@link ProposalUtils#getImage(CompletionProposal)} instead * * @param node/*from w w w . jav a2 s .co m*/ * @return */ @Deprecated protected Image getImageFor(ASTNode node) { if (node instanceof FieldNode) { int mods = ((FieldNode) node).getModifiers(); if (test(mods, Opcodes.ACC_PUBLIC)) { return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PUBLIC); } else if (test(mods, Opcodes.ACC_PROTECTED)) { return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PROTECTED); } else if (test(mods, Opcodes.ACC_PRIVATE)) { return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PRIVATE); } return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_DEFAULT); } else if (node instanceof PropertyNode) { // property nodes are not really used any more. int mods = ((PropertyNode) node).getModifiers(); if (test(mods, Opcodes.ACC_PUBLIC)) { return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PUBLIC); } else if (test(mods, Opcodes.ACC_PROTECTED)) { return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PROTECTED); } else if (test(mods, Opcodes.ACC_PRIVATE)) { return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PRIVATE); } return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_DEFAULT); } return null; }
From source file:org.codehaus.groovy.eclipse.refactoring.test.extractMethod.ExtractMethodTestCase.java
License:Apache License
@Override public void simulateUserInput() { // set refactoring parameters int modifier = 0; String newMethodName = ""; try {/*from ww w.ja v a2s .c om*/ newMethodName = properties.get("newMethodName"); String mod = properties.get("modifier"); if (mod.equals("private")) modifier = Opcodes.ACC_PRIVATE; if (mod.equals("def")) modifier = Opcodes.ACC_PUBLIC; if (mod.equals("protected")) modifier = Opcodes.ACC_PROTECTED; } catch (Exception e) { e.printStackTrace(); fail("Initialisation of testproperties failed! " + e.getMessage()); } refactoring.setModifier(modifier); refactoring.setNewMethodname(newMethodName); setMoveParameter(refactoring); setRenameParameter(refactoring); }
From source file:org.codehaus.groovy.eclipse.refactoring.ui.extract.ExtractMethodPageContent.java
License:Apache License
private void setModifier(MouseEvent e) { if (e.getSource() instanceof Button) { Button selectedButton = (Button) e.getSource(); if (selectedButton.getText().equals(MODIFIER_PRIVATE)) extractMethodRefactoring.setModifier(Opcodes.ACC_PRIVATE); else if (selectedButton.getText().equals(MODIFIER_DEF)) extractMethodRefactoring.setModifier(Opcodes.ACC_PUBLIC); else if (selectedButton.getText().equals(MODIFIER_PROTECTED)) extractMethodRefactoring.setModifier(Opcodes.ACC_PROTECTED); else if (selectedButton.getText().equals(MODIFIER_NONE)) extractMethodRefactoring.setModifier(0); }//w w w . j a va 2s. co m }
From source file:org.codehaus.groovy.parser.antlr4.ASTBuilder.java
License:Apache License
public int parseVisibilityModifiers(TerminalNode modifier) { assert modifier.getSymbol().getType() == GroovyLangLexer.VISIBILITY_MODIFIER; if (DefaultGroovyMethods.isCase(PUBLIC, modifier.getSymbol().getText())) return Opcodes.ACC_PUBLIC; else if (DefaultGroovyMethods.isCase(PRIVATE, modifier.getSymbol().getText())) return Opcodes.ACC_PRIVATE; else if (DefaultGroovyMethods.isCase(PROTECTED, modifier.getSymbol().getText())) return Opcodes.ACC_PROTECTED; else/*ww w .j a va 2 s . c o m*/ throw new AssertionError(modifier.getSymbol().getText() + " is not a valid visibility modifier!"); }
From source file:org.codehaus.groovy.tools.javac.JavaStubGenerator.java
License:Apache License
private static void printModifiers(PrintWriter out, int modifiers) { if ((modifiers & Opcodes.ACC_PUBLIC) != 0) out.print("public "); if ((modifiers & Opcodes.ACC_PROTECTED) != 0) out.print("protected "); if ((modifiers & Opcodes.ACC_PRIVATE) != 0) out.print("private "); if ((modifiers & Opcodes.ACC_STATIC) != 0) out.print("static "); if ((modifiers & Opcodes.ACC_SYNCHRONIZED) != 0) out.print("synchronized "); if ((modifiers & Opcodes.ACC_FINAL) != 0) out.print("final "); if ((modifiers & Opcodes.ACC_ABSTRACT) != 0) out.print("abstract "); }
From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.java
License:Open Source License
/** * Build JDT TypeDeclarations for the groovy type declarations that were parsed from the source file. *///w w w. j a v a 2 s .c o m private void createTypeDeclarations(ModuleNode moduleNode) { List<ClassNode> moduleClassNodes = moduleNode.getClasses(); List<TypeDeclaration> typeDeclarations = new ArrayList<TypeDeclaration>(); Map<ClassNode, TypeDeclaration> fromClassNodeToDecl = new HashMap<ClassNode, TypeDeclaration>(); char[] mainName = toMainName(compilationResult.getFileName()); boolean isInner = false; List<ClassNode> classNodes = null; classNodes = moduleClassNodes; Map<ClassNode, List<TypeDeclaration>> innersToRecord = new HashMap<ClassNode, List<TypeDeclaration>>(); for (ClassNode classNode : classNodes) { if (!classNode.isPrimaryClassNode()) { continue; } GroovyTypeDeclaration typeDeclaration = new GroovyTypeDeclaration(compilationResult, classNode); typeDeclaration.annotations = transformAnnotations(classNode.getAnnotations()); // FIXASC duplicates code further down, tidy this up if (classNode instanceof InnerClassNode) { InnerClassNode innerClassNode = (InnerClassNode) classNode; ClassNode outerClass = innerClassNode.getOuterClass(); String outername = outerClass.getNameWithoutPackage(); String newInner = innerClassNode.getNameWithoutPackage().substring(outername.length() + 1); typeDeclaration.name = newInner.toCharArray(); isInner = true; } else { typeDeclaration.name = classNode.getNameWithoutPackage().toCharArray(); isInner = false; } // classNode.getInnerClasses(); // classNode. boolean isInterface = classNode.isInterface(); int mods = classNode.getModifiers(); if ((mods & Opcodes.ACC_ENUM) != 0) { // remove final mods = mods & ~Opcodes.ACC_FINAL; } // FIXASC should this modifier be set? // mods |= Opcodes.ACC_PUBLIC; // FIXASC should not do this for inner classes, just for top level types // FIXASC does this make things visible that shouldn't be? mods = mods & ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED); if (!isInner) { if ((mods & Opcodes.ACC_STATIC) != 0) { mods = mods & ~(Opcodes.ACC_STATIC); } } typeDeclaration.modifiers = mods & ~(isInterface ? Opcodes.ACC_ABSTRACT : 0); if (!(classNode instanceof InnerClassNode)) { if (!CharOperation.equals(typeDeclaration.name, mainName)) { typeDeclaration.bits |= ASTNode.IsSecondaryType; } } fixupSourceLocationsForTypeDeclaration(typeDeclaration, classNode); if (classNode.getGenericsTypes() != null) { GenericsType[] genericInfo = classNode.getGenericsTypes(); // Example case here: Foo<T extends Number & I> // the type parameter is T, the 'type' is Number and the bounds for the type parameter are just the extra bound // I. typeDeclaration.typeParameters = new TypeParameter[genericInfo.length]; for (int tp = 0; tp < genericInfo.length; tp++) { TypeParameter typeParameter = new TypeParameter(); typeParameter.name = genericInfo[tp].getName().toCharArray(); ClassNode[] upperBounds = genericInfo[tp].getUpperBounds(); if (upperBounds != null) { // FIXASC (M3) Positional info for these references? typeParameter.type = createTypeReferenceForClassNode(upperBounds[0]); typeParameter.bounds = (upperBounds.length > 1 ? new TypeReference[upperBounds.length - 1] : null); for (int b = 1, max = upperBounds.length; b < max; b++) { typeParameter.bounds[b - 1] = createTypeReferenceForClassNode(upperBounds[b]); typeParameter.bounds[b - 1].bits |= ASTNode.IsSuperType; } } typeDeclaration.typeParameters[tp] = typeParameter; } } boolean isEnum = (classNode.getModifiers() & Opcodes.ACC_ENUM) != 0; configureSuperClass(typeDeclaration, classNode.getSuperClass(), isEnum); configureSuperInterfaces(typeDeclaration, classNode); typeDeclaration.methods = createMethodAndConstructorDeclarations(classNode, isEnum, compilationResult); typeDeclaration.fields = createFieldDeclarations(classNode); typeDeclaration.properties = classNode.getProperties(); if (classNode instanceof InnerClassNode) { InnerClassNode innerClassNode = (InnerClassNode) classNode; ClassNode outerClass = innerClassNode.getOuterClass(); String outername = outerClass.getNameWithoutPackage(); String newInner = innerClassNode.getNameWithoutPackage().substring(outername.length() + 1); typeDeclaration.name = newInner.toCharArray(); // Record that we need to set the parent of this inner type later List<TypeDeclaration> inners = innersToRecord.get(outerClass); if (inners == null) { inners = new ArrayList<TypeDeclaration>(); innersToRecord.put(outerClass, inners); } inners.add(typeDeclaration); } else { typeDeclarations.add(typeDeclaration); } fromClassNodeToDecl.put(classNode, typeDeclaration); } // For inner types, now attach them to their parents. This was not done earlier as sometimes the types are processed in // such an order that inners are dealt with before outers for (Map.Entry<ClassNode, List<TypeDeclaration>> innersToRecordEntry : innersToRecord.entrySet()) { TypeDeclaration outerTypeDeclaration = fromClassNodeToDecl.get(innersToRecordEntry.getKey()); // Check if there is a problem locating the parent for the inner if (outerTypeDeclaration == null) { throw new GroovyEclipseBug( "Failed to find the type declaration for " + innersToRecordEntry.getKey().getName()); } List<TypeDeclaration> newInnersList = innersToRecordEntry.getValue(); outerTypeDeclaration.memberTypes = newInnersList.toArray(new TypeDeclaration[newInnersList.size()]); } types = typeDeclarations.toArray(new TypeDeclaration[typeDeclarations.size()]); }