org.eclipse.jdt.internal.compiler.ast.TypeDeclaration Java Examples

The following examples show how to use org.eclipse.jdt.internal.compiler.ast.TypeDeclaration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SourceIndexerRequestor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void addDefaultConstructorIfNecessary(TypeInfo typeInfo) {
	boolean hasConstructor = false;
	
	TypeDeclaration typeDeclaration = typeInfo.node;
	AbstractMethodDeclaration[] methods = typeDeclaration.methods;
	int methodCounter = methods == null ? 0 : methods.length;
	done : for (int i = 0; i < methodCounter; i++) {
		AbstractMethodDeclaration method = methods[i];
		if (method.isConstructor() && !method.isDefaultConstructor()) {
			hasConstructor = true;
			break done;
		}
	}
	
	if (!hasConstructor) {
		this.indexer.addDefaultConstructorDeclaration(
				typeInfo.name,
				this.packageName == null ? CharOperation.NO_CHAR : this.packageName,
				typeInfo.modifiers,
				getMoreExtraFlags(typeInfo.extraFlags));
	}
}
 
Example #2
Source File: RecoveredType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: BindingKeyResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: Util.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the outer most enclosing type's visibility for the given TypeDeclaration
 * and visibility based on compiler options.
 */
public static int computeOuterMostVisibility(TypeDeclaration typeDeclaration, int visibility) {
	while (typeDeclaration != null) {
		switch (typeDeclaration.modifiers & ExtraCompilerModifiers.AccVisibilityMASK) {
			case ClassFileConstants.AccPrivate:
				visibility = ClassFileConstants.AccPrivate;
				break;
			case ClassFileConstants.AccDefault:
				if (visibility != ClassFileConstants.AccPrivate) {
					visibility = ClassFileConstants.AccDefault;
				}
				break;
			case ClassFileConstants.AccProtected:
				if (visibility == ClassFileConstants.AccPublic) {
					visibility = ClassFileConstants.AccProtected;
				}
				break;
		}
		typeDeclaration = typeDeclaration.enclosingType;
	}
	return visibility;
}
 
Example #5
Source File: Extractor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean visit(TypeDeclaration localTypeDeclaration, BlockScope scope) {
    Annotation[] annotations = localTypeDeclaration.annotations;
    if (hasRelevantAnnotations(annotations)) {
        SourceTypeBinding binding = localTypeDeclaration.binding;
        if (binding == null) {
            return true;
        }

        String fqn = getFqn(scope);
        if (fqn == null) {
            fqn = new String(localTypeDeclaration.binding.readableName());
        }
        Item item = ClassItem.create(fqn, ClassKind.forType(localTypeDeclaration));
        addItem(fqn, item);
        addAnnotations(annotations, item);

    }
    return true;
}
 
Example #6
Source File: Extractor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) {
    Annotation[] annotations = memberTypeDeclaration.annotations;
    if (hasRelevantAnnotations(annotations)) {
        SourceTypeBinding binding = memberTypeDeclaration.binding;
        if (!(binding instanceof MemberTypeBinding)) {
            return true;
        }
        if (binding.isAnnotationType() || binding.isAnonymousType()) {
            return false;
        }

        String fqn = new String(memberTypeDeclaration.binding.readableName());
        Item item = ClassItem.create(fqn, ClassKind.forType(memberTypeDeclaration));
        addItem(fqn, item);
        addAnnotations(annotations, item);
    }
    return true;
}
 
Example #7
Source File: Extractor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) {
    Annotation[] annotations = fieldDeclaration.annotations;
    if (hasRelevantAnnotations(annotations)) {
        FieldBinding fieldBinding = fieldDeclaration.binding;
        if (fieldBinding == null) {
            return false;
        }

        String fqn = getFqn(scope);
        ClassKind kind = scope.referenceContext instanceof TypeDeclaration ?
                ClassKind.forType((TypeDeclaration) scope.referenceContext) :
                ClassKind.CLASS;
        Item item = FieldItem.create(fqn, kind, fieldBinding);
        if (item != null && fqn != null) {
            addItem(fqn, item);
            addAnnotations(annotations, item);
        }
    }
    return false;
}
 
Example #8
Source File: SingletonEclipseHandler.java    From tutorials with MIT License 6 votes vote down vote up
private ConstructorDeclaration addConstructor(EclipseNode singletonClass, TypeDeclaration astNode) {
    ConstructorDeclaration constructor = new ConstructorDeclaration(astNode.compilationResult);
    constructor.modifiers = AccPrivate;
    constructor.selector = astNode.name;
    constructor.sourceStart = astNode.sourceStart;
    constructor.sourceEnd = astNode.sourceEnd;
    constructor.thrownExceptions = null;
    constructor.typeParameters = null;
    constructor.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    constructor.bodyStart = constructor.declarationSourceStart = constructor.sourceStart = astNode.sourceStart;
    constructor.bodyEnd = constructor.declarationSourceEnd = constructor.sourceEnd = astNode.sourceEnd;
    constructor.arguments = null;

    EclipseHandlerUtil.injectMethod(singletonClass, constructor);
    return constructor;
}
 
Example #9
Source File: PatchExtensionMethodCompletionProposal.java    From EasyMPermission with MIT License 6 votes vote down vote up
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;
	}
 
Example #10
Source File: LocalTypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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();
	MethodBinding methodBinding = methodScope.referenceMethodBinding();
	if (methodBinding != null) {
		this.enclosingMethod = methodBinding;
	}
}
 
Example #11
Source File: SourceExtraction.java    From immutables with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #12
Source File: AnnotationDiscoveryVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@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;
}
 
Example #13
Source File: SourceIndexerRequestor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see ISourceElementRequestor#enterType(ISourceElementRequestor.TypeInfo)
 */
public void enterType(TypeInfo typeInfo) {
	// TODO (jerome) might want to merge the 4 methods
	switch (TypeDeclaration.kind(typeInfo.modifiers)) {
		case TypeDeclaration.CLASS_DECL:
			enterClass(typeInfo);
			break;
		case TypeDeclaration.ANNOTATION_TYPE_DECL:
			enterAnnotationType(typeInfo);
			break;
		case TypeDeclaration.INTERFACE_DECL:
			enterInterface(typeInfo);
			break;
		case TypeDeclaration.ENUM_DECL:
			enterEnum(typeInfo);
			break;
	}
}
 
Example #14
Source File: EclipseHandlerUtil.java    From EasyMPermission with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #15
Source File: EclipseHandlerUtil.java    From EasyMPermission with MIT License 6 votes vote down vote up
public static TypeReference cloneSelfType(EclipseNode context, ASTNode source) {
	int pS = source == null ? 0 : source.sourceStart, pE = source == null ? 0 : source.sourceEnd;
	long p = (long)pS << 32 | pE;
	EclipseNode type = context;
	TypeReference result = null;
	while (type != null && type.getKind() != Kind.TYPE) type = type.up();
	if (type != null && type.get() instanceof TypeDeclaration) {
		TypeDeclaration typeDecl = (TypeDeclaration) type.get();
		if (typeDecl.typeParameters != null && typeDecl.typeParameters.length > 0) {
			TypeReference[] refs = new TypeReference[typeDecl.typeParameters.length];
			int idx = 0;
			for (TypeParameter param : typeDecl.typeParameters) {
				TypeReference typeRef = new SingleTypeReference(param.name, (long)param.sourceStart << 32 | param.sourceEnd);
				if (source != null) setGeneratedBy(typeRef, source);
				refs[idx++] = typeRef;
			}
			result = new ParameterizedSingleTypeReference(typeDecl.name, refs, 0, p);
		} else {
			result = new SingleTypeReference(((TypeDeclaration)type.get()).name, p);
		}
	}
	if (result != null && source != null) setGeneratedBy(result, source);
	return result;
}
 
Example #16
Source File: EclipseHandlerUtil.java    From EasyMPermission with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example #17
Source File: FlowContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public FlowInfo getInitsForFinalBlankInitializationCheck(TypeBinding declaringType, FlowInfo flowInfo) {
	FlowContext current = this;
	FlowInfo inits = flowInfo;
	do {
		if (current instanceof InitializationFlowContext) {
			InitializationFlowContext initializationContext = (InitializationFlowContext) current;
			if (TypeBinding.equalsEquals(((TypeDeclaration)initializationContext.associatedNode).binding, declaringType)) {
				return inits;
			}
			inits = initializationContext.initsBeforeContext;
			current = initializationContext.initializationParent;
		} else if (current instanceof ExceptionHandlingFlowContext) {
			ExceptionHandlingFlowContext exceptionContext = (ExceptionHandlingFlowContext) current;
			current = exceptionContext.initializationParent == null ? exceptionContext.getLocalParent() : exceptionContext.initializationParent;
		} else {
			current = current.getLocalParent();
		}
	} while (current != null);
	// not found
	return null;
}
 
Example #18
Source File: NameLookup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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.
	}
}
 
Example #19
Source File: SingletonEclipseHandler.java    From tutorials with MIT License 6 votes vote down vote up
private FieldDeclaration addInstanceVar(ConstructorDeclaration constructor, TypeReference typeReference, TypeDeclaration innerClass) {
    FieldDeclaration field = new FieldDeclaration();
    field.modifiers = AccPrivate | AccStatic | AccFinal;
    field.name = "INSTANCE".toCharArray();

    field.type = typeReference;

    AllocationExpression exp = new AllocationExpression();
    exp.type = typeReference;
    exp.binding = constructor.binding;
    exp.sourceStart = innerClass.sourceStart;
    exp.sourceEnd = innerClass.sourceEnd;

    field.initialization = exp;
    return field;
}
 
Example #20
Source File: RecoveredType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #21
Source File: ASTNodeFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public FieldDeclaration findField(IField fieldHandle) {
	TypeDeclaration typeDecl = findType((IType)fieldHandle.getParent());
	if (typeDecl == null) return null;
	FieldDeclaration[] fields = typeDecl.fields;
	if (fields != null) {
		char[] fieldName = fieldHandle.getElementName().toCharArray();
		for (int i = 0, length = fields.length; i < length; i++) {
			FieldDeclaration field = fields[i];
			if (CharOperation.equals(fieldName, field.name)) {
				return field;
			}
		}
	}
	return null;
}
 
Example #22
Source File: ASTNodeFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public Initializer findInitializer(IInitializer initializerHandle) {
	TypeDeclaration typeDecl = findType((IType)initializerHandle.getParent());
	if (typeDecl == null) return null;
	FieldDeclaration[] fields = typeDecl.fields;
	if (fields != null) {
		int occurenceCount = ((SourceRefElement)initializerHandle).occurrenceCount;
		for (int i = 0, length = fields.length; i < length; i++) {
			FieldDeclaration field = fields[i];
			if (field instanceof Initializer && --occurenceCount == 0) {
				return (Initializer)field;
			}
		}
	}
	return null;
}
 
Example #23
Source File: NodeSearcher.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean visit(
	TypeDeclaration typeDeclaration,
	CompilationUnitScope scope) {
		if (typeDeclaration.declarationSourceStart <= this.position
			&& this.position <= typeDeclaration.declarationSourceEnd) {
				this.enclosingType = typeDeclaration;
				return true;
		}
		return false;
}
 
Example #24
Source File: EcjParser.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private void addTypeDeclaration(TypeDeclaration typeDeclaration) {
    String type = new String(typeDeclaration.binding.readableName());
    mTypeUnits.put(type, typeDeclaration);
    // Recurse on member types
    if (typeDeclaration.memberTypes != null) {
        for (TypeDeclaration member : typeDeclaration.memberTypes) {
            addTypeDeclaration(member);
        }
    }
}
 
Example #25
Source File: RecoveredAnnotation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public RecoveredElement add(TypeDeclaration typeDeclaration, int bracketBalanceValue) {
	if (this.annotation == null && (typeDeclaration.bits & ASTNode.IsAnonymousType) != 0){
		// ignore anonymous type in annotations when annotation isn't fully recovered
		return this;
	}
	return super.add(typeDeclaration, bracketBalanceValue);
}
 
Example #26
Source File: BinaryTypeConverter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Convert a binary type into an AST type declaration and put it in the given compilation unit.
 */
public TypeDeclaration buildTypeDeclaration(IType type, CompilationUnitDeclaration compilationUnit)  throws JavaModelException {
	PackageFragment pkg = (PackageFragment) type.getPackageFragment();
	char[][] packageName = Util.toCharArrays(pkg.names);

	if (packageName.length > 0) {
		compilationUnit.currentPackage = new ImportReference(packageName, new long[]{0}, false, ClassFileConstants.AccDefault);
	}

	/* convert type */
	TypeDeclaration typeDeclaration = convert(type, null, null);

	IType alreadyComputedMember = type;
	IType parent = type.getDeclaringType();
	TypeDeclaration previousDeclaration = typeDeclaration;
	while(parent != null) {
		TypeDeclaration declaration = convert(parent, alreadyComputedMember, previousDeclaration);

		alreadyComputedMember = parent;
		previousDeclaration = declaration;
		parent = parent.getDeclaringType();
	}

	compilationUnit.types = new TypeDeclaration[]{previousDeclaration};

	return typeDeclaration;
}
 
Example #27
Source File: HandleBuilder.java    From EasyMPermission with MIT License 5 votes vote down vote up
public EclipseNode makeBuilderClass(EclipseNode tdParent, String builderClassName, TypeParameter[] typeParams, ASTNode source) {
	TypeDeclaration parent = (TypeDeclaration) tdParent.get();
	TypeDeclaration builder = new TypeDeclaration(parent.compilationResult);
	builder.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
	builder.modifiers |= ClassFileConstants.AccPublic | ClassFileConstants.AccStatic;
	builder.typeParameters = copyTypeParams(typeParams, source);
	builder.name = builderClassName.toCharArray();
	builder.traverse(new SetGeneratedByVisitor(source), (ClassScope) null);
	return injectType(tdParent, builder);
}
 
Example #28
Source File: SetGeneratedByVisitor.java    From EasyMPermission with MIT License 5 votes vote down vote up
private void fixPositions(TypeDeclaration node) {
	node.sourceEnd = sourceEnd;
	node.sourceStart = sourceStart;
	node.bodyEnd = sourceEnd;
	node.bodyStart = sourceStart;
	node.declarationSourceEnd = sourceEnd;
	node.declarationSourceStart = sourceStart;
	node.modifiersSourceStart = sourceStart;
}
 
Example #29
Source File: CompletionElementNotifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected char[][] getInterfaceNames(TypeDeclaration typeDeclaration) {
	char[][] interfaceNames = null;
	int superInterfacesLength = 0;
	TypeReference[] superInterfaces = typeDeclaration.superInterfaces;
	if (superInterfaces != null) {
		superInterfacesLength = superInterfaces.length;
		interfaceNames = new char[superInterfacesLength][];
	} else {
		if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) {
			// see PR 3442
			QualifiedAllocationExpression alloc = typeDeclaration.allocation;
			if (alloc != null && alloc.type != null) {
				superInterfaces = new TypeReference[] { alloc.type};
				superInterfacesLength = 1;
				interfaceNames = new char[1][];
			}
		}
	}
	if (superInterfaces != null) {
		int superInterfaceCount = 0;
		next: for (int i = 0; i < superInterfacesLength; i++) {
			TypeReference superInterface = superInterfaces[i];

			if (superInterface instanceof CompletionOnKeyword) continue next;
			if (CompletionUnitStructureRequestor.hasEmptyName(superInterface, this.assistNode)) continue next;

			interfaceNames[superInterfaceCount++] = CharOperation.concatWith(superInterface.getParameterizedTypeName(), '.');
		}

		if (superInterfaceCount == 0) return null;
		if (superInterfaceCount < superInterfacesLength) {
			System.arraycopy(interfaceNames, 0, interfaceNames = new char[superInterfaceCount][], 0, superInterfaceCount);
		}
	}
	return interfaceNames;
}
 
Example #30
Source File: EclipseHandlerUtil.java    From EasyMPermission with MIT License 5 votes vote down vote up
static Expression createFieldAccessor(EclipseNode field, FieldAccess fieldAccess, ASTNode source) {
	int pS = source == null ? 0 : source.sourceStart, pE = source == null ? 0 : source.sourceEnd;
	long p = (long)pS << 32 | pE;
	
	boolean lookForGetter = lookForGetter(field, fieldAccess);
	
	GetterMethod getter = lookForGetter ? findGetter(field) : null;
	
	if (getter == null) {
		FieldDeclaration fieldDecl = (FieldDeclaration)field.get();
		FieldReference ref = new FieldReference(fieldDecl.name, p);
		if ((fieldDecl.modifiers & ClassFileConstants.AccStatic) != 0) {
			EclipseNode containerNode = field.up();
			if (containerNode != null && containerNode.get() instanceof TypeDeclaration) {
				ref.receiver = new SingleNameReference(((TypeDeclaration)containerNode.get()).name, p);
			} else {
				Expression smallRef = new FieldReference(field.getName().toCharArray(), p);
				if (source != null) setGeneratedBy(smallRef, source);
				return smallRef;
			}
		} else {
			ref.receiver = new ThisReference(pS, pE);
		}
		
		if (source != null) {
			setGeneratedBy(ref, source);
			setGeneratedBy(ref.receiver, source);
		}
		return ref;
	}
	
	MessageSend call = new MessageSend();
	setGeneratedBy(call, source);
	call.sourceStart = pS; call.statementEnd = call.sourceEnd = pE;
	call.receiver = new ThisReference(pS, pE);
	setGeneratedBy(call.receiver, source);
	call.selector = getter.name;
	return call;
}