List of usage examples for org.eclipse.jdt.internal.compiler.ast TypeDeclaration kind
public final static int kind(int flags)
From source file:ch.uzh.ifi.seal.changedistiller.structuredifferencing.java.JavaStructureTreeBuilder.java
License:Apache License
@Override public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) { int kind = TypeDeclaration.kind(typeDeclaration.modifiers); Type type = null;// w w w.j a v a 2 s . c o m switch (kind) { case TypeDeclaration.INTERFACE_DECL: type = Type.INTERFACE; break; case TypeDeclaration.CLASS_DECL: type = Type.CLASS; break; case TypeDeclaration.ANNOTATION_TYPE_DECL: type = Type.ANNOTATION; break; case TypeDeclaration.ENUM_DECL: type = Type.ENUM; break; default: assert (false); } push(type, String.valueOf(typeDeclaration.name), typeDeclaration); fQualifiers.push(typeDeclaration.name); return true; }
From source file:com.android.tools.lint.psi.EcjPsiBuilder.java
License:Apache License
@NonNull private EcjPsiClass toClass(@NonNull EcjPsiSourceElement parent, @NonNull TypeDeclaration declaration) { EcjPsiClass cls = new EcjPsiClass(mManager, declaration, new String(declaration.name)); parent.adoptChild(cls);/* ww w . j a v a 2 s. c om*/ cls.setRange(declaration.declarationSourceStart, declaration.declarationSourceEnd + 1); EcjPsiModifierList modifierList = toModifierList(cls, declaration); cls.setNameIdentifier(toIdentifier(cls, declaration.name, toRange(declaration))); cls.setModifierList(modifierList); int kind = TypeDeclaration.kind(declaration.modifiers); switch (kind) { case TypeDeclaration.CLASS_DECL: { // Class: set body, super class, extended interfaces, and type variables cls.setSuperClass(declaration.superclass); cls.setSuperInterfaces(declaration.superInterfaces); cls.setTypeParameterList(toTypeParameterList(cls, declaration.typeParameters)); cls.setExtendsList(toTypeReferenceList(cls, declaration.superclass, Role.EXTENDS_LIST)); cls.setImplementsList(toTypeReferenceList(cls, declaration.superInterfaces, Role.IMPLEMENTS_LIST)); initializeClassBody(cls, declaration); break; } case TypeDeclaration.INTERFACE_DECL: { // Interface: set body, super interface, and type variables modifierList.setModifiers(modifierList.getModifiers() | Modifier.STATIC | Modifier.ABSTRACT); cls.setSuperInterfaces(declaration.superInterfaces); cls.setTypeParameterList(toTypeParameterList(cls, declaration.typeParameters)); cls.setImplementsList(toTypeReferenceList(cls, declaration.superInterfaces, Role.EXTENDS_LIST)); initializeClassBody(cls, declaration); break; } case TypeDeclaration.ENUM_DECL: { // Enum: set enum body, and implemented interfaces cls.setSuperInterfaces(declaration.superInterfaces); cls.setImplementsList(toTypeReferenceList(cls, declaration.superInterfaces, Role.IMPLEMENTS_LIST)); modifierList.setModifiers(modifierList.getModifiers() | Modifier.STATIC | Modifier.FINAL); initializeClassBody(cls, declaration); break; } case TypeDeclaration.ANNOTATION_TYPE_DECL: { // Annotation: set body modifierList.setModifiers(modifierList.getModifiers() | Modifier.STATIC | Modifier.ABSTRACT); initializeClassBody(cls, declaration); break; } } return cls; }
From source file:com.android.tools.lint.psi.EcjPsiClass.java
License:Apache License
@Override public boolean isInterface() { return TypeDeclaration.kind(mEcjModifiers) == TypeDeclaration.INTERFACE_DECL; }
From source file:com.android.tools.lint.psi.EcjPsiClass.java
License:Apache License
@Override public boolean isAnnotationType() { return TypeDeclaration.kind(mEcjModifiers) == TypeDeclaration.ANNOTATION_TYPE_DECL; }
From source file:com.android.tools.lint.psi.EcjPsiClass.java
License:Apache License
@Override public boolean isEnum() { return TypeDeclaration.kind(mEcjModifiers) == TypeDeclaration.ENUM_DECL; }
From source file:com.codenvy.ide.ext.java.server.internal.compiler.parser.SourceTypeConverter.java
License:Open Source License
private TypeDeclaration convert(SourceType typeHandle, CompilationResult compilationResult) throws JavaModelException { SourceTypeElementInfo typeInfo = (SourceTypeElementInfo) typeHandle.getElementInfo(); if (typeInfo.isAnonymousMember()) throw new AnonymousMemberFound(); /* create type declaration - can be member type */ TypeDeclaration type = new TypeDeclaration(compilationResult); if (typeInfo.getEnclosingType() == null) { if (typeHandle.isAnonymous()) { type.name = CharOperation.NO_CHAR; type.bits |= (ASTNode.IsAnonymousType | ASTNode.IsLocalType); } else {/* ww w.j a v a 2 s .c o m*/ if (typeHandle.isLocal()) { type.bits |= ASTNode.IsLocalType; } } } else { type.bits |= ASTNode.IsMemberType; } if ((type.bits & ASTNode.IsAnonymousType) == 0) { type.name = typeInfo.getName(); } type.name = typeInfo.getName(); int start, end; // only positions available type.sourceStart = start = typeInfo.getNameSourceStart(); type.sourceEnd = end = typeInfo.getNameSourceEnd(); type.modifiers = typeInfo.getModifiers(); type.declarationSourceStart = typeInfo.getDeclarationSourceStart(); type.declarationSourceEnd = typeInfo.getDeclarationSourceEnd(); type.bodyEnd = type.declarationSourceEnd; // convert 1.5 specific constructs only if compliance is 1.5 or above if (this.has1_5Compliance) { /* convert annotations */ type.annotations = convertAnnotations(typeHandle); } /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850, even in a 1.4 project, we must internalize type variables and observe any parameterization of super class and/or super interfaces in order to be able to detect overriding in the presence of generics. */ char[][] typeParameterNames = typeInfo.getTypeParameterNames(); if (typeParameterNames.length > 0) { int parameterCount = typeParameterNames.length; char[][][] typeParameterBounds = typeInfo.getTypeParameterBounds(); type.typeParameters = new TypeParameter[parameterCount]; for (int i = 0; i < parameterCount; i++) { type.typeParameters[i] = createTypeParameter(typeParameterNames[i], typeParameterBounds[i], start, end); } } /* set superclass and superinterfaces */ if (typeInfo.getSuperclassName() != null) { type.superclass = createTypeReference(typeInfo.getSuperclassName(), start, end, true /* include generics */); type.superclass.bits |= ASTNode.IsSuperType; } char[][] interfaceNames = typeInfo.getInterfaceNames(); int interfaceCount = interfaceNames == null ? 0 : interfaceNames.length; if (interfaceCount > 0) { type.superInterfaces = new TypeReference[interfaceCount]; for (int i = 0; i < interfaceCount; i++) { type.superInterfaces[i] = createTypeReference(interfaceNames[i], start, end, true /* include generics */); type.superInterfaces[i].bits |= ASTNode.IsSuperType; } } /* convert member types */ if ((this.flags & MEMBER_TYPE) != 0) { SourceType[] sourceMemberTypes = typeInfo.getMemberTypeHandles(); int sourceMemberTypeCount = sourceMemberTypes.length; type.memberTypes = new TypeDeclaration[sourceMemberTypeCount]; for (int i = 0; i < sourceMemberTypeCount; i++) { type.memberTypes[i] = convert(sourceMemberTypes[i], compilationResult); type.memberTypes[i].enclosingType = type; } } /* convert intializers and fields*/ InitializerElementInfo[] initializers = null; int initializerCount = 0; if ((this.flags & LOCAL_TYPE) != 0) { initializers = typeInfo.getInitializers(); initializerCount = initializers.length; } SourceField[] sourceFields = null; int sourceFieldCount = 0; if ((this.flags & FIELD) != 0) { sourceFields = typeInfo.getFieldHandles(); sourceFieldCount = sourceFields.length; } int length = initializerCount + sourceFieldCount; if (length > 0) { type.fields = new FieldDeclaration[length]; for (int i = 0; i < initializerCount; i++) { type.fields[i] = convert(initializers[i], compilationResult); } int index = 0; for (int i = initializerCount; i < length; i++) { type.fields[i] = convert(sourceFields[index++], type, compilationResult); } } /* convert methods - need to add default constructor if necessary */ boolean needConstructor = (this.flags & CONSTRUCTOR) != 0; boolean needMethod = (this.flags & METHOD) != 0; if (needConstructor || needMethod) { SourceMethod[] sourceMethods = typeInfo.getMethodHandles(); int sourceMethodCount = sourceMethods.length; /* source type has a constructor ? */ /* by default, we assume that one is needed. */ int extraConstructor = 0; int methodCount = 0; int kind = TypeDeclaration.kind(type.modifiers); boolean isAbstract = kind == TypeDeclaration.INTERFACE_DECL || kind == TypeDeclaration.ANNOTATION_TYPE_DECL; if (!isAbstract) { extraConstructor = needConstructor ? 1 : 0; for (int i = 0; i < sourceMethodCount; i++) { if (sourceMethods[i].isConstructor()) { if (needConstructor) { extraConstructor = 0; // Does not need the extra constructor since one constructor already exists. methodCount++; } } else if (needMethod) { methodCount++; } } } else { methodCount = needMethod ? sourceMethodCount : 0; } type.methods = new AbstractMethodDeclaration[methodCount + extraConstructor]; if (extraConstructor != 0) { // add default constructor in first position type.methods[0] = type.createDefaultConstructor(false, false); } int index = 0; boolean hasAbstractMethods = false; for (int i = 0; i < sourceMethodCount; i++) { SourceMethod sourceMethod = sourceMethods[i]; SourceMethodElementInfo methodInfo = (SourceMethodElementInfo) sourceMethod.getElementInfo(); boolean isConstructor = methodInfo.isConstructor(); if ((methodInfo.getModifiers() & ClassFileConstants.AccAbstract) != 0) { hasAbstractMethods = true; } if ((isConstructor && needConstructor) || (!isConstructor && needMethod)) { AbstractMethodDeclaration method = convert(sourceMethod, methodInfo, compilationResult); if (isAbstract || method.isAbstract()) { // fix-up flag method.modifiers |= ExtraCompilerModifiers.AccSemicolonBody; } type.methods[extraConstructor + index++] = method; } } if (hasAbstractMethods) type.bits |= ASTNode.HasAbstractMethods; } return type; }
From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryType.java
License:Open Source License
public boolean isClass() throws JavaModelException { IBinaryType info = (IBinaryType) getElementInfo(); return TypeDeclaration.kind(info.getModifiers()) == TypeDeclaration.CLASS_DECL; }
From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryType.java
License:Open Source License
/** * @see org.eclipse.jdt.core.IType#isEnum() * @since 3.0/*ww w . j av a2 s.c om*/ */ public boolean isEnum() throws JavaModelException { IBinaryType info = (IBinaryType) getElementInfo(); return TypeDeclaration.kind(info.getModifiers()) == TypeDeclaration.ENUM_DECL; }
From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryType.java
License:Open Source License
public boolean isInterface() throws JavaModelException { IBinaryType info = (IBinaryType) getElementInfo(); switch (TypeDeclaration.kind(info.getModifiers())) { case TypeDeclaration.INTERFACE_DECL: case TypeDeclaration.ANNOTATION_TYPE_DECL: // annotation is interface too return true; }// www .j a v a2 s. c o m return false; }
From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryType.java
License:Open Source License
/** * @see org.eclipse.jdt.core.IType#isAnnotation() * @since 3.0//from w ww . java 2 s.c o m */ public boolean isAnnotation() throws JavaModelException { IBinaryType info = (IBinaryType) getElementInfo(); return TypeDeclaration.kind(info.getModifiers()) == TypeDeclaration.ANNOTATION_TYPE_DECL; }