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

The following examples show how to use org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration. 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: MethodBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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);
			CompilerOptions options = scope.compilerOptions();
			if (options.isAnnotationBasedNullAnalysisEnabled) {
				boolean isJdk18 = options.sourceLevel >= ClassFileConstants.JDK1_8;
				long nullDefaultBits = isJdk18 ? this.defaultNullness
						: 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, isJdk18)) {
						declaringSourceType.checkRedundantNullnessDefaultRecurse(methodDecl, methodDecl.annotations, nullDefaultBits, isJdk18);
					}
				}
			}
		}
	}
	return originalMethod.tagBits;
}
 
Example #2
Source File: Extractor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean visit(Argument argument, BlockScope scope) {
    Annotation[] annotations = argument.annotations;
    if (hasRelevantAnnotations(annotations)) {
        ReferenceContext referenceContext = scope.referenceContext();
        if (referenceContext instanceof AbstractMethodDeclaration) {
            MethodBinding binding = ((AbstractMethodDeclaration) referenceContext).binding;
            ClassScope classScope = findClassScope(scope);
            if (classScope == null) {
                return false;
            }
            String fqn = getFqn(classScope);
            ClassKind kind = ClassKind.forType(classScope.referenceContext);
            Item item = ParameterItem.create(
                    (AbstractMethodDeclaration) referenceContext, argument, fqn, kind,
                    binding, argument.binding);
            if (item != null) {
                addItem(fqn, item);
                addAnnotations(annotations, item);
            }
        }
    }
    return false;
}
 
Example #3
Source File: Extractor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
static MethodItem create(@Nullable String classFqn,
                         @NonNull ClassKind classKind,
                         @NonNull AbstractMethodDeclaration declaration,
                         @Nullable MethodBinding binding) {
    if (classFqn == null || binding == null) {
        return null;
    }
    String returnType = getReturnType(binding);
    String methodName = getMethodName(binding);
    Argument[] arguments = declaration.arguments;
    boolean isVarargs = arguments != null && arguments.length > 0 &&
            arguments[arguments.length - 1].isVarArgs();
    String parameterList = getParameterList(binding, isVarargs);
    if (returnType == null || methodName == null) {
        return null;
    }
    //noinspection PointlessBooleanExpression,ConstantConditions
    if (!INCLUDE_TYPE_ARGS) {
        classFqn = ApiDatabase.getRawClass(classFqn);
        methodName = ApiDatabase.getRawMethod(methodName);
    }
    return new MethodItem(classFqn, classKind, returnType,
            methodName, parameterList,
            binding.isConstructor());
}
 
Example #4
Source File: ASTConstructBodySignature.java    From steady with Apache License 2.0 6 votes vote down vote up
/**
 * <p>convertConstructBody.</p>
 *
 * @param methodName a {@link java.lang.String} object.
 * @return a {@link ch.uzh.ifi.seal.changedistiller.treedifferencing.Node} object.
 */
public Node convertConstructBody(String methodName) {
     AbstractMethodDeclaration method = CompilationUtils.findMethod(fCompilation.getCompilationUnit(), methodName);
     fRoot = new Node(JavaEntityType.METHOD, methodName);
     fRoot.setEntity(new SourceCodeEntity(methodName, JavaEntityType.METHOD, new SourceRange(
             method.declarationSourceStart,
             method.declarationSourceEnd)));

     //List<Comment> comments = CompilationUtils.extractComments(fCompilation);

     //Here initialize the visitor with parameters
     //sMethodBodyConverter.initialize(fRoot, method, comments, fCompilation.getScanner());

     //Removed the <<comments>> argument from the previous statement
     sMethodBodyConverter.initialize(fRoot, method, null, fCompilation.getScanner());

     //AbstractMethodDeclaration.traverse(ASTVisitor,ClassScope)
     method.traverse(sMethodBodyConverter, (ClassScope) null);
     return fRoot;
 }
 
Example #5
Source File: EclipseAST.java    From EasyMPermission with MIT License 6 votes vote down vote up
/** {@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);
	}
}
 
Example #6
Source File: EclipseHandlerUtil.java    From EasyMPermission with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #7
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 #8
Source File: UnresolvedReferenceNameFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private ASTNode getEnclosingDeclaration() {
	int i = this.parentsPtr;
	while (i > -1) {
		ASTNode parent = this.parents[i];
		if (parent instanceof AbstractMethodDeclaration) {
			return parent;
		} else if (parent instanceof Initializer) {
			return parent;
		} else if (parent instanceof FieldDeclaration) {
			return parent;
		} else if (parent instanceof TypeDeclaration) {
			return parent;
		}
		i--;
	}
	return null;
}
 
Example #9
Source File: MethodBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public AbstractMethodDeclaration sourceMethod() {
	if (isSynthetic()) {
		return null;
	}
	SourceTypeBinding sourceType;
	try {
		sourceType = (SourceTypeBinding) this.declaringClass;
	} catch (ClassCastException e) {
		return null;
	}

	AbstractMethodDeclaration[] methods = sourceType.scope != null ? sourceType.scope.referenceContext.methods : null;
	if (methods != null) {
		for (int i = methods.length; --i >= 0;)
			if (this == methods[i].binding)
				return methods[i];
	}
	return null;
}
 
Example #10
Source File: CompletionElementNotifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected char[][] getThrownExceptions(AbstractMethodDeclaration methodDeclaration) {
	char[][] thrownExceptionTypes = null;
	TypeReference[] thrownExceptions = methodDeclaration.thrownExceptions;
	if (thrownExceptions != null) {
		int thrownExceptionLength = thrownExceptions.length;
		int thrownExceptionCount = 0;
		thrownExceptionTypes = new char[thrownExceptionLength][];
		next : for (int i = 0; i < thrownExceptionLength; i++) {
			TypeReference thrownException = thrownExceptions[i];

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

			thrownExceptionTypes[thrownExceptionCount++] =
				CharOperation.concatWith(thrownException.getParameterizedTypeName(), '.');
		}

		if (thrownExceptionCount == 0) return null;
		if (thrownExceptionCount < thrownExceptionLength) {
			System.arraycopy(thrownExceptionTypes, 0, thrownExceptionTypes = new char[thrownExceptionCount][], 0, thrownExceptionCount);
		}
	}
	return thrownExceptionTypes;
}
 
Example #11
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 #12
Source File: SourceElementNotifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void visitIfNeeded(AbstractMethodDeclaration method) {
	if (this.localDeclarationVisitor != null
		&& (method.bits & ASTNode.HasLocalType) != 0) {
			if (method instanceof ConstructorDeclaration) {
				ConstructorDeclaration constructorDeclaration = (ConstructorDeclaration) method;
				if (constructorDeclaration.constructorCall != null) {
					constructorDeclaration.constructorCall.traverse(this.localDeclarationVisitor, method.scope);
				}
			}
			if (method.statements != null) {
				int statementsLength = method.statements.length;
				for (int i = 0; i < statementsLength; i++)
					method.statements[i].traverse(this.localDeclarationVisitor, method.scope);
			}
	}
}
 
Example #13
Source File: DefaultBindingResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
IMethodBinding resolveMember(AnnotationTypeMemberDeclaration declaration) {
	Object oldNode = this.newAstToOldAst.get(declaration);
	if (oldNode instanceof AbstractMethodDeclaration) {
		AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) oldNode;
		IMethodBinding methodBinding = getMethodBinding(methodDeclaration.binding);
		if (methodBinding == null) {
			return null;
		}
		this.bindingsToAstNodes.put(methodBinding, declaration);
		String key = methodBinding.getKey();
		if (key != null) {
			this.bindingTables.bindingKeysToBindings.put(key, methodBinding);
		}
		return methodBinding;
	}
	return null;
}
 
Example #14
Source File: DefaultBindingResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
synchronized IMethodBinding resolveMethod(MethodDeclaration method) {
	Object oldNode = this.newAstToOldAst.get(method);
	if (oldNode instanceof AbstractMethodDeclaration) {
		AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) oldNode;
		IMethodBinding methodBinding = getMethodBinding(methodDeclaration.binding);
		if (methodBinding == null) {
			return null;
		}
		this.bindingsToAstNodes.put(methodBinding, method);
		String key = methodBinding.getKey();
		if (key != null) {
			this.bindingTables.bindingKeysToBindings.put(key, methodBinding);
		}
		return methodBinding;
	}
	return null;
}
 
Example #15
Source File: SourceTypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void createArgumentBindings(MethodBinding method, CompilerOptions compilerOptions) {
	
	if (!isPrototype()) throw new IllegalStateException();
	if (compilerOptions.isAnnotationBasedNullAnalysisEnabled)
		getNullDefault(); // ensure initialized
	AbstractMethodDeclaration methodDecl = method.sourceMethod();
	if (methodDecl != null) {
		// while creating argument bindings we also collect explicit null annotations:
		if (method.parameters != Binding.NO_PARAMETERS)
			methodDecl.createArgumentBindings();
		// add implicit annotations (inherited(?) & default):
		if (compilerOptions.isAnnotationBasedNullAnalysisEnabled) {
			new ImplicitNullAnnotationVerifier(this.scope.environment()).checkImplicitNullAnnotations(method, methodDecl, true, this.scope);
		}
	}
}
 
Example #16
Source File: CompilationResult.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int computePriority(CategorizedProblem problem){
	final int P_STATIC = 10000;
	final int P_OUTSIDE_METHOD = 40000;
	final int P_FIRST_ERROR = 20000;
	final int P_ERROR = 100000;

	int priority = 10000 - problem.getSourceLineNumber(); // early problems first
	if (priority < 0) priority = 0;
	if (problem.isError()){
		priority += P_ERROR;
	}
	ReferenceContext context = this.problemsMap == null ? null : (ReferenceContext) this.problemsMap.get(problem);
	if (context != null){
		if (context instanceof AbstractMethodDeclaration){
			AbstractMethodDeclaration method = (AbstractMethodDeclaration) context;
			if (method.isStatic()) {
				priority += P_STATIC;
			}
		} else {
			priority += P_OUTSIDE_METHOD;
		}
		if (this.firstErrors.contains(problem)){ // if context is null, firstErrors is null too
		  priority += P_FIRST_ERROR;
	    }
	} else {
		priority += P_OUTSIDE_METHOD;
	}
	return priority;
}
 
Example #17
Source File: ExceptionHandlingFlowContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void complainIfUnusedExceptionHandlers(AbstractMethodDeclaration method) {
	MethodScope scope = method.scope;
	// can optionally skip overriding methods
	if ((method.binding.modifiers & (ExtraCompilerModifiers.AccOverriding | ExtraCompilerModifiers.AccImplementing)) != 0
	        && !scope.compilerOptions().reportUnusedDeclaredThrownExceptionWhenOverriding) {
	    return;
	}

	// report errors for unreachable exception handlers
	TypeBinding[] docCommentReferences = null;
	int docCommentReferencesLength = 0;
	if (scope.compilerOptions().
				reportUnusedDeclaredThrownExceptionIncludeDocCommentReference &&
			method.javadoc != null &&
			method.javadoc.exceptionReferences != null &&
			(docCommentReferencesLength = method.javadoc.exceptionReferences.length) > 0) {
		docCommentReferences = new TypeBinding[docCommentReferencesLength];
		for (int i = 0; i < docCommentReferencesLength; i++) {
			docCommentReferences[i] = method.javadoc.exceptionReferences[i].resolvedType;
		}
	}
	nextHandledException: for (int i = 0, count = this.handledExceptions.length; i < count; i++) {
		int index = this.indexes.get(this.handledExceptions[i]);
		if ((this.isReached[index / ExceptionHandlingFlowContext.BitCacheSize] & 1 << (index % ExceptionHandlingFlowContext.BitCacheSize)) == 0) {
			for (int j = 0; j < docCommentReferencesLength; j++) {
				if (TypeBinding.equalsEquals(docCommentReferences[j], this.handledExceptions[i])) {
					continue nextHandledException;
				}
			}
			scope.problemReporter().unusedDeclaredThrownException(
				this.handledExceptions[index],
				method,
				method.thrownExceptions[index]);
		}
	}
}
 
Example #18
Source File: SourceTypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static void rejectTypeAnnotatedVoidMethod(AbstractMethodDeclaration methodDecl) {
	Annotation[] annotations = methodDecl.annotations;
	int length = annotations == null ? 0 : annotations.length;
	for (int i = 0; i < length; i++) {
		ReferenceBinding binding = (ReferenceBinding) annotations[i].resolvedType;
		if (binding != null
				&& (binding.tagBits & TagBits.AnnotationForTypeUse) != 0
				&& (binding.tagBits & TagBits.AnnotationForMethod) == 0) {
			methodDecl.scope.problemReporter().illegalUsageOfTypeAnnotations(annotations[i]);
		}
	}
}
 
Example #19
Source File: SourceElementNotifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected char[][] getThrownExceptions(AbstractMethodDeclaration methodDeclaration) {
	char[][] thrownExceptionTypes = null;
	TypeReference[] thrownExceptions = methodDeclaration.thrownExceptions;
	if (thrownExceptions != null) {
		int thrownExceptionLength = thrownExceptions.length;
		thrownExceptionTypes = new char[thrownExceptionLength][];
		for (int i = 0; i < thrownExceptionLength; i++) {
			thrownExceptionTypes[i] =
				CharOperation.concatWith(thrownExceptions[i].getParameterizedTypeName(), '.');
		}
	}
	return thrownExceptionTypes;
}
 
Example #20
Source File: RecoveredBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public RecoveredElement add(AbstractMethodDeclaration methodDeclaration, int bracketBalanceValue) {
	if (this.parent != null && this.parent instanceof RecoveredMethod) {
		RecoveredMethod enclosingRecoveredMethod = (RecoveredMethod) this.parent;
		if (enclosingRecoveredMethod.methodBody == this && enclosingRecoveredMethod.parent == null) {
			resetPendingModifiers();
			// the element cannot be added because we are in the body of a top level method
			return this; // ignore this element
		}
	}
	return super.add(methodDeclaration, bracketBalanceValue);
}
 
Example #21
Source File: Util.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static String[] typeParameterSignatures(AbstractMethodDeclaration method) {
	Argument[] args = method.arguments;
	if (args != null) {
		int length = args.length;
		String[] signatures = new String[length];
		for (int i = 0; i < args.length; i++) {
			Argument arg = args[i];
			signatures[i] = typeSignature(arg.type);
		}
		return signatures;
	}
	return CharOperation.NO_STRINGS;
}
 
Example #22
Source File: Eclipse.java    From EasyMPermission with MIT License 5 votes vote down vote up
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;
}
 
Example #23
Source File: SourceIndexer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void purgeMethodStatements(TypeDeclaration type) {
	AbstractMethodDeclaration[] methods = type.methods;
	for (int j = 0, length = methods == null ? 0 : methods.length; j < length; j++) {
		AbstractMethodDeclaration method = methods[j];
		if (method != null && (method.bits & ASTNode.HasFunctionalInterfaceTypes) == 0) {
			method.statements = null;
			method.javadoc = null;
		}
	}

	TypeDeclaration[] memberTypes = type.memberTypes;
	if (memberTypes != null)
		for (int i = 0, l = memberTypes.length; i < l; i++)
			purgeMethodStatements(memberTypes[i]);
}
 
Example #24
Source File: AssistParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Parse the block statements inside the given method declaration and try to complete at the
 * cursor location.
 */
public void parseBlockStatements(AbstractMethodDeclaration md, CompilationUnitDeclaration unit) {
	if (md instanceof MethodDeclaration) {
		parseBlockStatements((MethodDeclaration) md, unit);
	} else if (md instanceof ConstructorDeclaration) {
		parseBlockStatements((ConstructorDeclaration) md, unit);
	}
}
 
Example #25
Source File: UnresolvedReferenceNameFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void find(
		char[] startWith,
		AbstractMethodDeclaration methodDeclaration,
		int from,
		char[][] discouragedNames,
		UnresolvedReferenceNameRequestor nameRequestor) {
	MethodDeclaration fakeMethod =
		this.findAfter(startWith, methodDeclaration.scope, from, methodDeclaration.bodyEnd, MAX_LINE_COUNT, false, discouragedNames, nameRequestor);
	if (fakeMethod != null) fakeMethod.traverse(this, methodDeclaration.scope.classScope());
}
 
Example #26
Source File: EclipseNode.java    From EasyMPermission with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected boolean calculateIsStructurallySignificant(ASTNode parent) {
	if (node instanceof TypeDeclaration) return true;
	if (node instanceof AbstractMethodDeclaration) return true;
	if (node instanceof FieldDeclaration) return true;
	if (node instanceof LocalDeclaration) return true;
	if (node instanceof CompilationUnitDeclaration) return true;
	return false;
}
 
Example #27
Source File: EclipseNode.java    From EasyMPermission with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
@Override public String getName() {
	final char[] n;
	if (node instanceof TypeDeclaration) n = ((TypeDeclaration)node).name;
	else if (node instanceof FieldDeclaration) n = ((FieldDeclaration)node).name;
	else if (node instanceof AbstractMethodDeclaration) n = ((AbstractMethodDeclaration)node).selector;
	else if (node instanceof LocalDeclaration) n = ((LocalDeclaration)node).name;
	else n = null;
	
	return n == null ? null : new String(n);
}
 
Example #28
Source File: EclipseSingularsRecipes.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void setGeneratedByRecursive(ASTNode target) {
	SetGeneratedByVisitor visitor = new SetGeneratedByVisitor(source);
	
	if (target instanceof AbstractMethodDeclaration) {
		((AbstractMethodDeclaration) target).traverse(visitor, (ClassScope) null);
	} else if (target instanceof FieldDeclaration) {
		((FieldDeclaration) target).traverse(visitor, (MethodScope) null);
	} else {
		target.traverse(visitor, null);
	}
}
 
Example #29
Source File: SetGeneratedByVisitor.java    From EasyMPermission with MIT License 5 votes vote down vote up
private void fixPositions(AbstractMethodDeclaration node) {
	node.sourceEnd = sourceEnd;
	node.sourceStart = sourceStart;
	node.bodyEnd = sourceEnd;
	node.bodyStart = sourceStart;
	node.declarationSourceEnd = sourceEnd;
	node.declarationSourceStart = sourceStart;
	node.modifiersSourceStart = sourceStart;
}
 
Example #30
Source File: VariableBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public IMethodBinding getDeclaringMethod() {
	if (!isField()) {
		ASTNode node = this.resolver.findDeclaringNode(this);
		while (true) {
			if (node == null) {
				if (this.binding instanceof LocalVariableBinding) {
					LocalVariableBinding localVariableBinding = (LocalVariableBinding) this.binding;
					BlockScope blockScope = localVariableBinding.declaringScope;
					if (blockScope != null) {
						ReferenceContext referenceContext = blockScope.referenceContext();
						if (referenceContext instanceof Initializer) {
							return null;
						}
						if (referenceContext instanceof AbstractMethodDeclaration) {
							return this.resolver.getMethodBinding(((AbstractMethodDeclaration) referenceContext).binding);
						}
					}
				}
				return null;
			}
			switch(node.getNodeType()) {
				case ASTNode.INITIALIZER :
					return null;
				case ASTNode.METHOD_DECLARATION :
					MethodDeclaration methodDeclaration = (MethodDeclaration) node;
					return methodDeclaration.resolveBinding();
				default:
					node = node.getParent();
			}
		}
	}
	return null;
}