Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added annotation codeassist tests

  • Loading branch information...
commit 75d2998dddf98e527e5325a807d11dcd25690d2b 1 parent 810eac0
@pulse00 authored
View
4 LICENSE
@@ -1,7 +1,7 @@
-Copyright (c) 2011 Robert Gruendler <r.gruendler@gmail.com>
+Copyright (c) 2013 Robert Gruendler <r.gruendler@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
9 com.dubture.symfony.core/src/com/dubture/symfony/core/codeassist/contexts/AnnotationCompletionContext.java
@@ -8,7 +8,6 @@
******************************************************************************/
package com.dubture.symfony.core.codeassist.contexts;
-import org.eclipse.core.resources.IProjectNature;
import org.eclipse.dltk.core.CompletionRequestor;
import org.eclipse.dltk.core.ISourceModule;
import org.eclipse.php.internal.core.codeassist.contexts.PHPDocTagContext;
@@ -34,15 +33,13 @@
public boolean isValid(ISourceModule sourceModule, int offset,
CompletionRequestor requestor) {
- if (!super.isValid(sourceModule, offset, requestor) == true)
+ if (!super.isValid(sourceModule, offset, requestor) == true) {
return false;
+ }
try {
-
- IProjectNature nature = sourceModule.getScriptProject().getProject().getNature(SymfonyNature.NATURE_ID);
-
// wrong nature
- if(!(nature instanceof SymfonyNature)) {
+ if(!sourceModule.getScriptProject().getProject().hasNature(SymfonyNature.NATURE_ID)) {
return false;
}
View
27 ...ubture.symfony.core/src/com/dubture/symfony/core/codeassist/strategies/AnnotationCompletionStrategy.java
@@ -76,19 +76,15 @@ public void apply(final ICompletionReporter reporter) throws BadLocationExceptio
AnnotationCompletionContext context = (AnnotationCompletionContext) ctx;
SourceRange replaceRange = getReplacementRange(context);
- annotations = SymfonyModelAccess.getDefault()
- .findAnnotationClasses(context.getSourceModule().getScriptProject());
+ annotations = SymfonyModelAccess.getDefault().findAnnotationClasses(context.getSourceModule().getScriptProject());
String suffix = "()";
String prefix = context.getPrefix();
IType[] types = getTypes(context, prefix);
for (IType type : types) {
-
if (annotations.containsKey(type.getElementName())) {
-
String qualifier = annotations.get(type.getElementName());
-
if (qualifier != null && type.getTypeQualifiedName().equals(qualifier + "$" + type.getElementName()) ) {
reporter.reportType(type, suffix, replaceRange);
}
@@ -104,26 +100,22 @@ public void apply(final ICompletionReporter reporter) throws BadLocationExceptio
private IType[] getTypes(AnnotationCompletionContext context, String prefix) {
-
IDLTKSearchScope scope = createSearchScope();
if (context.getCompletionRequestor().isContextInformationMode()) {
- return PhpModelAccess.getDefault().findTypes(prefix,
- MatchRule.EXACT, trueFlag, falseFlag, scope, null);
+ return PhpModelAccess.getDefault().findTypes(prefix, MatchRule.EXACT, trueFlag, falseFlag, scope, null);
}
List<IType> result = new LinkedList<IType>();
if (prefix.length() > 1 && prefix.toUpperCase().equals(prefix)) {
// Search by camel-case
- IType[] types = PhpModelAccess.getDefault().findTypes(prefix,
- MatchRule.CAMEL_CASE, trueFlag, falseFlag, scope, null);
+ IType[] types = PhpModelAccess.getDefault().findTypes(prefix, MatchRule.CAMEL_CASE, trueFlag, falseFlag, scope, null);
result.addAll(Arrays.asList(types));
}
- IType[] types = PhpModelAccess.getDefault().findTypes(null, prefix,
- MatchRule.PREFIX, trueFlag, falseFlag, scope, null);
+
+ IType[] types = PhpModelAccess.getDefault().findTypes(null, prefix, MatchRule.PREFIX, trueFlag, falseFlag, scope, null);
result.addAll(Arrays.asList(types));
return (IType[]) result.toArray(new IType[result.size()]);
-
}
@@ -152,17 +144,10 @@ public void apply(ICompletionReporter reporter) throws BadLocationException {
for (IType type : types) {
try {
int flags = type.getFlags();
-
if (annotations.containsKey(type.getElementName())) {
-
String qualifier = annotations.get(type.getElementName());
-
if (qualifier != null && type.getTypeQualifiedName().equals(qualifier + "$" + type.getElementName()) ) {
-
- reporter.reportType(type,
- PHPFlags.isNamespace(flags) ? nsSuffix : suffix,
- replacementRange, getExtraInfo());
-
+ reporter.reportType(type,PHPFlags.isNamespace(flags) ? nsSuffix : suffix, replacementRange, getExtraInfo());
}
}
View
48 com.dubture.symfony.core/src/com/dubture/symfony/core/index/SymfonyIndexingVisitorExtension.java
@@ -46,6 +46,8 @@
import org.eclipse.wst.sse.core.utils.StringUtils;
import org.json.simple.JSONObject;
+import com.dubture.doctrine.annotation.model.Annotation;
+import com.dubture.doctrine.annotation.parser.AnnotationCommentParser;
import com.dubture.symfony.core.builder.SymfonyNature;
import com.dubture.symfony.core.index.visitor.RegisterNamespaceVisitor;
import com.dubture.symfony.core.index.visitor.TemplateVariableVisitor;
@@ -54,6 +56,7 @@
import com.dubture.symfony.core.model.SymfonyModelAccess;
import com.dubture.symfony.core.model.TemplateVariable;
import com.dubture.symfony.core.preferences.SymfonyCoreConstants;
+import com.dubture.symfony.core.util.AnnotationUtils;
import com.dubture.symfony.core.util.JsonUtils;
import com.dubture.symfony.core.util.text.SymfonyTextSequenceUtilities;
import com.dubture.symfony.index.SymfonyIndexer;
@@ -82,6 +85,7 @@
private NamespaceDeclaration namespace;
private TemplateVariableVisitor controllerIndexer;
private SymfonyIndexer indexer;
+ private AnnotationCommentParser parser = AnnotationUtils.createParser();
private List<UseStatement> useStatements = new ArrayList<UseStatement>();
private boolean isSymfonyResource;
@@ -197,23 +201,16 @@ public boolean visit(UseStatement s) throws Exception {
}
if (s instanceof ClassInstanceCreation) {
-
ClassInstanceCreation instance = (ClassInstanceCreation) s;
-
if (SymfonyCoreConstants.APP_KERNEL.equals(instance.getClassName().toString())) {
-
List args = instance.getCtorParams().getChilds();
-
if (args.get(0) instanceof Scalar) {
Scalar environment = (Scalar) args.get(0);
-
String value = environment.getValue().replace("\"", "").replace("'", "");
String path = sourceModule.getPath().toString();
Logger.debugMSG("indexing environment: " + value + " => " + path);
-
ReferenceInfo info = new ReferenceInfo(ISymfonyModelElement.ENVIRONMENT, instance.sourceStart(), instance.sourceEnd()-instance.sourceStart(), value, null, path);
requestor.addReference(info);
-
}
}
}
@@ -253,9 +250,7 @@ public boolean visit(TypeDeclaration s) throws Exception {
// we got a bundle definition, index it
if (fqcn.equals(SymfonyCoreConstants.BUNDLE_FQCN) && ! isTestOrFixture) {
-
int length = (currentClass.sourceEnd() - currentClass.sourceEnd());
-
JSONObject meta = JsonUtils.createBundle(sourceModule, currentClass, namespace);
ReferenceInfo info = new ReferenceInfo(ISymfonyModelElement.BUNDLE, currentClass.sourceStart(), length, currentClass.getName(), meta.toJSONString(), namespace.getName());
requestor.addReference(info);
@@ -291,29 +286,28 @@ public boolean visit(TypeDeclaration s) throws Exception {
private void parseAnnotation(ClassDeclaration clazz) {
PHPDocBlock block = clazz.getPHPDoc();
-
- if (block == null)
+
+ if (block == null) {
return;
+ }
boolean isAnnotation = false;
-
if (block.getCommentType() == Comment.TYPE_PHPDOC) {
- for (PHPDocTag tag : block.getTags()) {
- if (tag.getValue() != null &&
- tag.getValue().contains("Annotation")) {
- isAnnotation = true;
- }
+
+ List<Annotation> annotations = null;
+ if (org.apache.commons.lang.StringUtils.isNotBlank(block.getLongDescription())) {
+ annotations = parser.parse(block.getLongDescription());
+ } else if (org.apache.commons.lang.StringUtils.isNotBlank(block.getShortDescription())) {
+ annotations = parser.parse(block.getShortDescription());
}
-
- if (isAnnotation == false) {
- String comment = block.getShortDescription();
- if (comment.length() == 0) {
- comment = block.getLongDescription();
- }
- if ((comment == null || !comment.contains("@Annotation"))) {
- return;
- }
- isAnnotation = true;
+
+ if (annotations != null) {
+ for (Annotation annotation : annotations) {
+ if (annotation.getClassName().equals("Annotation")) {
+ isAnnotation = true;
+ break;
+ }
+ }
}
}
View
5 com.dubture.symfony.test/src/com/dubture/symfony/test/AllTests.java
@@ -4,13 +4,14 @@
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
+import com.dubture.symfony.test.codeassist.AnnotationCodeAssistTest;
import com.dubture.symfony.test.codeassist.DoctrineCodeAssistTest;
-import com.dubture.symfony.test.codeassist.SymfonyCodeAssistTest;
+import com.dubture.symfony.test.codeassist.ServiceCodeAssistTest;
@RunWith(Suite.class)
@SuiteClasses({ AnnotationCommentParserTest.class, AnnotationParserTest.class, IndexTest.class, ModelUtilsTest.class,
PathUtilsTest.class, RoutingParserTest.class, TextSequenceUtilityTest.class, XMLParserTest.class,
- YamlTest.class, SymfonyCodeAssistTest.class, DoctrineCodeAssistTest.class })
+ YamlTest.class, ServiceCodeAssistTest.class, DoctrineCodeAssistTest.class, AnnotationCodeAssistTest.class })
public class AllTests {
}
View
25 com.dubture.symfony.test/src/com/dubture/symfony/test/codeassist/AnnotationCodeAssistTest.java
@@ -0,0 +1,25 @@
+package com.dubture.symfony.test.codeassist;
+
+import org.junit.Test;
+
+import com.dubture.symfony.test.AbstractCodeAssistTest;
+
+/**
+ * @author Robert Gruendler <r.gruendler@gmail.com>
+ */
+public class AnnotationCodeAssistTest extends AbstractCodeAssistTest {
+
+ public AnnotationCodeAssistTest() {
+ super("annotation");
+ }
+
+ @Test
+ public void testRouteAnnotationCompletion() throws Exception {
+ runPdttTest("testRouteCompletion.pdtt");
+ }
+
+ @Test
+ public void testDICompletion() throws Exception {
+ runPdttTest("testDICompletion.pdtt");
+ }
+}
View
4 ...ymfony/test/codeassist/SymfonyCodeAssistTest.java → ...ymfony/test/codeassist/ServiceCodeAssistTest.java
@@ -4,9 +4,9 @@
import com.dubture.symfony.test.AbstractCodeAssistTest;
-public class SymfonyCodeAssistTest extends AbstractCodeAssistTest {
+public class ServiceCodeAssistTest extends AbstractCodeAssistTest {
- public SymfonyCodeAssistTest() {
+ public ServiceCodeAssistTest() {
super("codeassist");
}
View
27 com.dubture.symfony.test/workspace/annotation/Inject.php
@@ -0,0 +1,27 @@
+<?php
+
+/*
+ * Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace JMS\DiExtraBundle\Annotation;
+
+/**
+ * @Annotation
+ * @Target({"PROPERTY", "ANNOTATION"})
+ */
+final class Inject extends Reference
+{
+}
View
24 com.dubture.symfony.test/workspace/annotation/Route.php
@@ -0,0 +1,24 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Routing\Annotation;
+
+/**
+ * Annotation class for @Route().
+ *
+ * @Annotation
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+class Route
+{
+
+}
View
20 com.dubture.symfony.test/workspace/annotation/testDICompletion.pdtt
@@ -0,0 +1,20 @@
+--TEST--
+Should complete methods a @Route annotation
+--FILE--
+<?
+namespace NS;
+class SomeController {
+
+ /**
+ * @I|
+ */
+ public function someAction() {
+
+ }
+}
+?>
+--EXPECT--
+type(Inject)
+keyword(ignore)
+keyword(internal)
+
View
18 com.dubture.symfony.test/workspace/annotation/testRouteCompletion.pdtt
@@ -0,0 +1,18 @@
+--TEST--
+Should complete methods a @Route annotation
+--FILE--
+<?
+namespace NS;
+class SomeController {
+
+ /**
+ * @R|
+ */
+ public function someAction() {
+
+ }
+}
+?>
+--EXPECT--
+type(Route)
+keyword(return)
Please sign in to comment.
Something went wrong with that request. Please try again.