Java 类org.eclipse.jdt.internal.compiler.ast.TypeDeclaration 实例源码

项目:GitHub    文件:SourceExtraction.java   
private static CharSequence readSourceDeclaration(SourceTypeBinding binding) {
  TypeDeclaration referenceContext = binding.scope.referenceContext;
  char[] content = referenceContext.compilationResult.compilationUnit.getContents();
  int start = referenceContext.declarationSourceStart;
  int end = referenceContext.declarationSourceEnd;

  StringBuilder declaration = new StringBuilder();
  for (int p = start; p <= end; p++) {
    char c = content[p];
    if (c == '{') {
      break;
    }
    declaration.append(c);
  }
  return declaration;
}
项目:lombok-ianchiu    文件:PatchExtensionMethodCompletionProposal.java   
static TypeBinding getFirstParameterType(TypeDeclaration decl, CompletionProposalCollector completionProposalCollector) {
        TypeBinding firstParameterType = null;
        ASTNode node = getAssistNode(completionProposalCollector);
        if (node == null) return null;
        if (!(node instanceof CompletionOnQualifiedNameReference) && !(node instanceof CompletionOnSingleNameReference) && !(node instanceof CompletionOnMemberAccess)) return null;

        // Never offer on 'super.<autocomplete>'.
        if (node instanceof FieldReference && ((FieldReference)node).receiver instanceof SuperReference) return null;

        if (node instanceof NameReference) {
            Binding binding = ((NameReference) node).binding;
            // Unremark next block to allow a 'blank' autocomplete to list any extensions that apply to the current scope, but make sure we're not in a static context first, which this doesn't do.
            // Lacking good use cases, and having this particular concept be a little tricky on javac, means for now we don't support extension methods like this. this.X() will be fine, though.

/*          if ((node instanceof SingleNameReference) && (((SingleNameReference) node).token.length == 0)) {
                firstParameterType = decl.binding;
            } else */if (binding instanceof VariableBinding) {
                firstParameterType = ((VariableBinding) binding).type;
            }
        } else if (node instanceof FieldReference) {
            firstParameterType = ((FieldReference) node).actualReceiverType;
        }
        return firstParameterType;
    }
项目:lombok-ianchiu    文件:PatchExtensionMethod.java   
static List<Extension> getApplicableExtensionMethods(EclipseNode typeNode, Annotation ann, TypeBinding receiverType) {
    List<Extension> extensions = new ArrayList<Extension>();
    if ((typeNode != null) && (ann != null) && (receiverType != null)) {
        BlockScope blockScope = ((TypeDeclaration) typeNode.get()).initializerScope;
        EclipseNode annotationNode = typeNode.getNodeFor(ann);
        AnnotationValues<ExtensionMethod> annotation = createAnnotation(ExtensionMethod.class, annotationNode);
        boolean suppressBaseMethods = false;
        try {
            suppressBaseMethods = annotation.getInstance().suppressBaseMethods();
        } catch (AnnotationValueDecodeFail fail) {
            fail.owner.setError(fail.getMessage(), fail.idx);
        }
        for (Object extensionMethodProvider : annotation.getActualExpressions("value")) {
            if (extensionMethodProvider instanceof ClassLiteralAccess) {
                TypeBinding binding = ((ClassLiteralAccess) extensionMethodProvider).type.resolveType(blockScope);
                if (binding == null) continue;
                if (!binding.isClass() && !binding.isEnum()) continue;
                Extension e = new Extension();
                e.extensionMethods = getApplicableExtensionMethodsDefinedInProvider(typeNode, (ReferenceBinding) binding, receiverType);
                e.suppressBaseMethods = suppressBaseMethods;
                extensions.add(e);
            }
        }
    }
    return extensions;
}
项目:lombok-ianchiu    文件:EclipseAST.java   
/** {@inheritDoc} */
@Override protected EclipseNode buildTree(ASTNode node, Kind kind) {
    switch (kind) {
    case COMPILATION_UNIT:
        return buildCompilationUnit((CompilationUnitDeclaration) node);
    case TYPE:
        return buildType((TypeDeclaration) node);
    case FIELD:
        return buildField((FieldDeclaration) node);
    case INITIALIZER:
        return buildInitializer((Initializer) node);
    case METHOD:
        return buildMethod((AbstractMethodDeclaration) node);
    case ARGUMENT:
        return buildLocal((Argument) node, kind);
    case LOCAL:
        return buildLocal((LocalDeclaration) node, kind);
    case STATEMENT:
        return buildStatement((Statement) node);
    case ANNOTATION:
        return buildAnnotation((Annotation) node, false);
    default:
        throw new AssertionError("Did not expect to arrive here: " + kind);
    }
}
项目:lombok-ianchiu    文件:EclipseHandlerUtil.java   
/**
 * Checks if there is a field with the provided name.
 * 
 * @param fieldName the field name to check for.
 * @param node Any node that represents the Type (TypeDeclaration) to look in, or any child node thereof.
 */
public static MemberExistsResult fieldExists(String fieldName, EclipseNode node) {
    while (node != null && !(node.get() instanceof TypeDeclaration)) {
        node = node.up();
    }

    if (node != null && node.get() instanceof TypeDeclaration) {
        TypeDeclaration typeDecl = (TypeDeclaration)node.get();
        if (typeDecl.fields != null) for (FieldDeclaration def : typeDecl.fields) {
            char[] fName = def.name;
            if (fName == null) continue;
            if (fieldName.equals(new String(fName))) {
                return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
            }
        }
    }

    return MemberExistsResult.NOT_EXISTS;
}
项目:lombok-ianchiu    文件:EclipseHandlerUtil.java   
/**
 * Checks if there is a (non-default) constructor. In case of multiple constructors (overloading), only
 * the first constructor decides if EXISTS_BY_USER or EXISTS_BY_LOMBOK is returned.
 * 
 * @param node Any node that represents the Type (TypeDeclaration) to look in, or any child node thereof.
 */
public static MemberExistsResult constructorExists(EclipseNode node) {
    while (node != null && !(node.get() instanceof TypeDeclaration)) {
        node = node.up();
    }

    if (node != null && node.get() instanceof TypeDeclaration) {
        TypeDeclaration typeDecl = (TypeDeclaration)node.get();
        if (typeDecl.methods != null) top: for (AbstractMethodDeclaration def : typeDecl.methods) {
            if (def instanceof ConstructorDeclaration) {
                if ((def.bits & ASTNode.IsDefaultConstructor) != 0) continue;

                if (def.annotations != null) for (Annotation anno : def.annotations) {
                    if (typeMatches(Tolerate.class, node, anno.type)) continue top;
                }

                return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
            }
        }
    }

    return MemberExistsResult.NOT_EXISTS;
}
项目:lombok-ianchiu    文件:EclipseHandlerUtil.java   
/**
 * Adds an inner type (class, interface, enum) to the given type. Cannot inject top-level types.
 * 
 * @param typeNode parent type to inject new type into
 * @param type New type (class, interface, etc) to inject.
 */
public static EclipseNode injectType(final EclipseNode typeNode, final TypeDeclaration type) {
    type.annotations = addSuppressWarningsAll(typeNode, type, type.annotations);
    type.annotations = addGenerated(typeNode, type, type.annotations);
    TypeDeclaration parent = (TypeDeclaration) typeNode.get();

    if (parent.memberTypes == null) {
        parent.memberTypes = new TypeDeclaration[] { type };
    } else {
        TypeDeclaration[] newArray = new TypeDeclaration[parent.memberTypes.length + 1];
        System.arraycopy(parent.memberTypes, 0, newArray, 0, parent.memberTypes.length);
        newArray[parent.memberTypes.length] = type;
        parent.memberTypes = newArray;
    }

    return typeNode.add(type, Kind.TYPE);
}
项目:lombok-ianchiu    文件:HandleBuilder.java   
public MethodDeclaration generateBuilderMethod(boolean isStatic, String builderMethodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, ASTNode source) {
    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long) pS << 32 | pE;

    MethodDeclaration out = new MethodDeclaration(((CompilationUnitDeclaration) type.top().get()).compilationResult);
    out.selector = builderMethodName.toCharArray();
    out.modifiers = ClassFileConstants.AccPublic;
    if (isStatic) out.modifiers |= ClassFileConstants.AccStatic;
    out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    out.returnType = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
    out.typeParameters = copyTypeParams(typeParams, source);
    AllocationExpression invoke = new AllocationExpression();
    invoke.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
    out.statements = new Statement[] {new ReturnStatement(invoke, pS, pE)};

    out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope);
    return out;
}
项目:lombok-ianchiu    文件:HandleBuilder.java   
private void makeSimpleSetterMethodForBuilder(EclipseNode builderType, EclipseNode fieldNode, EclipseNode sourceNode, boolean fluent, boolean chain) {
    TypeDeclaration td = (TypeDeclaration) builderType.get();
    AbstractMethodDeclaration[] existing = td.methods;
    if (existing == null) existing = EMPTY;
    int len = existing.length;
    FieldDeclaration fd = (FieldDeclaration) fieldNode.get();
    char[] name = fd.name;

    for (int i = 0; i < len; i++) {
        if (!(existing[i] instanceof MethodDeclaration)) continue;
        char[] existingName = existing[i].selector;
        if (Arrays.equals(name, existingName)) return;
    }

    String setterName = fluent ? fieldNode.getName() : HandlerUtil.buildAccessorName("set", fieldNode.getName());

    MethodDeclaration setter = HandleSetter.createSetter(td, fieldNode, setterName, chain, ClassFileConstants.AccPublic,
        sourceNode, Collections.<Annotation>emptyList(), Collections.<Annotation>emptyList());
    injectMethod(builderType, setter);
}
项目:EasyMPermission    文件:PatchExtensionMethodCompletionProposal.java   
static TypeBinding getFirstParameterType(TypeDeclaration decl, CompletionProposalCollector completionProposalCollector) {
        TypeBinding firstParameterType = null;
        ASTNode node = getAssistNode(completionProposalCollector);
        if (node == null) return null;
        if (!(node instanceof CompletionOnQualifiedNameReference) && !(node instanceof CompletionOnSingleNameReference) && !(node instanceof CompletionOnMemberAccess)) return null;

        // Never offer on 'super.<autocomplete>'.
        if (node instanceof FieldReference && ((FieldReference)node).receiver instanceof SuperReference) return null;

        if (node instanceof NameReference) {
            Binding binding = ((NameReference) node).binding;
            // Unremark next block to allow a 'blank' autocomplete to list any extensions that apply to the current scope, but make sure we're not in a static context first, which this doesn't do.
            // Lacking good use cases, and having this particular concept be a little tricky on javac, means for now we don't support extension methods like this. this.X() will be fine, though.

/*          if ((node instanceof SingleNameReference) && (((SingleNameReference) node).token.length == 0)) {
                firstParameterType = decl.binding;
            } else */if (binding instanceof VariableBinding) {
                firstParameterType = ((VariableBinding) binding).type;
            }
        } else if (node instanceof FieldReference) {
            firstParameterType = ((FieldReference) node).actualReceiverType;
        }
        return firstParameterType;
    }
项目:EasyMPermission    文件:PatchExtensionMethod.java   
static List<Extension> getApplicableExtensionMethods(EclipseNode typeNode, Annotation ann, TypeBinding receiverType) {
    List<Extension> extensions = new ArrayList<Extension>();
    if ((typeNode != null) && (ann != null) && (receiverType != null)) {
        BlockScope blockScope = ((TypeDeclaration) typeNode.get()).initializerScope;
        EclipseNode annotationNode = typeNode.getNodeFor(ann);
        AnnotationValues<ExtensionMethod> annotation = createAnnotation(ExtensionMethod.class, annotationNode);
        boolean suppressBaseMethods = false;
        try {
            suppressBaseMethods = annotation.getInstance().suppressBaseMethods();
        } catch (AnnotationValueDecodeFail fail) {
            fail.owner.setError(fail.getMessage(), fail.idx);
        }
        for (Object extensionMethodProvider : annotation.getActualExpressions("value")) {
            if (extensionMethodProvider instanceof ClassLiteralAccess) {
                TypeBinding binding = ((ClassLiteralAccess) extensionMethodProvider).type.resolveType(blockScope);
                if (binding == null) continue;
                if (!binding.isClass() && !binding.isEnum()) continue;
                Extension e = new Extension();
                e.extensionMethods = getApplicableExtensionMethodsDefinedInProvider(typeNode, (ReferenceBinding) binding, receiverType);
                e.suppressBaseMethods = suppressBaseMethods;
                extensions.add(e);
            }
        }
    }
    return extensions;
}
项目:EasyMPermission    文件:EclipseAST.java   
/** {@inheritDoc} */
@Override protected EclipseNode buildTree(ASTNode node, Kind kind) {
    switch (kind) {
    case COMPILATION_UNIT:
        return buildCompilationUnit((CompilationUnitDeclaration) node);
    case TYPE:
        return buildType((TypeDeclaration) node);
    case FIELD:
        return buildField((FieldDeclaration) node);
    case INITIALIZER:
        return buildInitializer((Initializer) node);
    case METHOD:
        return buildMethod((AbstractMethodDeclaration) node);
    case ARGUMENT:
        return buildLocal((Argument) node, kind);
    case LOCAL:
        return buildLocal((LocalDeclaration) node, kind);
    case STATEMENT:
        return buildStatement((Statement) node);
    case ANNOTATION:
        return buildAnnotation((Annotation) node, false);
    default:
        throw new AssertionError("Did not expect to arrive here: " + kind);
    }
}
项目:EasyMPermission    文件:EclipseHandlerUtil.java   
/**
 * Checks if there is a field with the provided name.
 * 
 * @param fieldName the field name to check for.
 * @param node Any node that represents the Type (TypeDeclaration) to look in, or any child node thereof.
 */
public static MemberExistsResult fieldExists(String fieldName, EclipseNode node) {
    while (node != null && !(node.get() instanceof TypeDeclaration)) {
        node = node.up();
    }

    if (node != null && node.get() instanceof TypeDeclaration) {
        TypeDeclaration typeDecl = (TypeDeclaration)node.get();
        if (typeDecl.fields != null) for (FieldDeclaration def : typeDecl.fields) {
            char[] fName = def.name;
            if (fName == null) continue;
            if (fieldName.equals(new String(fName))) {
                return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
            }
        }
    }

    return MemberExistsResult.NOT_EXISTS;
}
项目:EasyMPermission    文件:EclipseHandlerUtil.java   
/**
 * Checks if there is a (non-default) constructor. In case of multiple constructors (overloading), only
 * the first constructor decides if EXISTS_BY_USER or EXISTS_BY_LOMBOK is returned.
 * 
 * @param node Any node that represents the Type (TypeDeclaration) to look in, or any child node thereof.
 */
public static MemberExistsResult constructorExists(EclipseNode node) {
    while (node != null && !(node.get() instanceof TypeDeclaration)) {
        node = node.up();
    }

    if (node != null && node.get() instanceof TypeDeclaration) {
        TypeDeclaration typeDecl = (TypeDeclaration)node.get();
        if (typeDecl.methods != null) top: for (AbstractMethodDeclaration def : typeDecl.methods) {
            if (def instanceof ConstructorDeclaration) {
                if ((def.bits & ASTNode.IsDefaultConstructor) != 0) continue;

                if (def.annotations != null) for (Annotation anno : def.annotations) {
                    if (typeMatches(Tolerate.class, node, anno.type)) continue top;
                }

                return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
            }
        }
    }

    return MemberExistsResult.NOT_EXISTS;
}
项目:EasyMPermission    文件:EclipseHandlerUtil.java   
/**
 * Adds an inner type (class, interface, enum) to the given type. Cannot inject top-level types.
 * 
 * @param typeNode parent type to inject new type into
 * @param type New type (class, interface, etc) to inject.
 */
public static EclipseNode injectType(final EclipseNode typeNode, final TypeDeclaration type) {
    type.annotations = addSuppressWarningsAll(typeNode, type, type.annotations);
    type.annotations = addGenerated(typeNode, type, type.annotations);
    TypeDeclaration parent = (TypeDeclaration) typeNode.get();

    if (parent.memberTypes == null) {
        parent.memberTypes = new TypeDeclaration[] { type };
    } else {
        TypeDeclaration[] newArray = new TypeDeclaration[parent.memberTypes.length + 1];
        System.arraycopy(parent.memberTypes, 0, newArray, 0, parent.memberTypes.length);
        newArray[parent.memberTypes.length] = type;
        parent.memberTypes = newArray;
    }

    return typeNode.add(type, Kind.TYPE);
}
项目:EasyMPermission    文件:HandleBuilder.java   
public MethodDeclaration generateBuilderMethod(String builderMethodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, ASTNode source) {
    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long) pS << 32 | pE;

    MethodDeclaration out = new MethodDeclaration(
            ((CompilationUnitDeclaration) type.top().get()).compilationResult);
    out.selector = builderMethodName.toCharArray();
    out.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic;
    out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    out.returnType = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
    out.typeParameters = copyTypeParams(typeParams, source);
    AllocationExpression invoke = new AllocationExpression();
    invoke.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
    out.statements = new Statement[] {new ReturnStatement(invoke, pS, pE)};

    out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope);
    return out;
}
项目:EasyMPermission    文件:HandleBuilder.java   
private void makeSimpleSetterMethodForBuilder(EclipseNode builderType, EclipseNode fieldNode, EclipseNode sourceNode, boolean fluent, boolean chain) {
    TypeDeclaration td = (TypeDeclaration) builderType.get();
    AbstractMethodDeclaration[] existing = td.methods;
    if (existing == null) existing = EMPTY;
    int len = existing.length;
    FieldDeclaration fd = (FieldDeclaration) fieldNode.get();
    char[] name = fd.name;

    for (int i = 0; i < len; i++) {
        if (!(existing[i] instanceof MethodDeclaration)) continue;
        char[] existingName = existing[i].selector;
        if (Arrays.equals(name, existingName)) return;
    }

    String setterName = fluent ? fieldNode.getName() : HandlerUtil.buildAccessorName("set", fieldNode.getName());

    MethodDeclaration setter = HandleSetter.createSetter(td, fieldNode, setterName, chain, ClassFileConstants.AccPublic,
            sourceNode, Collections.<Annotation>emptyList(), Collections.<Annotation>emptyList());
    injectMethod(builderType, setter);
}
项目:che    文件:SourceTypeConverter.java   
private QualifiedAllocationExpression convert(
    IJavaElement localType, FieldDeclaration enumConstant, CompilationResult compilationResult)
    throws JavaModelException {
  TypeDeclaration anonymousLocalTypeDeclaration =
      convert((SourceType) localType, compilationResult);
  QualifiedAllocationExpression expression =
      new QualifiedAllocationExpression(anonymousLocalTypeDeclaration);
  expression.type = anonymousLocalTypeDeclaration.superclass;
  anonymousLocalTypeDeclaration.superclass = null;
  anonymousLocalTypeDeclaration.superInterfaces = null;
  anonymousLocalTypeDeclaration.allocation = expression;
  if (enumConstant != null) {
    anonymousLocalTypeDeclaration.modifiers &= ~ClassFileConstants.AccEnum;
    expression.enumConstant = enumConstant;
    expression.type = null;
  }
  return expression;
}
项目:Eclipse-Postfix-Code-Completion    文件:AnnotationDiscoveryVisitor.java   
@Override
public boolean visit(Argument argument, BlockScope scope) {
    Annotation[] annotations = argument.annotations;
    ReferenceContext referenceContext = scope.referenceContext();
    if (referenceContext instanceof AbstractMethodDeclaration) {
        MethodBinding binding = ((AbstractMethodDeclaration) referenceContext).binding;
        if (binding != null) {
            TypeDeclaration typeDeclaration = scope.referenceType();
            typeDeclaration.binding.resolveTypesFor(binding);
            if (argument.binding != null) {
                argument.binding = new AptSourceLocalVariableBinding(argument.binding, binding);
            }
        }
        if (annotations != null) {
            this.resolveAnnotations(
                    scope,
                    annotations,
                    argument.binding);
        }
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CodeFormatterVisitor.java   
private void format(
    TypeDeclaration memberTypeDeclaration,
    ClassScope scope,
    boolean isChunkStart,
    boolean isFirstClassBodyDeclaration) {

    if (isFirstClassBodyDeclaration) {
        int newLinesBeforeFirstClassBodyDeclaration = this.preferences.blank_lines_before_first_class_body_declaration;
        if (newLinesBeforeFirstClassBodyDeclaration > 0) {
            this.scribe.printEmptyLines(newLinesBeforeFirstClassBodyDeclaration);
        }
    } else {
        int newLineBeforeChunk = isChunkStart ? this.preferences.blank_lines_before_new_chunk : 0;
        if (newLineBeforeChunk > 0) {
            this.scribe.printEmptyLines(newLineBeforeChunk);
        }
        final int newLinesBeforeMember = this.preferences.blank_lines_before_member_type;
        if (newLinesBeforeMember > 0) {
            this.scribe.printEmptyLines(newLinesBeforeMember);
        }
    }
    memberTypeDeclaration.traverse(this, scope);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RecoveredType.java   
public RecoveredType(TypeDeclaration typeDeclaration, RecoveredElement parent, int bracketBalance){
    super(typeDeclaration, parent, bracketBalance);
    this.typeDeclaration = typeDeclaration;
    if(typeDeclaration.allocation != null && typeDeclaration.allocation.type == null) {
        // an enum constant body can not exist if there is no opening brace
        this.foundOpeningBrace = true;
    } else {
        this.foundOpeningBrace = !bodyStartsAtHeaderEnd();
    }
    this.insideEnumConstantPart = TypeDeclaration.kind(typeDeclaration.modifiers) == TypeDeclaration.ENUM_DECL;
    if(this.foundOpeningBrace) {
        this.bracketBalance++;
    }

    this.preserveContent = parser().methodRecoveryActivated || parser().statementRecoveryActivated;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:NameLookup.java   
/**
 * Returns true if:<ul>
 *  <li>the given type is an existing class and the flag's <code>ACCEPT_CLASSES</code>
 *      bit is on
 *  <li>the given type is an existing interface and the <code>ACCEPT_INTERFACES</code>
 *      bit is on
 *  <li>neither the <code>ACCEPT_CLASSES</code> or <code>ACCEPT_INTERFACES</code>
 *      bit is on
 *  </ul>
 * Otherwise, false is returned.
 */
protected boolean acceptType(IType type, int acceptFlags, boolean isSourceType) {
    if (acceptFlags == 0 || acceptFlags == ACCEPT_ALL)
        return true; // no flags or all flags, always accepted
    try {
        int kind = isSourceType
                ? TypeDeclaration.kind(((SourceTypeElementInfo) ((SourceType) type).getElementInfo()).getModifiers())
                : TypeDeclaration.kind(((IBinaryType) ((BinaryType) type).getElementInfo()).getModifiers());
        switch (kind) {
            case TypeDeclaration.CLASS_DECL :
                return (acceptFlags & ACCEPT_CLASSES) != 0;
            case TypeDeclaration.INTERFACE_DECL :
                return (acceptFlags & ACCEPT_INTERFACES) != 0;
            case TypeDeclaration.ENUM_DECL :
                return (acceptFlags & ACCEPT_ENUMS) != 0;
            default:
                //case IGenericType.ANNOTATION_TYPE :
                return (acceptFlags & ACCEPT_ANNOTATIONS) != 0;
        }
    } catch (JavaModelException npe) {
        return false; // the class is not present, do not accept.
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:CodeFormatterVisitor.java   
private void formatAnonymousTypeDeclaration(TypeDeclaration typeDeclaration) {
    /*
     * Type body
     */
    String anonymous_type_declaration_brace_position = this.preferences.brace_position_for_anonymous_type_declaration;

    formatTypeOpeningBrace(anonymous_type_declaration_brace_position, this.preferences.insert_space_before_opening_brace_in_anonymous_type_declaration, typeDeclaration);

    this.scribe.indent();

    formatTypeMembers(typeDeclaration);

    this.scribe.unIndent();
    if (this.preferences.insert_new_line_in_empty_anonymous_type_declaration) {
        this.scribe.printNewLine();
    }
    this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE);
    if (anonymous_type_declaration_brace_position.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) {
        this.scribe.unIndent();
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RecoveredBlock.java   
public RecoveredElement add(TypeDeclaration typeDeclaration, int bracketBalanceValue, boolean delegatedByParent) {

    /* do not consider a type starting passed the block end (if set)
        it must be belonging to an enclosing block */
    if (this.blockDeclaration.sourceEnd != 0
            && typeDeclaration.declarationSourceStart > this.blockDeclaration.sourceEnd){
        resetPendingModifiers();
        if (delegatedByParent) return this; //ignore
        return this.parent.add(typeDeclaration, bracketBalanceValue);
    }

    RecoveredType element = new RecoveredType(typeDeclaration, this, bracketBalanceValue);
    if(this.pendingAnnotationCount > 0) {
        element.attach(
                this.pendingAnnotations,
                this.pendingAnnotationCount,
                this.pendingModifiers,
                this.pendingModifersSourceStart);
    }
    resetPendingModifiers();
    attach(element);
    if (typeDeclaration.declarationSourceEnd == 0) return element;
    return this;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RecoveredMethod.java   
public RecoveredElement updateOnClosingBrace(int braceStart, int braceEnd){
    if(this.methodDeclaration.isAnnotationMethod()) {
        this.updateSourceEndIfNecessary(braceStart, braceEnd);
        if(!this.foundOpeningBrace && this.parent != null) {
            return this.parent.updateOnClosingBrace(braceStart, braceEnd);
        }
        return this;
    }
    if(this.parent != null && this.parent instanceof RecoveredType) {
        int mods = ((RecoveredType)this.parent).typeDeclaration.modifiers;
        if (TypeDeclaration.kind(mods) == TypeDeclaration.INTERFACE_DECL) {
            if (!this.foundOpeningBrace) {
                this.updateSourceEndIfNecessary(braceStart - 1, braceStart - 1);
                return this.parent.updateOnClosingBrace(braceStart, braceEnd);
            }
        }
    }
    return super.updateOnClosingBrace(braceStart, braceEnd);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:AnnotationDiscoveryVisitor.java   
@Override
public boolean visit(Argument argument, BlockScope scope) {
    Annotation[] annotations = argument.annotations;
    ReferenceContext referenceContext = scope.referenceContext();
    if (referenceContext instanceof AbstractMethodDeclaration) {
        MethodBinding binding = ((AbstractMethodDeclaration) referenceContext).binding;
        if (binding != null) {
            TypeDeclaration typeDeclaration = scope.referenceType();
            typeDeclaration.binding.resolveTypesFor(binding);
            if (argument.binding != null) {
                argument.binding = new AptSourceLocalVariableBinding(argument.binding, binding);
            }
        }
        if (annotations != null) {
            this.resolveAnnotations(
                    scope,
                    annotations,
                    argument.binding);
        }
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:ProblemReporter.java   
public void inheritedDefaultMethodConflictsWithOtherInherited(SourceTypeBinding type, MethodBinding defaultMethod, MethodBinding otherMethod) {
    TypeDeclaration typeDecl = type.scope.referenceContext;
    String[] problemArguments = new String[] { 
            String.valueOf(defaultMethod.readableName()), 
            String.valueOf(defaultMethod.declaringClass.readableName()), 
            String.valueOf(otherMethod.declaringClass.readableName()) };
    String[] messageArguments = new String[] { 
            String.valueOf(defaultMethod.shortReadableName()), 
            String.valueOf(defaultMethod.declaringClass.shortReadableName()), 
            String.valueOf(otherMethod.declaringClass.shortReadableName()) };   
    this.handle(IProblem.InheritedDefaultMethodConflictsWithOtherInherited,
            problemArguments,
            messageArguments,
            typeDecl.sourceStart,
            typeDecl.sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:LocalTypeBinding.java   
public LocalTypeBinding(ClassScope scope, SourceTypeBinding enclosingType, CaseStatement switchCase) {
    super(
        new char[][] {CharOperation.concat(LocalTypeBinding.LocalTypePrefix, scope.referenceContext.name)},
        scope,
        enclosingType);
    TypeDeclaration typeDeclaration = scope.referenceContext;
    if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) {
        this.tagBits |= TagBits.AnonymousTypeMask;
    } else {
        this.tagBits |= TagBits.LocalTypeMask;
    }
    this.enclosingCase = switchCase;
    this.sourceStart = typeDeclaration.sourceStart;
    MethodScope methodScope = scope.enclosingMethodScope();
    AbstractMethodDeclaration methodDeclaration = methodScope.referenceMethod();
    if (methodDeclaration != null) {
        this.enclosingMethod = methodDeclaration.binding;
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:ProblemReporter.java   
public void unusedPrivateType(TypeDeclaration typeDecl) {
    int severity = computeSeverity(IProblem.UnusedPrivateType);
    if (severity == ProblemSeverities.Ignore) return;
    if (excludeDueToAnnotation(typeDecl.annotations, IProblem.UnusedPrivateType)) return;
    ReferenceBinding type = typeDecl.binding;
    this.handle(
            IProblem.UnusedPrivateType,
        new String[] {
            new String(type.readableName()),
         },
        new String[] {
            new String(type.shortReadableName()),
         },
        severity,
        typeDecl.sourceStart,
        typeDecl.sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion    文件:SourceTypeBinding.java   
/**
 * @see org.eclipse.jdt.internal.compiler.lookup.Binding#initializeDeprecatedAnnotationTagBits()
 */
public void initializeDeprecatedAnnotationTagBits() {
    if (!isPrototype()) {
        this.prototype.initializeDeprecatedAnnotationTagBits();
        return;
    }
    if ((this.tagBits & TagBits.DeprecatedAnnotationResolved) == 0) {
        TypeDeclaration typeDecl = this.scope.referenceContext;
        boolean old = typeDecl.staticInitializerScope.insideTypeAnnotation;
        try {
            typeDecl.staticInitializerScope.insideTypeAnnotation = true;
            ASTNode.resolveDeprecatedAnnotations(typeDecl.staticInitializerScope, typeDecl.annotations, this);
            this.tagBits |= TagBits.DeprecatedAnnotationResolved;
        } finally {
            typeDecl.staticInitializerScope.insideTypeAnnotation = old;
        }
        if ((this.tagBits & TagBits.AnnotationDeprecated) != 0) {
            this.modifiers |= ClassFileConstants.AccDeprecated;
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:ExtraFlags.java   
public static int getExtraFlags(TypeDeclaration typeDeclaration) {
    int extraFlags = 0;

    if (typeDeclaration.enclosingType != null) {
        extraFlags |= ExtraFlags.IsMemberType;
    }
    TypeDeclaration[] memberTypes = typeDeclaration.memberTypes;
    int memberTypeCounter = memberTypes == null ? 0 : memberTypes.length;
    if (memberTypeCounter > 0) {
        done : for (int i = 0; i < memberTypeCounter; i++) {
            int modifiers = memberTypes[i].modifiers;
            // if the member type is static and not private
            if ((modifiers & ClassFileConstants.AccStatic) != 0 && (modifiers & ClassFileConstants.AccPrivate) == 0) {
                extraFlags |= ExtraFlags.HasNonPrivateStaticMemberTypes;
                break done;
            }
        }
    }

    return extraFlags;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:MethodBinding.java   
/**
 * Compute the tagbits for standard annotations. For source types, these could require
 * lazily resolving corresponding annotation nodes, in case of forward references.
 * @see org.eclipse.jdt.internal.compiler.lookup.Binding#getAnnotationTagBits()
 */
public long getAnnotationTagBits() {
    MethodBinding originalMethod = original();
    if ((originalMethod.tagBits & TagBits.AnnotationResolved) == 0 && originalMethod.declaringClass instanceof SourceTypeBinding) {
        ClassScope scope = ((SourceTypeBinding) originalMethod.declaringClass).scope;
        if (scope != null) {
            TypeDeclaration typeDecl = scope.referenceContext;
            AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(originalMethod);
            if (methodDecl != null)
                ASTNode.resolveAnnotations(methodDecl.scope, methodDecl.annotations, originalMethod);
            long nullDefaultBits = this.tagBits & (TagBits.AnnotationNonNullByDefault|TagBits.AnnotationNullUnspecifiedByDefault);
            if (nullDefaultBits != 0 && this.declaringClass instanceof SourceTypeBinding) {
                SourceTypeBinding declaringSourceType = (SourceTypeBinding) this.declaringClass;
                if (declaringSourceType.checkRedundantNullnessDefaultOne(methodDecl, methodDecl.annotations, nullDefaultBits)) {
                    declaringSourceType.checkRedundantNullnessDefaultRecurse(methodDecl, methodDecl.annotations, nullDefaultBits);
                }
            }
        }
    }
    return originalMethod.tagBits;
}
项目:Eclipse-Postfix-Code-Completion    文件:ClassFile.java   
/**
 * INTERNAL USE-ONLY
 * Generate the byte for problem method infos that correspond to missing abstract methods.
 * http://dev.eclipse.org/bugs/show_bug.cgi?id=3179
 *
 * @param methodDeclarations Array of all missing abstract methods
 */
public void generateMissingAbstractMethods(MethodDeclaration[] methodDeclarations, CompilationResult compilationResult) {
    if (methodDeclarations != null) {
        TypeDeclaration currentDeclaration = this.referenceBinding.scope.referenceContext;
        int typeDeclarationSourceStart = currentDeclaration.sourceStart();
        int typeDeclarationSourceEnd = currentDeclaration.sourceEnd();
        for (int i = 0, max = methodDeclarations.length; i < max; i++) {
            MethodDeclaration methodDeclaration = methodDeclarations[i];
            MethodBinding methodBinding = methodDeclaration.binding;
             String readableName = new String(methodBinding.readableName());
             CategorizedProblem[] problems = compilationResult.problems;
             int problemsCount = compilationResult.problemCount;
            for (int j = 0; j < problemsCount; j++) {
                CategorizedProblem problem = problems[j];
                if (problem != null
                        && problem.getID() == IProblem.AbstractMethodMustBeImplemented
                        && problem.getMessage().indexOf(readableName) != -1
                        && problem.getSourceStart() >= typeDeclarationSourceStart
                        && problem.getSourceEnd() <= typeDeclarationSourceEnd) {
                    // we found a match
                    addMissingAbstractProblemMethod(methodDeclaration, methodBinding, problem, compilationResult);
                }
            }
        }
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:BindingKeyResolver.java   
private TypeBinding getTypeBinding(char[] simpleTypeName) {
    if (this.typeBinding instanceof ReferenceBinding) {
        return ((ReferenceBinding) this.typeBinding).getMemberType(simpleTypeName);
    }
    TypeDeclaration[] typeDeclarations =
        this.typeDeclaration == null ?
            (this.parsedUnit == null ? null : this.parsedUnit.types) :
            this.typeDeclaration.memberTypes;
    if (typeDeclarations == null) return null;
    for (int i = 0, length = typeDeclarations.length; i < length; i++) {
        TypeDeclaration declaration = typeDeclarations[i];
        if (CharOperation.equals(simpleTypeName, declaration.name)) {
            this.typeDeclaration = declaration;
            return declaration.binding;
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:RecoveredType.java   
public Statement updatedStatement(int depth, Set knownTypes){

    // ignore closed anonymous type
    if ((this.typeDeclaration.bits & ASTNode.IsAnonymousType) != 0 && !this.preserveContent){
        return null;
    }

    TypeDeclaration updatedType = updatedTypeDeclaration(depth + 1, knownTypes);
    if (updatedType != null && (updatedType.bits & ASTNode.IsAnonymousType) != 0){
        /* in presence of an anonymous type, we want the full allocation expression */
        QualifiedAllocationExpression allocation = updatedType.allocation;

        if (allocation.statementEnd == -1) {
            allocation.statementEnd = updatedType.declarationSourceEnd;
        }
        return allocation;
    }
    return updatedType;
}
项目:Eclipse-Postfix-Code-Completion    文件:Parser.java   
protected void consumeAnnotationTypeDeclaration() {
    int length;
    if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
        //there are length declarations
        //dispatch according to the type of the declarations
        dispatchDeclarationInto(length);
    }

    TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr];

    //convert constructor that do not have the type's name into methods
    typeDecl.checkConstructors(this);

    //always add <clinit> (will be remove at code gen time if empty)
    if (this.scanner.containsAssertKeyword) {
        typeDecl.bits |= ASTNode.ContainsAssertion;
    }
    typeDecl.addClinit();
    typeDecl.bodyEnd = this.endStatementPosition;
    if (length == 0 && !containsComment(typeDecl.bodyStart, typeDecl.bodyEnd)) {
        typeDecl.bits |= ASTNode.UndocumentedEmptyBlock;
    }
    typeDecl.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
}
项目:Eclipse-Postfix-Code-Completion    文件:ProblemReporter.java   
public void parameterLackingNonnullAnnotation(Argument argument, ReferenceBinding declaringClass, char[][] inheritedAnnotationName) {
    int sourceStart = 0, sourceEnd = 0;
    if (argument != null) {
        sourceStart = argument.type.sourceStart;
        sourceEnd = argument.type.sourceEnd;
    } else if (this.referenceContext instanceof TypeDeclaration) {
        sourceStart = ((TypeDeclaration) this.referenceContext).sourceStart;
        sourceEnd =   ((TypeDeclaration) this.referenceContext).sourceEnd;
    }
    this.handle(
        IProblem.ParameterLackingNonNullAnnotation, 
        new String[] { new String(declaringClass.readableName()), CharOperation.toString(inheritedAnnotationName)},
        new String[] { new String(declaringClass.shortReadableName()), new String(inheritedAnnotationName[inheritedAnnotationName.length-1])},
        sourceStart,
        sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ProblemReporter.java   
public void unusedPrivateType(TypeDeclaration typeDecl) {
    int severity = computeSeverity(IProblem.UnusedPrivateType);
    if (severity == ProblemSeverities.Ignore) return;
    if (excludeDueToAnnotation(typeDecl.annotations)) return;
    ReferenceBinding type = typeDecl.binding;
    this.handle(
            IProblem.UnusedPrivateType,
        new String[] {
            new String(type.readableName()),
         },
        new String[] {
            new String(type.shortReadableName()),
         },
        severity,
        typeDecl.sourceStart,
        typeDecl.sourceEnd);
}
项目:xtext-extras    文件:JavaDerivedStateComputer.java   
public void installStubs(final Resource resource) {
  boolean _isInfoFile = this.isInfoFile(resource);
  if (_isInfoFile) {
    return;
  }
  final CompilationUnit compilationUnit = this.getCompilationUnit(resource);
  IErrorHandlingPolicy _proceedWithAllProblems = DefaultErrorHandlingPolicies.proceedWithAllProblems();
  CompilerOptions _compilerOptions = this.getCompilerOptions(resource);
  DefaultProblemFactory _defaultProblemFactory = new DefaultProblemFactory();
  ProblemReporter _problemReporter = new ProblemReporter(_proceedWithAllProblems, _compilerOptions, _defaultProblemFactory);
  final Parser parser = new Parser(_problemReporter, true);
  final CompilationResult compilationResult = new CompilationResult(compilationUnit, 0, 1, (-1));
  final CompilationUnitDeclaration result = parser.dietParse(compilationUnit, compilationResult);
  if ((result.types != null)) {
    for (final TypeDeclaration type : result.types) {
      {
        ImportReference _currentPackage = result.currentPackage;
        char[][] _importName = null;
        if (_currentPackage!=null) {
          _importName=_currentPackage.getImportName();
        }
        List<String> _map = null;
        if (((List<char[]>)Conversions.doWrapArray(_importName))!=null) {
          final Function1<char[], String> _function = (char[] it) -> {
            return String.valueOf(it);
          };
          _map=ListExtensions.<char[], String>map(((List<char[]>)Conversions.doWrapArray(_importName)), _function);
        }
        String _join = null;
        if (_map!=null) {
          _join=IterableExtensions.join(_map, ".");
        }
        final String packageName = _join;
        final JvmDeclaredType jvmType = this.createType(type, packageName);
        resource.getContents().add(jvmType);
      }
    }
  }
}
项目:lombok-ianchiu    文件:Eclipse.java   
public static boolean hasClinit(TypeDeclaration parent) {
    if (parent.methods == null) return false;

    for (AbstractMethodDeclaration method : parent.methods) {
        if (method instanceof Clinit) return true;
    }
    return false;
}