List of usage examples for org.eclipse.jdt.core.dom Modifier ABSTRACT
int ABSTRACT
To view the source code for org.eclipse.jdt.core.dom Modifier ABSTRACT.
Click Source Link
From source file:astview.Binding.java
License:Open Source License
private static StringBuffer getModifiersString(int flags, boolean isMethod) { StringBuffer sb = new StringBuffer().append("0x").append(Integer.toHexString(flags)).append(" ("); int prologLen = sb.length(); int rest = flags; rest &= ~appendFlag(sb, flags, Modifier.PUBLIC, "public "); rest &= ~appendFlag(sb, flags, Modifier.PRIVATE, "private "); rest &= ~appendFlag(sb, flags, Modifier.PROTECTED, "protected "); rest &= ~appendFlag(sb, flags, Modifier.STATIC, "static "); rest &= ~appendFlag(sb, flags, Modifier.FINAL, "final "); if (isMethod) { rest &= ~appendFlag(sb, flags, Modifier.SYNCHRONIZED, "synchronized "); rest &= ~appendFlag(sb, flags, Modifier.DEFAULT, "default "); } else {/* w w w . ja v a 2 s.c o m*/ rest &= ~appendFlag(sb, flags, Modifier.VOLATILE, "volatile "); rest &= ~appendFlag(sb, flags, Modifier.TRANSIENT, "transient "); } rest &= ~appendFlag(sb, flags, Modifier.NATIVE, "native "); rest &= ~appendFlag(sb, flags, Modifier.ABSTRACT, "abstract "); rest &= ~appendFlag(sb, flags, Modifier.STRICTFP, "strictfp "); if (rest != 0) sb.append("unknown:0x").append(Integer.toHexString(rest)).append(" "); int len = sb.length(); if (len != prologLen) sb.setLength(len - 1); sb.append(")"); return sb; }
From source file:com.google.devtools.j2objc.translate.AbstractMethodRewriter.java
License:Apache License
@Override public void endVisit(MethodDeclaration node) { if (Modifier.isAbstract(node.getModifiers())) { if (!TranslationUtil.needsReflection(node.getMethodBinding().getDeclaringClass())) { unit.setHasIncompleteProtocol(); unit.setHasIncompleteImplementation(); return; }/*from w w w . jav a 2s .c o m*/ Block body = new Block(); // Generate a body which throws a NSInvalidArgumentException. String bodyCode = "// can't call an abstract method\n" + "[self doesNotRecognizeSelector:_cmd];"; if (!typeEnv.isVoidType(node.getReturnType().getTypeBinding())) { bodyCode += "\nreturn 0;"; // Never executes, but avoids a gcc warning. } body.getStatements().add(new NativeStatement(bodyCode)); node.setBody(body); node.removeModifiers(Modifier.ABSTRACT); } }
From source file:com.google.devtools.j2objc.translate.MetadataWriter.java
License:Apache License
/** * Returns the modifiers for a specified type, including internal ones. * All class modifiers are defined in the JVM specification, table 4.1. *///from www .j a va 2s . co m private static int getTypeModifiers(ITypeBinding type) { int modifiers = type.getModifiers(); if (type.isInterface()) { modifiers |= java.lang.reflect.Modifier.INTERFACE | java.lang.reflect.Modifier.ABSTRACT | java.lang.reflect.Modifier.STATIC; } if (type.isSynthetic()) { modifiers |= BindingUtil.ACC_SYNTHETIC; } if (type.isAnnotation()) { modifiers |= BindingUtil.ACC_ANNOTATION; } if (type.isEnum()) { modifiers |= BindingUtil.ACC_ENUM; } if (type.isAnonymous()) { // Anonymous classes are always static, though their closure may include an instance. modifiers |= BindingUtil.ACC_ANONYMOUS | java.lang.reflect.Modifier.STATIC; } return modifiers; }
From source file:com.ibm.wala.cast.java.translator.jdt.JDT2CAstUtils.java
License:Open Source License
public static Collection<CAstQualifier> mapModifiersToQualifiers(int modifiers, boolean isInterface, boolean isAnnotation) { Set<CAstQualifier> quals = new LinkedHashSet<CAstQualifier>(); if (isInterface) quals.add(CAstQualifier.INTERFACE); if (isAnnotation) quals.add(CAstQualifier.ANNOTATION); if ((modifiers & Modifier.ABSTRACT) != 0) quals.add(CAstQualifier.ABSTRACT); if ((modifiers & Modifier.FINAL) != 0) quals.add(CAstQualifier.FINAL);//from w w w .j ava2 s . com if ((modifiers & Modifier.NATIVE) != 0) quals.add(CAstQualifier.NATIVE); // if (flags.isPackage()) quals.add(CAstQualifier.PACKAGE); if ((modifiers & Modifier.PRIVATE) != 0) quals.add(CAstQualifier.PRIVATE); if ((modifiers & Modifier.PROTECTED) != 0) quals.add(CAstQualifier.PROTECTED); if ((modifiers & Modifier.PUBLIC) != 0) quals.add(CAstQualifier.PUBLIC); if ((modifiers & Modifier.STATIC) != 0) quals.add(CAstQualifier.STATIC); if ((modifiers & Modifier.STRICTFP) != 0) quals.add(CAstQualifier.STRICTFP); if ((modifiers & Modifier.SYNCHRONIZED) != 0) quals.add(CAstQualifier.SYNCHRONIZED); if ((modifiers & Modifier.TRANSIENT) != 0) quals.add(CAstQualifier.TRANSIENT); if ((modifiers & Modifier.VOLATILE) != 0) quals.add(CAstQualifier.VOLATILE); return quals; }
From source file:com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.java
License:Open Source License
/** * @param inits Instance intializers & field initializers. Only used if method is a constructor, in which case the initializers * will be inserted in.//from ww w . j a v a 2s .co m */ private CAstEntity visit(MethodDeclaration n, ITypeBinding classBinding, WalkContext oldContext, ArrayList<ASTNode> inits) { // pass in memberEntities to the context, later visit(New) etc. may add classes final Map<CAstNode, CAstEntity> memberEntities = new LinkedHashMap<CAstNode, CAstEntity>(); final MethodContext context = new MethodContext(oldContext, memberEntities); // LEFTOUT: in polyglot there is a // class context in between method and // root CAstNode mdast; if (n.isConstructor()) mdast = createConstructorBody(n, classBinding, context, inits); else if ((n.getModifiers() & Modifier.ABSTRACT) != 0) // abstract mdast = null; else if (n.getBody() == null || n.getBody().statements().size() == 0) // empty mdast = makeNode(context, fFactory, n, CAstNode.RETURN); else mdast = visitNode(n.getBody(), context); // Polyglot comment: Presumably the MethodContext's parent is a ClassContext, // and he has the list of initializers. Hopefully the following // will glue that stuff in the right place in any constructor body. Set<CAstAnnotation> annotations = null; if (n.resolveBinding() != null) { annotations = handleAnnotations(n.resolveBinding()); } return new ProcedureEntity(mdast, n, classBinding, memberEntities, context, annotations); }
From source file:org.ebayopensource.dsf.javatojs.translate.TypeTranslator.java
License:Open Source License
private void processTypeSigniture(final AbstractTypeDeclaration abstractType, final JstType jstType) { if (jstType == null) { return;// www . ja v a2 s .c om } jstType.clearParams(); jstType.clearExtends(); jstType.clearSatisfies(); jstType.clearEnumValues(); if (abstractType instanceof TypeDeclaration) { List<TypeParameter> params = ((TypeDeclaration) abstractType).typeParameters(); for (TypeParameter p : params) { JstParamType pType = jstType.addParam(p.getName().toString()); if (pType == null) { continue; } for (Object b : p.typeBounds()) { if (b instanceof Type) { pType.addBound(getDataTypeTranslator().processType((Type) b, jstType)); } } } } String typeName = abstractType.getName().toString(); jstType.setSimpleName(typeName); TranslateCtx ctx = getCtx(); TranslateInfo tInfo = ctx.getTranslateInfo(jstType); if (abstractType instanceof TypeDeclaration) { TypeDeclaration astType = (TypeDeclaration) abstractType; if (astType.isInterface()) { jstType.setCategory(Category.INTERFACE); } else if ((astType.getModifiers() & Modifier.ABSTRACT) == Modifier.ABSTRACT) { jstType.getModifiers().setAbstract(); } // Extends Type type = astType.getSuperclassType(); if (type != null) { String typeFullName = jstType.getPackage().getName() + "." + type.toString(); IJstType baseType = JstCache.getInstance().getType(typeFullName, false); if (baseType == null) { baseType = getDataTypeTranslator().processType(type, jstType); } if (baseType != null) { tInfo.setBaseType(baseType); JstTypeReference extendRef = new JstTypeReference(baseType); extendRef.setSource(new JstSource(new AstBinding(type))); jstType.addExtend(extendRef); } } // Interfaces processSuperInterfaces(astType.superInterfaceTypes(), jstType); // add default vjo.Object extends if using NativeProxy if (usingNativeProxy(jstType)) { jstType.clearExtends(); jstType.addExtend(JstCache.getInstance().getType("vjo.Object")); } // Add default extend if none exists if (canAddDefaultExtendForClass(jstType)) { jstType.addExtend(JstCache.getInstance().getType("vjo.Object")); } } else if (abstractType instanceof EnumDeclaration) { jstType.setCategory(Category.ENUM); jstType.getModifiers().setFinal(); if (jstType.getParentNode() != null) { jstType.getModifiers().setStatic(true); } EnumDeclaration enumType = (EnumDeclaration) abstractType; // Interfaces processSuperInterfaces(enumType.superInterfaceTypes(), jstType); // Enum Constants FieldTranslator fieldTranslator = getCtx().getProvider().getFieldTranslator(); for (Object d : enumType.enumConstants()) { fieldTranslator.processEnumConstsDecl((EnumConstantDeclaration) d, jstType); } //Add default extend if none exists if (jstType.getExtend() == null) { jstType.addExtend(JstCache.getInstance().getType("vjo.Enum")); } } else { getLogger().logUnhandledNode(this, abstractType, jstType); } }
From source file:org.eclipse.ajdt.internal.ui.refactoring.pullout.PullOutRefactoring.java
License:Open Source License
@Override public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { RefactoringStatus status = new RefactoringStatus(); SubProgressMonitor submonitor = new SubProgressMonitor(pm, memberMap.keySet().size()); submonitor.beginTask("Checking preconditions...", memberMap.keySet().size()); try {/*from www. j a v a2 s . c o m*/ aspectChanges = new AspectRewrite(); // For a more predictable and orderly outcome, sort by the name of the CU ICompilationUnit[] cus = memberMap.keySet().toArray(new ICompilationUnit[0]); Arrays.sort(cus, CompilationUnitComparator.the); for (ICompilationUnit cu : cus) { ASTParser parser = ASTParser.newParser(AST.JLS8); parser.setSource(cu); parser.setResolveBindings(true); ASTNode cuNode = parser.createAST(pm); for (IMember member : memberMap.get(cu)) { BodyDeclaration memberNode = (BodyDeclaration) findASTNode(cuNode, member); ITDCreator itd = new ITDCreator(member, memberNode); if (member.getDeclaringType().isInterface()) { // No need to check "isAllowMakePublic" since technically it was already public. itd.addModifier(Modifier.PUBLIC); } if (itd.wasProtected()) { if (isAllowDeleteProtected()) { itd.removeModifier(Modifier.PROTECTED); } else { status.addWarning("moved member '" + member.getElementName() + "' is protected\n" + "protected ITDs are not allowed by AspectJ.\n", makeContext(member)); } } if (itd.wasAbstract()) { if (isGenerateAbstractMethodStubs()) { itd.removeModifier(Modifier.ABSTRACT); itd.setBody(getAbstractMethodStubBody(member)); } else { status.addWarning("moved member '" + member.getElementName() + "' is abstract.\n" + "abstract ITDs are not allowed by AspectJ.\n" + "You can enable the 'convert abstract methods' option to avoid this error.", makeContext(member)); //If you choose to ignore this error and perform refactoring anyway... // We make sure the abstract keyword is added to the itd, so you will get a compile error // and be forced to deal with that error. itd.addModifier(Modifier.ABSTRACT); } } checkOutgoingReferences(itd, status); checkIncomingReferences(itd, status); checkConctructorThisCall(itd, status); aspectChanges.addITD(itd, status); } submonitor.worked(1); } } catch (BadLocationException e) { status.merge(RefactoringStatus.createFatalErrorStatus("Internal error:" + e.getMessage())); } finally { submonitor.done(); } return status; }
From source file:org.eclipse.emf.test.tools.merger.ASTTest.java
License:Open Source License
@Test public void testRead() { String content = TestUtil.readFile(CLASS_FILE, false); ASTParser astParser = CodeGenUtil.EclipseUtil.newASTParser(); astParser.setSource(content.toCharArray()); CompilationUnit compilationUnit = (CompilationUnit) astParser.createAST(null); {/*from w w w . j ava 2s . c o m*/ Javadoc javadoc = (Javadoc) compilationUnit.getCommentList().get(0); assertEquals(1, javadoc.tags().size()); TagElement tagElement = (TagElement) javadoc.tags().get(0); assertEquals(7, tagElement.fragments().size()); // for (Iterator i = tagElement.fragments().iterator(); i.hasNext();) // { // TextElement element = (TextElement)i.next(); // System.out.println(element.getText()); // } } //** Package PackageDeclaration packageDeclaration = compilationUnit.getPackage(); assertNotNull(packageDeclaration); assertTrue(packageDeclaration.getName().isQualifiedName()); assertEquals("org.eclipse.emf.test.tools.merger", packageDeclaration.getName().getFullyQualifiedName()); //** Imports List<?> importDeclarations = compilationUnit.imports(); assertEquals(6, importDeclarations.size()); assertEquals("java.util.Collections", ((ImportDeclaration) importDeclarations.get(0)).getName().getFullyQualifiedName()); assertFalse(((ImportDeclaration) importDeclarations.get(0)).isOnDemand()); assertEquals("java.util.List", ((ImportDeclaration) importDeclarations.get(1)).getName().getFullyQualifiedName()); assertFalse(((ImportDeclaration) importDeclarations.get(1)).isOnDemand()); assertEquals("java.util.Map", ((ImportDeclaration) importDeclarations.get(2)).getName().getFullyQualifiedName()); assertFalse(((ImportDeclaration) importDeclarations.get(2)).isOnDemand()); assertEquals("org.eclipse.emf.common", ((ImportDeclaration) importDeclarations.get(3)).getName().getFullyQualifiedName()); assertTrue(((ImportDeclaration) importDeclarations.get(3)).isOnDemand()); assertEquals("org.eclipse.emf.common.notify.Notification", ((ImportDeclaration) importDeclarations.get(4)).getName().getFullyQualifiedName()); assertFalse(((ImportDeclaration) importDeclarations.get(4)).isOnDemand()); assertEquals("org.eclipse.emf.ecore.impl.EObjectImpl", ((ImportDeclaration) importDeclarations.get(5)).getName().getFullyQualifiedName()); assertFalse(((ImportDeclaration) importDeclarations.get(5)).isOnDemand()); //** Types List<?> typeDeclarations = compilationUnit.types(); assertEquals(2, typeDeclarations.size()); //** Class Example1 TypeDeclaration exampleClass = (TypeDeclaration) typeDeclarations.get(1); assertEquals("Example1", exampleClass.getName().getFullyQualifiedName()); assertFalse(exampleClass.isInterface()); //Javadoc { Javadoc typeJavadoc = exampleClass.getJavadoc(); assertEquals(4, typeJavadoc.tags().size()); @SuppressWarnings("unchecked") TagElement[] tagElements = (TagElement[]) typeJavadoc.tags() .toArray(new TagElement[typeJavadoc.tags().size()]); //Tag[0]: " This is an example to be parsed by the ASTTests.\n Not really important" assertNull(tagElements[0].getTagName()); assertEquals(2, tagElements[0].fragments().size()); assertEquals("This is an example of a fairly complete Java file.", ((TextElement) tagElements[0].fragments().get(0)).getText()); assertEquals("Its content is not really important", ((TextElement) tagElements[0].fragments().get(1)).getText()); //Tag[1]: "@author EMF team" assertEquals("@author", tagElements[1].getTagName()); assertEquals(1, tagElements[1].fragments().size()); assertEquals(" EMF team", ((TextElement) tagElements[1].fragments().get(0)).getText()); //Tag[2]: "@generated" assertEquals("@generated", tagElements[2].getTagName()); assertTrue(tagElements[2].fragments().isEmpty()); //Tag[3]: "@generated NOT" assertEquals("@generated", tagElements[3].getTagName()); assertEquals(1, tagElements[3].fragments().size()); assertEquals(" NOT", ((TextElement) tagElements[3].fragments().get(0)).getText()); } //Super Class assertTrue(exampleClass.getSuperclassType().isSimpleType()); assertEquals("EObjectImpl", ((SimpleType) exampleClass.getSuperclassType()).getName().getFullyQualifiedName()); //Interfaces assertTrue(exampleClass.superInterfaceTypes().isEmpty()); //Modifiers assertEquals(Modifier.PUBLIC, exampleClass.getModifiers()); //** Content of the Example1 class assertEquals(19, exampleClass.bodyDeclarations().size()); assertEquals(2, exampleClass.getTypes().length); assertEquals(7, exampleClass.getFields().length); assertEquals(7, exampleClass.getMethods().length); // Tests the order of the contents List<?> bodyDeclarations = exampleClass.bodyDeclarations(); assertTrue(bodyDeclarations.get(0).toString(), bodyDeclarations.get(0) instanceof TypeDeclaration); assertTrue(bodyDeclarations.get(1).toString(), bodyDeclarations.get(1) instanceof Initializer); assertTrue(bodyDeclarations.get(2).toString(), bodyDeclarations.get(2) instanceof FieldDeclaration); assertTrue(bodyDeclarations.get(3).toString(), bodyDeclarations.get(3) instanceof TypeDeclaration); assertTrue(bodyDeclarations.get(4).toString(), bodyDeclarations.get(4) instanceof FieldDeclaration); assertTrue(bodyDeclarations.get(5).toString(), bodyDeclarations.get(5) instanceof FieldDeclaration); assertTrue(bodyDeclarations.get(6).toString(), bodyDeclarations.get(6) instanceof FieldDeclaration); assertTrue(bodyDeclarations.get(7).toString(), bodyDeclarations.get(7) instanceof Initializer); assertTrue(bodyDeclarations.get(8).toString(), bodyDeclarations.get(8) instanceof MethodDeclaration); assertTrue(bodyDeclarations.get(8).toString(), bodyDeclarations.get(9) instanceof MethodDeclaration); assertTrue(bodyDeclarations.get(8).toString(), bodyDeclarations.get(10) instanceof MethodDeclaration); assertTrue(bodyDeclarations.get(9).toString(), bodyDeclarations.get(11) instanceof MethodDeclaration); assertTrue(bodyDeclarations.get(10).toString(), bodyDeclarations.get(12) instanceof FieldDeclaration); assertTrue(bodyDeclarations.get(11).toString(), bodyDeclarations.get(13) instanceof MethodDeclaration); assertTrue(bodyDeclarations.get(12).toString(), bodyDeclarations.get(14) instanceof MethodDeclaration); assertTrue(bodyDeclarations.get(13).toString(), bodyDeclarations.get(15) instanceof MethodDeclaration); assertTrue(bodyDeclarations.get(14).toString(), bodyDeclarations.get(16) instanceof Initializer); //** Initializers { Initializer initializer = (Initializer) bodyDeclarations.get(1); assertFalse(Modifier.isStatic(initializer.getModifiers())); assertNull(initializer.getJavadoc()); } // { Initializer initializer = (Initializer) bodyDeclarations.get(7); assertTrue(Modifier.isStatic(initializer.getModifiers())); assertNotNull(initializer.getJavadoc()); Javadoc javadoc = initializer.getJavadoc(); assertEquals(1, javadoc.tags().size()); assertEquals(1, ((TagElement) javadoc.tags().get(0)).fragments().size()); assertEquals("An static initializer", ((TextElement) ((TagElement) javadoc.tags().get(0)).fragments().get(0)).getText()); } // { Initializer initializer = (Initializer) bodyDeclarations.get(16); assertFalse(Modifier.isStatic(initializer.getModifiers())); assertNotNull(initializer.getJavadoc()); Javadoc javadoc = initializer.getJavadoc(); assertEquals(1, javadoc.tags().size()); assertEquals(2, ((TagElement) javadoc.tags().get(0)).fragments().size()); assertEquals("Another initializer with 2 lines", ((TextElement) ((TagElement) javadoc.tags().get(0)).fragments().get(0)).getText()); assertEquals("of javadoc.", ((TextElement) ((TagElement) javadoc.tags().get(0)).fragments().get(1)).getText()); } //** Inner Class TypeDeclaration innerClass = exampleClass.getTypes()[0]; assertFalse(innerClass.isInterface()); assertTrue(innerClass.bodyDeclarations().isEmpty()); assertEquals(Modifier.PUBLIC | Modifier.ABSTRACT, innerClass.getModifiers()); assertNull(innerClass.getSuperclassType()); assertEquals(2, innerClass.superInterfaceTypes().size()); assertTrue(((Type) innerClass.superInterfaceTypes().get(0)).isSimpleType()); assertEquals("Notification", ((SimpleType) innerClass.superInterfaceTypes().get(0)).getName().getFullyQualifiedName()); assertTrue(((Type) innerClass.superInterfaceTypes().get(1)).isSimpleType()); assertEquals("org.eclipse.emf.common.notify.Notifier", ((SimpleType) innerClass.superInterfaceTypes().get(1)).getName().getFullyQualifiedName()); assertNull(innerClass.getJavadoc()); //** Inner Interface TypeDeclaration innerInterface = exampleClass.getTypes()[1]; assertTrue(innerInterface.isInterface()); assertTrue(innerInterface.bodyDeclarations().isEmpty()); assertEquals(Modifier.PRIVATE | Modifier.STATIC, innerInterface.getModifiers()); assertNull(innerInterface.getSuperclassType()); assertEquals(1, innerInterface.superInterfaceTypes().size()); assertTrue(((Type) innerInterface.superInterfaceTypes().get(0)).isSimpleType()); assertEquals("Notification", ((SimpleType) innerInterface.superInterfaceTypes().get(0)).getName().getFullyQualifiedName()); assertNull(innerClass.getJavadoc()); //** Fields FieldDeclaration[] fieldDeclarations = exampleClass.getFields(); //fieldDeclarations[0]: public static final String STR_CONST = "something" { Javadoc javadoc = fieldDeclarations[0].getJavadoc(); assertEquals(1, javadoc.tags().size()); assertEquals(1, ((TagElement) javadoc.tags().get(0)).fragments().size()); assertEquals("public String constant.", ((TextElement) ((TagElement) javadoc.tags().get(0)).fragments().get(0)).getText()); // assertEquals(Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL, fieldDeclarations[0].getModifiers()); // assertTrue(fieldDeclarations[0].getType().isSimpleType()); assertEquals("String", ((SimpleType) fieldDeclarations[0].getType()).getName().getFullyQualifiedName()); // assertEquals(1, fieldDeclarations[0].fragments().size()); @SuppressWarnings("unchecked") VariableDeclarationFragment[] variableDeclarationFragments = (VariableDeclarationFragment[]) fieldDeclarations[0] .fragments().toArray(new VariableDeclarationFragment[fieldDeclarations[0].fragments().size()]); assertEquals(0, variableDeclarationFragments[0].getExtraDimensions()); assertEquals("STR_CONST", variableDeclarationFragments[0].getName().getFullyQualifiedName()); // assertNotNull(variableDeclarationFragments[0].getInitializer()); assertTrue(variableDeclarationFragments[0].getInitializer().getClass().getName(), variableDeclarationFragments[0].getInitializer() instanceof InfixExpression); InfixExpression infixExpression = (InfixExpression) variableDeclarationFragments[0].getInitializer(); assertTrue(infixExpression.getLeftOperand() instanceof StringLiteral); assertEquals("something is ; different \"//; /*;*/", ((StringLiteral) infixExpression.getLeftOperand()).getLiteralValue()); assertTrue(infixExpression.getRightOperand() instanceof StringLiteral); assertEquals(" !!;;", ((StringLiteral) infixExpression.getRightOperand()).getLiteralValue()); assertEquals("+", infixExpression.getOperator().toString()); } //fieldDeclarations[1]: protected static long longStatic = 1l { Javadoc javadoc = fieldDeclarations[1].getJavadoc(); assertEquals(1, javadoc.tags().size()); assertEquals(2, ((TagElement) javadoc.tags().get(0)).fragments().size()); assertEquals("protected static long field.", ((TextElement) ((TagElement) javadoc.tags().get(0)).fragments().get(0)).getText()); assertEquals("This is a multiline comment.", ((TextElement) ((TagElement) javadoc.tags().get(0)).fragments().get(1)).getText()); // assertEquals(Modifier.PROTECTED | Modifier.STATIC, fieldDeclarations[1].getModifiers()); // assertTrue(fieldDeclarations[1].getType().isPrimitiveType()); assertEquals(PrimitiveType.LONG, ((PrimitiveType) fieldDeclarations[1].getType()).getPrimitiveTypeCode()); // assertEquals(1, fieldDeclarations[1].fragments().size()); @SuppressWarnings("unchecked") VariableDeclarationFragment[] variableDeclarationFragments = (VariableDeclarationFragment[]) fieldDeclarations[1] .fragments().toArray(new VariableDeclarationFragment[fieldDeclarations[1].fragments().size()]); assertEquals(0, variableDeclarationFragments[0].getExtraDimensions()); assertEquals("longStatic", variableDeclarationFragments[0].getName().getFullyQualifiedName()); // assertNotNull(variableDeclarationFragments[0].getInitializer()); assertTrue(variableDeclarationFragments[0].getInitializer() instanceof NumberLiteral); assertEquals("1l", ((NumberLiteral) variableDeclarationFragments[0].getInitializer()).getToken()); } //fieldDeclarations[2]: Boolean booleanInstance { assertNull(fieldDeclarations[2].getJavadoc()); // assertEquals(0, fieldDeclarations[2].getModifiers()); // assertTrue(fieldDeclarations[2].getType().isSimpleType()); assertEquals("Boolean", ((SimpleType) fieldDeclarations[2].getType()).getName().getFullyQualifiedName()); // assertEquals(1, fieldDeclarations[2].fragments().size()); @SuppressWarnings("unchecked") VariableDeclarationFragment[] variableDeclarationFragments = (VariableDeclarationFragment[]) fieldDeclarations[2] .fragments().toArray(new VariableDeclarationFragment[fieldDeclarations[2].fragments().size()]); assertEquals(0, variableDeclarationFragments[0].getExtraDimensions()); assertEquals("booleanInstance", variableDeclarationFragments[0].getName().getFullyQualifiedName()); // assertNull(variableDeclarationFragments[0].getInitializer()); } //fieldDeclarations[3]: private Map.Entry myEntry { assertNull(fieldDeclarations[3].getJavadoc()); // assertEquals(Modifier.PRIVATE, fieldDeclarations[3].getModifiers()); // assertTrue(fieldDeclarations[3].getType().isSimpleType()); assertEquals("Map.Entry", ((SimpleType) fieldDeclarations[3].getType()).getName().getFullyQualifiedName()); // assertEquals(1, fieldDeclarations[3].fragments().size()); @SuppressWarnings("unchecked") VariableDeclarationFragment[] variableDeclarationFragments = (VariableDeclarationFragment[]) fieldDeclarations[3] .fragments().toArray(new VariableDeclarationFragment[fieldDeclarations[3].fragments().size()]); assertEquals(0, variableDeclarationFragments[0].getExtraDimensions()); assertEquals("myEntry", variableDeclarationFragments[0].getName().getFullyQualifiedName()); // assertNull(variableDeclarationFragments[0].getInitializer()); } //fieldDeclarations[4]: private int[][] myMatrix = new int[4][5] { assertNull(fieldDeclarations[4].getJavadoc()); // assertEquals(Modifier.PRIVATE, fieldDeclarations[4].getModifiers()); // assertTrue(fieldDeclarations[4].getType().isArrayType()); assertEquals(2, ((ArrayType) fieldDeclarations[4].getType()).getDimensions()); assertTrue(((ArrayType) fieldDeclarations[4].getType()).getElementType().isPrimitiveType()); assertEquals(PrimitiveType.INT, ((PrimitiveType) ((ArrayType) fieldDeclarations[4].getType()).getElementType()) .getPrimitiveTypeCode()); // assertEquals(1, fieldDeclarations[4].fragments().size()); @SuppressWarnings("unchecked") VariableDeclarationFragment[] variableDeclarationFragments = (VariableDeclarationFragment[]) fieldDeclarations[4] .fragments().toArray(new VariableDeclarationFragment[fieldDeclarations[4].fragments().size()]); assertEquals(0, variableDeclarationFragments[0].getExtraDimensions()); assertEquals("myMatrix", variableDeclarationFragments[0].getName().getFullyQualifiedName()); // assertNotNull(variableDeclarationFragments[0].getInitializer()); assertTrue(variableDeclarationFragments[0].getInitializer() instanceof ArrayCreation); ArrayCreation arrayCreation = (ArrayCreation) variableDeclarationFragments[0].getInitializer(); assertEquals(2, arrayCreation.dimensions().size()); assertEquals("4", ((NumberLiteral) arrayCreation.dimensions().get(0)).getToken()); assertEquals("5", ((NumberLiteral) arrayCreation.dimensions().get(1)).getToken()); } //** Methods MethodDeclaration[] methodDeclarations = exampleClass.getMethods(); //methodDeclarations[0]: public Example1() { Javadoc javadoc = methodDeclarations[0].getJavadoc(); assertEquals(1, javadoc.tags().size()); assertEquals(1, ((TagElement) javadoc.tags().get(0)).fragments().size()); assertEquals("This is a contructor", ((TextElement) ((TagElement) javadoc.tags().get(0)).fragments().get(0)).getText()); // assertTrue(methodDeclarations[0].isConstructor()); // assertEquals(Modifier.PUBLIC, methodDeclarations[0].getModifiers()); // assertNull(methodDeclarations[0].getReturnType2()); // assertEquals("Example1", methodDeclarations[0].getName().getFullyQualifiedName()); // assertTrue(methodDeclarations[0].parameters().isEmpty()); // assertNotNull(methodDeclarations[0].getBody()); assertEquals(1, methodDeclarations[0].getBody().statements().size()); Statement statement = (Statement) methodDeclarations[0].getBody().statements().get(0); assertEquals(ASTNode.SUPER_CONSTRUCTOR_INVOCATION, statement.getNodeType()); assertTrue(((SuperConstructorInvocation) statement).arguments().isEmpty()); } //methodDeclarations[2]: public void setBooleanInstance(Boolean b) { Javadoc javadoc = methodDeclarations[2].getJavadoc(); assertEquals(3, javadoc.tags().size()); assertNull(((TagElement) javadoc.tags().get(0)).getTagName()); assertEquals(1, ((TagElement) javadoc.tags().get(0)).fragments().size()); assertEquals("Sets the boolean instance.", ((TextElement) ((TagElement) javadoc.tags().get(0)).fragments().get(0)).getText()); assertEquals("@param", ((TagElement) javadoc.tags().get(1)).getTagName()); assertEquals(1, ((TagElement) javadoc.tags().get(0)).fragments().size()); assertEquals("b", ((SimpleName) ((TagElement) javadoc.tags().get(1)).fragments().get(0)).getFullyQualifiedName()); assertEquals("@generated", ((TagElement) javadoc.tags().get(2)).getTagName()); assertTrue(((TagElement) javadoc.tags().get(2)).fragments().isEmpty()); // assertFalse(methodDeclarations[2].isConstructor()); // assertEquals(Modifier.PUBLIC, methodDeclarations[2].getModifiers()); // assertNotNull(methodDeclarations[2].getReturnType2()); assertTrue(methodDeclarations[2].getReturnType2().isPrimitiveType()); assertEquals(PrimitiveType.VOID, ((PrimitiveType) methodDeclarations[2].getReturnType2()).getPrimitiveTypeCode()); // assertEquals("setBooleanInstance", methodDeclarations[2].getName().getFullyQualifiedName()); // assertEquals(1, methodDeclarations[2].parameters().size()); assertTrue(((SingleVariableDeclaration) methodDeclarations[2].parameters().get(0)).getType() .isSimpleType()); assertEquals("Boolean", ((SimpleType) ((SingleVariableDeclaration) methodDeclarations[2].parameters().get(0)).getType()) .getName().getFullyQualifiedName()); assertEquals("b", ((SingleVariableDeclaration) methodDeclarations[2].parameters().get(0)).getName() .getFullyQualifiedName()); // assertNotNull(methodDeclarations[2].getBody()); assertEquals(1, methodDeclarations[2].getBody().statements().size()); } }
From source file:org.eclipse.objectteams.otdt.internal.ui.bindingeditor.BindingEditor.java
License:Open Source License
public BindingEditor(final Composite parent, int style, final IType teamType, final CompilationUnit root) { super(parent, style); _team = teamType;// w w w . j a va2 s .c o m calculateRootNode(root); setLayout(new FormLayout()); final Group connDefGroup = new Group(this, SWT.NONE); connDefGroup.setText(Messages.BindingEditor_connector_title); final FormData formData = new FormData(); formData.bottom = new FormAttachment(58, 0); formData.right = new FormAttachment(100, -5); formData.top = new FormAttachment(0, 5); formData.left = new FormAttachment(0, 5); connDefGroup.setLayoutData(formData); connDefGroup.setLayout(new FormLayout()); _connTableViewer = new TreeViewer(connDefGroup, SWT.BORDER); _connTableViewer.setContentProvider(new TreeContentProvider()); _connTableViewer.setLabelProvider(new LabelProvider()); _connTableViewer.setAutoExpandLevel(2); _connTableTree = _connTableViewer.getTree(); final FormData formData_2 = new FormData(); formData_2.bottom = new FormAttachment(84, 0); formData_2.right = new FormAttachment(100, -5); formData_2.top = new FormAttachment(0, 5); formData_2.left = new FormAttachment(0, 5); _connTableTree.setLayoutData(formData_2); _connTableTree.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent evt) { bindingTableSelectionChanged(); } }); _connTableTree.setLinesVisible(true); _connTableTree.setHeaderVisible(true); final TreeColumn rolesCol = new TreeColumn(_connTableTree, SWT.NONE); rolesCol.setWidth(300); rolesCol.setText(Messages.BindingEditor_role_types_title); final TreeColumn methMapColumn = new TreeColumn(_connTableTree, SWT.NONE); methMapColumn.setWidth(80); final TreeColumn baseCol = new TreeColumn(_connTableTree, SWT.NONE); baseCol.setWidth(300); baseCol.setText(Messages.BindingEditor_base_types_title); // Note(SH): need all columns set before retrieving contents by setInput() _connTableViewer.setInput(_rootTeam); final Composite buttonComp = new Composite(connDefGroup, SWT.NONE); final FormData formData_3 = new FormData(); formData_3.bottom = new FormAttachment(100, -5); formData_3.right = new FormAttachment(100, -5); formData_3.top = new FormAttachment(_connTableTree, 5, SWT.BOTTOM); formData_3.left = new FormAttachment(_connTableTree, 0, SWT.LEFT); buttonComp.setLayoutData(formData_3); buttonComp.setLayout(new FormLayout()); final Button addConnBtn = new Button(buttonComp, SWT.NONE); final FormData formData_4 = new FormData(); formData_4.top = new FormAttachment(0, 5); formData_4.left = new FormAttachment(0, 5); addConnBtn.setLayoutData(formData_4); addConnBtn.setText(Messages.BindingEditor_add_type_binding_button); addConnBtn.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent evt) { IType roleClass = null; AddTypeBindingDialog dlg = AddTypeBindingDialog.create(parent.getShell(), teamType); if (AddTypeBindingDialog.OK == dlg.open()) { roleClass = dlg.getRoleType(); } else { return; } AST ast = _rootTeam.getAST(); RoleTypeDeclaration role = ast.newRoleTypeDeclaration(); role.setName(ast.newSimpleName(roleClass.getElementName())); role.setRole(true); try { int flags = roleClass.getFlags() & ~Modifier.ABSTRACT; role.modifiers().addAll(ast.newModifiers(flags)); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } String qualifiedBaseTypeName = dlg.getBaseTypeName(); String[] identifiers = qualifiedBaseTypeName.split("\\."); //$NON-NLS-1$ // use the single name for playedBy: int len = identifiers.length; String singleName = identifiers[len - 1]; role.setBaseClassType(ast.newSimpleType(ast.newName(singleName))); BindingEditor.this._baseClassLookup.put(singleName, qualifiedBaseTypeName); // add an import using the qualified name: _rootTeam.bodyDeclarations().add(role); ImportDeclaration baseImport = ast.newImportDeclaration(); baseImport.setBase(true); baseImport.setName(ast.newName(identifiers)); root.imports().add(baseImport); refresh(); _connTableViewer.setSelection(new StructuredSelection(role)); bindingTableSelectionChanged(); } }); final Button remConnBtn = new Button(buttonComp, SWT.NONE); final FormData formData_5 = new FormData(); formData_5.top = new FormAttachment(addConnBtn, 0, SWT.TOP); formData_5.left = new FormAttachment(addConnBtn, 5, SWT.RIGHT); remConnBtn.setLayoutData(formData_5); remConnBtn.setText(Messages.BindingEditor_remove_button); remConnBtn.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent evt) { removeElementsFromAST(); refresh(); bindConfig.resetLists(); } }); // TabFolder _tabFolder = new TabFolder(this, SWT.NONE); final FormData formData_1 = new FormData(); formData_1.bottom = new FormAttachment(100, -5); formData_1.right = new FormAttachment(100, -5); formData_1.top = new FormAttachment(connDefGroup, 5, SWT.BOTTOM); formData_1.left = new FormAttachment(0, 5); _tabFolder.setLayoutData(formData_1); // method mapping tab item bindConfig = new BindingConfiguration(_tabFolder, SWT.NONE); bindConfig.setCurrentTeamForMethodFake(teamType); _methMapItem = new TabItem(_tabFolder, SWT.NONE); _methMapItem.setText(Messages.BindingEditor_method_binding_tab); _methMapItem.setControl(bindConfig); _methMapItems = new TabItem[] { _methMapItem }; // parameter mapping tab item _callinMapConfig = new CallinMappingConfiguration(_tabFolder, SWT.NONE); _calloutMapConfig = new CalloutMappingConfiguration(_tabFolder, SWT.NONE); _paraMapItem = new TabItem(_tabFolder, SWT.NONE); _paraMapItem.setText(Messages.BindingEditor_param_mapping_tab); _paraMapItem.setControl(_callinMapConfig); _paraMapItems = new TabItem[] { _paraMapItem }; }
From source file:org.evolizer.famix.importer.test.FamixImporterTest.java
License:Apache License
@Test public void testMethodModifiers() { FamixMethod publicAbstractMethod = (FamixMethod) aModel .getElement(aFactory.createMethod("testPackage.Base.compute()", null)); assertEquals("Type string of " + publicAbstractMethod.getUniqueName() + " must have modifier PUBLIC", publicAbstractMethod.getModifiers() & Modifier.PUBLIC, Modifier.PUBLIC); assertEquals("Type string of " + publicAbstractMethod.getUniqueName() + " must have modifier ABSTRACT", publicAbstractMethod.getModifiers() & Modifier.ABSTRACT, Modifier.ABSTRACT); }