-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mmews
committed
Jul 15, 2024
1 parent
a24f4c0
commit 17f8aed
Showing
4 changed files
with
132 additions
and
117 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...lipse.n4js/src/org/eclipse/n4js/validation/validators/FindClassifierInHierarchyUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (c) 2016 NumberFour AG. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* NumberFour AG - Initial API and implementation | ||
*/ | ||
package org.eclipse.n4js.validation.validators; | ||
|
||
import static org.eclipse.xtext.xbase.lib.IterableExtensions.filter; | ||
|
||
import org.eclipse.n4js.n4JS.N4ClassifierDefinition; | ||
import org.eclipse.n4js.n4JS.TypeReferenceNode; | ||
import org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef; | ||
import org.eclipse.n4js.ts.typeRefs.TypeRef; | ||
import org.eclipse.n4js.ts.types.ContainerType; | ||
import org.eclipse.n4js.ts.types.TMember; | ||
import org.eclipse.n4js.ts.types.Type; | ||
|
||
/** | ||
* Helper class extracted from N4JSAllMemberValidator | ||
*/ | ||
public class FindClassifierInHierarchyUtils { | ||
|
||
/***/ | ||
public static Iterable<TypeReferenceNode<ParameterizedTypeRef>> findSuperTypesWithMember( | ||
N4ClassifierDefinition classifier, TMember member) { | ||
|
||
return filter(classifier.getSuperClassifierRefs(), typeRefNode -> { | ||
TypeRef tref = typeRefNode == null ? null : typeRefNode.getTypeRef(); | ||
Type declType = tref == null ? null : tref.getDeclaredType(); | ||
return (declType instanceof ContainerType<?>) | ||
? ((ContainerType<?>) declType).getOwnedMembers().contains(member) | ||
: false; | ||
}); | ||
} | ||
} |
30 changes: 0 additions & 30 deletions
30
...ipse.n4js/src/org/eclipse/n4js/validation/validators/FindClassifierInHierarchyUtils.xtend
This file was deleted.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
plugins/org.eclipse.n4js/src/org/eclipse/n4js/validation/validators/IDEBUGValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* Copyright (c) 2016 NumberFour AG. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* NumberFour AG - Initial API and implementation | ||
*/ | ||
package org.eclipse.n4js.validation.validators; | ||
|
||
import static org.eclipse.n4js.validation.IssueCodes.ANN_UNUSED_IDEBUG; | ||
import static org.eclipse.xtext.xbase.lib.IterableExtensions.filter; | ||
|
||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
|
||
import org.eclipse.n4js.AnnotationDefinition; | ||
import org.eclipse.n4js.n4JS.Annotation; | ||
import org.eclipse.n4js.utils.validation.PostValidation; | ||
import org.eclipse.n4js.validation.AbstractMessageAdjustingN4JSValidator; | ||
import org.eclipse.n4js.validation.AbstractN4JSDeclarativeValidator; | ||
import org.eclipse.n4js.validation.IssueItem; | ||
import org.eclipse.xtext.validation.Check; | ||
import org.eclipse.xtext.validation.EValidatorRegistrar; | ||
|
||
/** | ||
* Creates issues for unnecessary IDEBUG annotations. | ||
* <p> | ||
* The list of of used IDEBUG annotations is managed by {@link AbstractN4JSDeclarativeValidator}. | ||
* | ||
* @see AbstractN4JSDeclarativeValidator | ||
*/ | ||
@SuppressWarnings("javadoc") | ||
public class IDEBUGValidator extends AbstractMessageAdjustingN4JSValidator { | ||
|
||
public static String DEFINED_IDEBUGS_KEY = AnnotationDefinition.IDEBUG.name + "_defined"; | ||
public static String USED_IDEBUGS_KEY = AnnotationDefinition.IDEBUG.name + "_used"; | ||
|
||
/** | ||
* NEEEDED | ||
* | ||
* when removed check methods will be called twice once by N4JSValidator, and once by | ||
* AbstractDeclarativeN4JSValidator | ||
*/ | ||
@Override | ||
public void register(EValidatorRegistrar registrar) { | ||
// nop | ||
} | ||
|
||
public static Collection<Annotation> getDefinedAnnotations(Map<Object, Object> context) { | ||
@SuppressWarnings("unchecked") | ||
Collection<Annotation> annotations = (Collection<Annotation>) context.get(DEFINED_IDEBUGS_KEY); | ||
if (annotations == null) { | ||
annotations = new HashSet<>(); | ||
context.put(DEFINED_IDEBUGS_KEY, annotations); | ||
} | ||
return annotations; | ||
} | ||
|
||
public static Collection<Annotation> getUsedAnnotations(Map<Object, Object> context) { | ||
@SuppressWarnings("unchecked") | ||
Collection<Annotation> annotations = (Collection<Annotation>) context.get(USED_IDEBUGS_KEY); | ||
if (annotations == null) { | ||
annotations = new HashSet<>(); | ||
context.put(USED_IDEBUGS_KEY, annotations); | ||
} | ||
return annotations; | ||
} | ||
|
||
@Check | ||
public void checkDefinedIDEBUGAnnotation(Annotation annotation) { | ||
if (AnnotationDefinition.IDEBUG.name.equals(annotation.getName())) { | ||
getDefinedAnnotations(getContext()).add(annotation); | ||
} | ||
} | ||
|
||
@Check | ||
public void checkUnusedIDEBUGAnnotation(@SuppressWarnings("unused") PostValidation postValidation) { | ||
Collection<Annotation> definedAnnotations = getDefinedAnnotations(getContext()); | ||
Collection<Annotation> usedAnnotations = getUsedAnnotations(getContext()); | ||
for (Annotation a : filter(definedAnnotations, it -> !usedAnnotations.contains(it))) { | ||
if (!a.getArgs().isEmpty()) { | ||
String bugID = a.getArgs().get(0).getValueAsString(); | ||
IssueItem issueItem = ANN_UNUSED_IDEBUG.toIssueItem(bugID); | ||
addIssue(issueItem.message, a, issueItem.getID()); | ||
} | ||
} | ||
} | ||
} |
87 changes: 0 additions & 87 deletions
87
plugins/org.eclipse.n4js/src/org/eclipse/n4js/validation/validators/IDEBUGValidator.xtend
This file was deleted.
Oops, something went wrong.